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”}]}
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!