# difficulty in creating engagements

**URL:** <https://community.hubspot.com/t/difficulty-in-creating-engagements/122253>\
**Category:** APIs & Integrations\
**Tags:** starter\
**Created:** [December 10, 2024, 9:08pm UTC](https://community.hubspot.com/t/difficulty-in-creating-engagements/122253 "2024-12-10T21:08:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AngelKanna](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@AngelKanna](https://community.hubspot.com/u/AngelKanna)\
**Post date:** [December 10, 2024, 9:08pm UTC](https://community.hubspot.com/t/difficulty-in-creating-engagements/122253/1 "2024-12-10T21:08:11Z")

</div>

Getting this error when I tried to create an Email engagement through API- [https://api.hubapi.com/engagements/v1](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

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [December 11, 2024, 2:52am UTC](https://community.hubspot.com/t/difficulty-in-creating-engagements/122253/2 "2024-12-11T02:52:22Z")

</div>

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:

```lia-code-sample
...

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

...

```

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

---

<div class="post-metadata">

**Author:** ![AngelKanna](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@AngelKanna](https://community.hubspot.com/u/AngelKanna)\
**Post date:** [February 5, 2025, 2:03pm UTC](https://community.hubspot.com/t/difficulty-in-creating-engagements/122253/3 "2025-02-05T14:03:34Z")

</div>

Thanks, it worked

---

<div class="post-metadata">

**Author:** ![AngelKanna](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@AngelKanna](https://community.hubspot.com/u/AngelKanna)\
**Post date:** [December 12, 2024, 2:57am UTC](https://community.hubspot.com/t/difficulty-in-creating-engagements/122253/4 "2024-12-12T02:57:34Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [December 13, 2024, 2:18am UTC](https://community.hubspot.com/t/difficulty-in-creating-engagements/122253/5 "2024-12-13T02:18:35Z")

</div>

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](https://developers.hubspot.com/beta-docs/guides/api/library/files) 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.
