I’m trying to create products in Shopify with their API through a google sheet. Whenever I try to create an HTTP request I get the following error:
“Login information disallowed”
To test the API, I created a more or less identical python script. When I run the Python script the product gets created as planned. But I just can’t get it to work through my google sheet.
GOOGLE SCRIPT CODE (NOT WORKING) :
function create_product() {
var url = "https://XXXX:[email protected]/admin/api/2019-04/products.json";
var data = {
"product": {
"title": 'test 1',
"body_html": 'test 1',
"vendor": 'test 1',
"product_type": 'test 1',
"tags" : 'test 1'
}
};
var params = {
method : 'POST',
contentType : 'application/json',
payload : JSON.stringify(data),
};
var post = UrlFetchApp.fetch(url, params);
}
PYTHON CODE:
import requests
url = "https://XXXX:[email protected]/admin/api/2019-04/products.json"
data = {
"product": {
"title": 'test 1',
"body_html": 'test 1',
"vendor": 'test 1',
"product_type": 'test 1',
"tags" : 'test 1'}
}
post = requests.post(url=url, json=data)
I expected both scripts to give me the same results, but only the Python script seems to work. The “Login information disallowed” error keeps showing up in the google script, when i try to do the http post.
2
Answers
As per this Stack Overflow answer and this issue on Google bug tracker, API credentials in the URL does not work well. Consider adding them in Authorization header. A sample code for POST request will be like
I had the same issue, I was able to fix it with the followings:
Here is what my Python code was:
Here is my current GoogleScript code:
Once i was able to fix the request call, here is how I was able to check the result.
Other source: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app