I have been trying to use the UrlFetchApp from apps script to fetch the inventory information from an inventory system API called Salesbinders, for some reason I kept getting login information disallowed error, I have tried different ways I found online but none of them is working, I have also tried to put it on postman and it worked so I am assuming the details I provided should be correct. Here is the salesbindner API documentation: https://www.salesbinder.com/api/
and here is my code
function fetching() {
var USERNAME ='{API KEY}'
var PASSWORD = '{x}'
var url ='https://{API KEY}:x@{subdomain}.salesbinder.com/api/2.0/items.json'
var headers = {
"Authorization" : "Basic " + Utilities.base64Encode(USERNAME+ ':' + PASSWORD)
};
let response = UrlFetchApp.fetch(url,headers)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Logger.log(response.getContentText());
}
would appreciate it a lot if anyone can help, I have been stuck with this all weekend
In your script, headers
is not included in the request as the header. If your URL, USERNAME
andPASSWORD
are correct, I think that this might be the reason for your issue.
And also, at UrlFetchApp, then
is not used. When these points are reflected in your script, it becomes as follows.
function fetching() {
var USERNAME = '{API KEY}';
var PASSWORD = '{x}';
var url = 'https://{API KEY}:x@{subdomain}.salesbinder.com/api/2.0/items.json';
var headers = {
"Authorization": "Basic " + Utilities.base64Encode(USERNAME + ':' + PASSWORD)
};
let response = UrlFetchApp.fetch(url, { headers });
Logger.log(response.getContentText());
}
USERNAME
andPASSWORD
are correct. If an error occurs, please confirm them again.