Google Apps Script POST/PATCH requests giving 405/415 error?
SOLVE
Hello Hubspot community,
I'm using Google Apps Script to try and update data within my Hubspot CRM, but I'm still very much learning to work with the API. The documentation shows many examples using things like Node and Python, but Apps Script appears to use vanilla JavaScript with some custom functions.
I've successfully performed GET requests to pull data out of Hubspot, but now I need to learn to push data into it. The code sample I'm working on right now is intended to update a property within a company object and set it to a chosen value (in this example, the number 1000). Here's what I have so far:
function myFunction() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheets()[0];
const data = ws.getRange('A1').getDataRegion().getValues();
//"?limit=10" determines how many lines of data to pull?
//correct, and there's a limit cap of 100
const hubSpot = "https://api.hubapi.com/crm/v3/objects/companies/************/?archived=false&properties=test_kpi_property;
const testKPI = {
"properties":{
"test_kpi_property" : "1000"
}
}
const options = {
"muteHttpExceptions" : true,
"method": "patch",
"headers": {
"contentType":"application/json",
"authorization": "Bearer ***************************************",
},
"payload": JSON.stringify(testKPI)
};
var response = UrlFetchApp.fetch(hubSpot,options);
ws.getRange('A7').setValue(String(response));
}
Google Apps Script POST/PATCH requests giving 405/415 error?
SOLVE
Hi there, 405/415 usually means HS is rejecting the request.
Could it be "content-type" instead? I personally use the nodejs library mostly, and the headers are handled by it. However I see that yours is "contentType" and maybe Google Apps translates it incorrectly.
Also it could be the querystring params at the back of your endpoint. Usually just stops at .../objects/companies/{companyID} and I'm not sure if this would be the case.
Google Apps Script POST/PATCH requests giving 405/415 error?
SOLVE
Hi there, 405/415 usually means HS is rejecting the request.
Could it be "content-type" instead? I personally use the nodejs library mostly, and the headers are handled by it. However I see that yours is "contentType" and maybe Google Apps translates it incorrectly.
Also it could be the querystring params at the back of your endpoint. Usually just stops at .../objects/companies/{companyID} and I'm not sure if this would be the case.
Google Apps Script POST/PATCH requests giving 405/415 error?
SOLVE
OMG that was it. The contentType is how Apps Script formats it, but I'm including it in the header so it makes sense that it needs to be formatted for Hubspot. Thank you so much!