Integrating Shopify Private App with Netsuite
I couldn’t find this in the shopify documentation so I thought it would be helpful to share it.
Backstory:
I was trying to get the JSON from Shopify Private App and I was getting this error:
[API] Invalid API key or access token (unrecognized login or wrong password)
After much research all I needed to do was add header “X-Shopify-Access-Token”.
Here’s the code, just make sure to replace HTTPSMODULE or load with the Netsuite https Module.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
var SHOP_NAME = 'YOUR_SHOP_NAME'; var API_KEY = 'YOUR_API_KEY'; var PASSWORD_ACCESS_TOKEN = 'YOUR_PASSWORD_ACCESS_TOKEN'; var URLTEMPLATE = 'https://$APIKEY$:$PASSWORD$@$SHOP$.myshopify.com' .replace('$SHOP$', SHOP_NAME) .replace('$APIKEY$', API_KEY) .replace('$PASSWORD$', PASSWORD_ACCESS_TOKEN); function run(){ var myUrl = URLTEMPLATE; var path = '/admin/orders.json'; myUrl += path; var orders = shopifyRequest(myUrl); var ordersJSON = JSON.parse(orders); return orders; } function shopifyRequest(myurl){ var myrequest = {}; myrequest.url = myurl; myrequest.method = HTTPSMODULE.Method.GET; myrequest.headers = {}; myrequest.headers["X-Shopify-Access-Token"] = PASSWORD_ACCESS_TOKEN; var myresponse = HTTPSMODULE.request(myrequest); return myresponse.body; } |