Skip to content

Instantly share code, notes, and snippets.

@darryn
Last active July 12, 2022 11:13
Show Gist options
  • Save darryn/61f934785e68f2e22b4ab072c5673a9d to your computer and use it in GitHub Desktop.
Save darryn/61f934785e68f2e22b4ab072c5673a9d to your computer and use it in GitHub Desktop.
Shopify Gift Card Importer Google App Script
const sheet = SpreadsheetApp.getActive().getSheetByName("[sheet_name]");
const data = sheet.getDataRange().getValues();
function postData(giftData) {
let options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify(giftData),
'headers': {
'Authorization': "Basic " + Utilities.base64Encode("[api_key]:[api_password]")
}
};
UrlFetchApp.fetch("https://[store-name].myshopify.com/admin/api/2021-10/gift_cards.json", options);
};
function iterateThroughRows() {
data.forEach(function (row) {
let giftData = {
"gift_card": {
"initial_value": row[2],
"code": row[0],
"customer_id": row[1]
}
};
postData(giftData)
});
};
@darryn
Copy link
Author

darryn commented Oct 27, 2021

Google Script to be used for importing a Google Sheet of gift card information into Shopify.

Requires a private app to be set up in the Shopify store with access to the Gift Card API.

When you Run the script in Google Scripts, make sure you select the iterateThroughRows function first.

https://screenshot.click/02-07-towuk-dtuqg.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment