Jump to content

Google Script Error


fsandovalsk

Recommended Posts

Hello,
Can't connect to Loyverse API with Google Script. Same info works fine with Postman.

GOOGLE SCRIPT

function loyverseJSON() {
  var url = "https://api.loyverse.com/v1.0/receipts";
  var options = {
    "Method": "get",
    "Headers": {
       "Accept": "application/json",
       "Content-Type": "application/json",
       "Authorization": "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
       },
    "Body": {
      "created_at_min" : "2023-05-18T00:00:00.000Z",
      "limit" : 20
    }
  }
  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response);
 }


ERROR
Exception: Request failed for https://api.loyverse.com returned code 401. Truncated server response: {"errors":[{"code":"UNAUTHORIZED","details":"Access token is not valid."}]}

Thanks

Link to comment
Share on other sites

Hello, access token not expired. Added another and both don't work. Postman works fine.

Link to comment
Share on other sites

Thanks Ki this works!

function loyverseJSON() {
 var url = "https://api.loyverse.com/v1.0/receipts?created_at_min=2023-05-26T00:00:00.000Z&limit=2";

 var options =
 {
  "method": "get", //<-
  "headers": //<-
  {
  "Accept": "application/json",
  "Content-Type": "application/json",
  "Authorization": "Bearer XXXXXXXXXXXXXXXXXXXXXXXX"
  }
 }

 var response = UrlFetchApp.fetch(url, options);
 Logger.log(response); 
}

Edited by fsandovalsk
Link to comment
Share on other sites

Loyverse Point of Sale

 

 

 

 

×
×
  • Create New...