Not able to create a note for a deal-Engagement

SOLVE
Highlighted
Regular Contributor

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!

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Regular Contributor

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));

3 Replies 3
Highlighted
Regular Contributor

Waiting for a response here ...

Reply
0 Upvotes
Regular Contributor

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));

Highlighted
HubSpot Moderator

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!

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes