APIs & Integrations

AngelKanna
Member

difficulty in creating engagements

SOLVE

Getting this error when I tried to create an Email engagement through API- https://api.hubapi.com/engagements/v1

{"status":"error","message":"Invalid input JSON on line 1, column 129: Encountered START_ARRAY token for non-repeated field com.hubspot.engagements.base.Associations.deal_ids", correlation_Id:}

Sample

const data={
        "engagement": {
         "active": true,
         "type": "EMAIL",
         "timestamp": Date.parse(outboundObject[i].ReceivedAt)
        },
        "associations": {
         "contactIds": [contactId],
         "dealIds": [dealId]
        },
        "metadata": {
         "from": {
         "email": "risksolutions@prolink.insure",
         "firstName": "Prolink",
         "lastName": "Insurance"
        },
        "to": [
         {
          "email": outboundObject[i].Recipients[0]
         }
        ],
        "cc": [],
        "bcc": [],        
        "subject": outboundObject[i].Subject,  
        "text": actions,
        "html": htmlBody,
        "hs_email_open": opens,
        "hs_email_click": clicks  
        }
        };          

the values for contactIds=[1] and dealIds=[4,5,6]

 

Please help me to resolve this

0 Upvotes
1 Accepted solution
zach_threadint
Solution
Guide

difficulty in creating engagements

SOLVE

Hi @AngelKanna 👋

 

I suspect this is due to nested arrays set for associations.contactIds and associations.dealIds. Given your Contact and Deal ID variables are arrays themselves, try updating your associations object definition to:

...

"associations": {
  "contactIds": contactId,
  "dealIds": dealId
}

...

 I hope that proves helpful. Please let me know if you have any follow-up quesitons.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


View solution in original post

0 Upvotes
3 Replies 3
AngelKanna
Member

difficulty in creating engagements

SOLVE

Ya, I removed the nesting and now I am able to create engagements in more than one deal. Thanks.

One more quick question, can we update Clicks and Opens throught the engagement API endpoint and how to add attachments. The documentation mentioned about the File API to get the file ID, but the attachments are from external email. Can you suggest some resource to dig...

zach_threadint
Guide

difficulty in creating engagements

SOLVE

Hi @AngelKanna 👋

 

I don't think you'll be able to set the number of opens or clicks for this object type. The Engagement "Email" properties hs_email_click_count and hs_email_open_count are read-only (i.e. they are set automatically by HubSpot as part of the connected inbox feature).

 

And for attachments, yes, you'll need to use the Files API to make the files available in HubSpot (either via import from a public URL or local file upload) and then "attach" them to the Email record via the hs_attachment_ids property.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


0 Upvotes
zach_threadint
Solution
Guide

difficulty in creating engagements

SOLVE

Hi @AngelKanna 👋

 

I suspect this is due to nested arrays set for associations.contactIds and associations.dealIds. Given your Contact and Deal ID variables are arrays themselves, try updating your associations object definition to:

...

"associations": {
  "contactIds": contactId,
  "dealIds": dealId
}

...

 I hope that proves helpful. Please let me know if you have any follow-up quesitons.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


0 Upvotes