APIs & Integrations

aliknox
Member

API - Create Engagements - Error Message

SOLVE

Hi this is the first time I have done this. I’ve created a test account and trying to add an engagement to an existing company. And I get the following error.

Status code: 400
Response: {“status”:“error”,“message”:“Invalid input JSON on line 1, column 15: Can not deserialize instance of com.hubspot.engagements.base.detail.views.EngagementView out of START_ARRAY token”,“correlationId”:“43b0088a-9991-4980-abe0-3e39750dbaab”,“requestId”:“db0d3584988ae0b441a650cae2d5e38c”}

Below is the JSON I’m passing.

{“engagement”:[{“property”:“active”,“value”:“True”},{“property”:“ownerId”,“value”:“31308819”},{“property”:“type”,“value”:“NOTE”},{“property”:“timestamp”,“value”:1517514219}],“associations”:[{“property”:“contactIds”,“value”:“2”},{“property”:“companyIds”,“value”:“686724768”}],“metadata”:[{“property”:“body”,“value”:“Import Record Test”}]}

Any help would be appreciated.

Thanks,

Ali

0 Upvotes
1 Accepted solution
aliknox
Solution
Member

API - Create Engagements - Error Message

SOLVE

Thanks, I have resolved this, it was an array conversion problem.

View solution in original post

0 Upvotes
7 Replies 7
mcraciun
HubSpot Employee
HubSpot Employee

API - Create Engagements - Error Message

SOLVE

I ran into a similar issue and it was caused by having ownerId in an array, which it shouldn't be in 

jaywhy
Participant

API - Create Engagements - Error Message

SOLVE

I found my own solution to this issue and will post it here as I have received a couple of upvotes to my initial question. Hopefully it will help someone else.

 

var createjsonVar = [];

createjsonVar.push({
  engagement: {
    active: true,
    type: "TASK",
    timestamp: new Date().getTime(,
    ownerId: ownerId
  },
  associations: {
    contactIds: [contactID]
  },
  metadata: {
    subject: 'follow up',
    body: taskBody,
    status: 'NOT_STARTED'
  }
});

var createjson = JSON.stringify(createjsonVar);
var body = createjson.substr(1, createjson.length - 2);

 

By taking a substring of the output you are removing the initial opening square bracket which causes the error.

I know it's probably not the best solution but it works!

dennisedson
HubSpot Product Team
HubSpot Product Team

API - Create Engagements - Error Message

SOLVE

Thanks for posting your solution, @jaywhy !

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

API - Create Engagements - Error Message

SOLVE

Hi @aliknox,

You’re correct; the engagement, associations, and metadata fields aren’t arrays, they’re objects. The request body should look like this:

{
    "engagement": {
      "active": true,
      "ownerId": 1,
      "type": "NOTE",
      "timestamp": 1409172644778
    },
    "associations": {
      "contactIds": [
        2
      ],
      "companyIds": [],
      "dealIds": [],
      "ownerIds": []
    },
    "attachments": [
      {
        "id": 4241968539
      }
    ],
    "metadata": {
      "body": "note body"
    }
  }
aliknox
Solution
Member

API - Create Engagements - Error Message

SOLVE

Thanks, I have resolved this, it was an array conversion problem.

0 Upvotes
jaywhy
Participant

API - Create Engagements - Error Message

SOLVE

Please could you explain how you resolved as I am having the same issue?

aliknox
Member

API - Create Engagements - Error Message

SOLVE

Is my JSON file structure incorrect?

0 Upvotes