Jump to content

Google Script Error


Recommended Posts

Posted

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

Posted

Hello. Could you check if your access token is correct or not expired?

Posted

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

Posted (edited)

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
Posted

That's great to hear!

Loyverse Point of Sale

 

 

 

 

×
×
  • Create New...