Not able to create a note for a deal-Engagement

I get this error message when I try to create a note for a deal in Hubspot-

FetchError: invalid json response body at https://api.hubapi.com/engagements/v1/engagements?hapikey=demo reason: Unexpected end of JSON input

This is the code that I have written,

var form = {
 "engagement": {
 "active": true,
 "type": "NOTE",

 },
 "associations": {
 "companyIds": [ ],
 "dealIds": [123],
 "ownerIds": [ ]
 },
 "attachments": [
 {

 }
 ],
 "metadata": {
 "body": "note body"
 }
}
 url_deal='https://api.hubapi.com/engagements/v1/engagements?hapikey=demo';
 fetch(url_deal, {
 method: 'put',
 headers: {
 'Accept': 'application/json, text/plain, */*',
 'Content-Type': 'application/json'
 },
 body: JSON.stringify(form)
 }).then(res=>res.json())
 .then(res => context.log(res));

Any help on this matter would be greatly appreciated!

Waiting for a response here …

I found the Issue that I was having. I was using “put” Instead of “POST” for the fetch call.

//Attempt to create a note for a deal in Hubspot

var fetch = require("node-fetch");
var urlBody="https://www.google.com";
var form = {
 "engagement": {
 "active": true,
 "type": "NOTE",

 },
 "associations": {
 "dealIds": [123]

 },
 "metadata": {
 "body": urlBody
 }
}

 url_deal='https://api.hubapi.com/engagements/v1/engagements?hapikey=demo';
 fetch(url_deal, {
 method: 'POST',
 headers: {
 'Accept': 'application/json, text/plain, */*',
 'Content-Type': 'application/json'
 },
 body: JSON.stringify(form)
 }).then(res=>res.json())
 .then(res => console.log(res));

Hey, @ricky23.

Apologies that this post fell through the cracks. My team strives to respond to posts within 48 hours.

I’m glad you found the solution!