Last active
July 12, 2022 11:13
-
-
Save darryn/61f934785e68f2e22b4ab072c5673a9d to your computer and use it in GitHub Desktop.
Shopify Gift Card Importer Google App Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 theiterateThroughRows
function first.