Error 415 when Creating Task

Hi all,

I’m trying to create a task in Hubspot using an API call from a Google Sheet (using Google Script). I’ve sorted through the API etc using Postman until my code worked, but when I use the same set-up in Google Script, I keep getting error 415:

Exception: Request failed for https://api.hubspot.com returned code 415

function hsAPI_Task() {
 const options = {
 method: "POST",
 muteHttpExceptions: false,
 headers: {
 accept: "application/json",
 Authorization: "Bearer <hidden for privacy>",
 },
 body: {
 "properties": {
 "hs_timestamp": "2024-10-30T03:30:17.883Z",
 "hs_task_body": "Send test",
 "hubspot_owner_id": "<hidden for privacy>",
 "hs_task_subject": "Test Task",
 "hs_task_status": "WAITING",
 "hs_task_priority": "HIGH",
 "hs_task_type": "CALL"
 },
 "associations": [{
 "to": {
 "id": <hidden for privacy>
 },
 "types": [{
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 18
 }]
 }]
 },

 };

 var r = UrlFetchApp.fetch("https://api.hubspot.com/crm/v3/objects/tasks", options);
 console.log(r);
}

Any smart insights in what is going wrong or causing the error?

Managed to solve this by accident , will post working code for future reference:

function hsAPI_Task() {
 const b = {
 "properties": {
 "hs_timestamp": "2024-10-30T03:30:17.883Z",
 "hs_task_body": "Send Proposal",
 "hubspot_owner_id": "HIDDEN",
 "hs_task_subject": "test",
 "hs_task_status": "WAITING",
 "hs_task_priority": "HIGH",
 "hs_task_type": "CALL"
 },
 "associations": [{
 "to": {
 "id": HIDDEN
 },
 "types": [{
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 18
 }]
 }]
 }
 const options = {
 "method" : "POST",
 "muteHttpExceptions": false,
 "headers": {
 "Content-Type": "application/json",
 "Authorization": "Bearer HIDDEN",
 },
 "payload": JSON.stringify(b)

 };

 var r = UrlFetchApp.fetch("https://api.hubspot.com/crm/v3/objects/tasks", options);
 console.log(r);
}