bliscar Posted November 8, 2022 Share Posted November 8, 2022 I am trying to implement basic Google sheet script to retrieve customers list using Prestashop webservices : var URL_STRING = "https://www.mydomain.com/api/customers?display=[firstname,lastname,email]"; var response = UrlFetchApp.fetch(URL_STRING); var json = response.getContentText(); var data = JSON.parse(json); Very logically, this script is not working because I do not mention the authentication KEY, so I go the reply "401 Unauthorized". So I have tried to insert the KEY in the URL, like this : var URL_STRING = "https://[email protected]/api/customers?display=[firstname,lastname,email]"; var response = UrlFetchApp.fetch(URL_STRING); var json = response.getContentText(); var data = JSON.parse(json); But it is not working as well (reply "401 Unauthorized"). What should I do to mention the KEY in the code and make the script working correctly ? Thank you 🙂 Link to comment Share on other sites More sharing options...
ps8modules.com Posted November 8, 2022 Share Posted November 8, 2022 Hi. Your api url?ws_key=ABCDEF 1 Link to comment Share on other sites More sharing options...
bliscar Posted November 8, 2022 Author Share Posted November 8, 2022 12 minutes ago, 4you.software said: Hi. Your api url?ws_key=ABCDEF Thank you. I have tried this code : var URL_STRING = "https://www.mydomain.com/api/customers?ws_key=KEY"; var response = UrlFetchApp.fetch(URL_STRING); var json = response.getContentText(); var data = JSON.parse(json); And I got the error : SyntaxError: Unexpected token < in JSON at position 0 🙁 Link to comment Share on other sites More sharing options...
ps8modules.com Posted November 8, 2022 Share Posted November 8, 2022 UrlFetchApp.fetch( URL_STRING, { headers : { 'Content-Type': 'application/json', 'Accept': 'application/json' } }); 1 Link to comment Share on other sites More sharing options...
ps8modules.com Posted November 8, 2022 Share Posted November 8, 2022 https://www.google.com/amp/s/www.freecodecamp.org/news/javascript-fetch-api-tutorial-with-js-fetch-post-and-header-examples/amp/ 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now