I'm trying to get information from a squareup api into Google Sheets, but I'm not quite sure how to deal with the bearer token and misalignment with the ScriptApp method signature. Thank you!
function squareLocations() {
var url = "https://connect.squareup.com/v2/locations";
var headers = {
"Square-Version": "2022-01-20",
"Authorization": token,
"Content-Type": 'application/json'
}
var data = {
'locations': {
'id': locationID,
'name': locationName,
'address': locationAdress,
}
}
const params = {
headers: head,
method: "get",
muteHttpExceptions: true,
payload: JSON.stringify(data)
}
var response = UrlFetchApp.fetch(url, headers);
var responseCode = response.getResponseCode();
var responseBody = JSON.parse(response.getContextText());
var json = JSON.parse(responseBody);
if (responseCode === 200)
{
responseJSON.error = false;
return responseJSON;
}
else
{
responseJSON.error = true;
responseJSON.message = `Request failed. Expected 200, got ${responseCode}: ${responseBody}`;
return responseJSON;
}
}