# Parsing Error using HubSpot Associations API

**URL:** <https://community.hubspot.com/t/parsing-error-using-hubspot-associations-api/91881>\
**Category:** APIs & Integrations\
**Tags:** workflows\
**Created:** [October 16, 2023, 1:39pm UTC](https://community.hubspot.com/t/parsing-error-using-hubspot-associations-api/91881 "2023-10-16T13:39:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GianVentura](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/gianventura/32/3378_2.png) [@GianVentura](https://community.hubspot.com/u/GianVentura)\
**Post date:** [October 16, 2023, 1:39pm UTC](https://community.hubspot.com/t/parsing-error-using-hubspot-associations-api/91881/1 "2023-10-16T13:39:53Z")

</div>

Hi all, I have a problem with using hubspot’s api within workflows, particularly in custom code.

When I add the code from the Hubspot documentation ([https://developers.hubspot.com/docs/api/crm/associations](https://developers.hubspot.com/docs/api/crm/associations)) CREATE BATCH section, in the custom code I get the error “Parsing Error”. I attach screen.

I have tried using a regular expression to modify it but I always get the same error.

Can anyone help me?

Thanks,

Gianmarco

 ![864917_1_parsing-error.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/d/e/def16f2bf30e8b780437a88f88492eab276a79d8.png)

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [October 17, 2023, 7:51am UTC](https://community.hubspot.com/t/parsing-error-using-hubspot-associations-api/91881/2 "2023-10-17T07:51:49Z")

</div>

Hi @GianVentura,  
Thank you for posting in our Community and thanks for the screenshot!  
I understand that you are trying to [batch create associations between records via API](https://developers.hubspot.com/docs/api/crm/associations) but you are getting the following “ **Parsing error: Invalid regular expression flag** ”.  
Let’s see if some of our Community Members have already seen this type of error: Hi @NTroiani2, @soday and @AArtiles do you have suggestions to help @GianVentura, please?  
I’d like to also invite some of our experts to this conversation: Hi @Teun, @ChrisoKlepke and @DanielJeal have you already encounter this error message, please?  
**Also, if anybody else has anything to add and/or share, please feel free to join in the conversation** 🙂  
I appreciate your feedback on this, thank you very much!  
Have a lovely day!  
Best,  
Bérangère

---

<div class="post-metadata">

**Author:** ![GianVentura](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/gianventura/32/3378_2.png) [@GianVentura](https://community.hubspot.com/u/GianVentura)\
**Post date:** [October 27, 2023, 8:13am UTC](https://community.hubspot.com/t/parsing-error-using-hubspot-associations-api/91881/3 "2023-10-27T08:13:08Z")

</div>

Hi [@BérangèreL](https://community.hubspot.com/t5/user/viewprofilepage/user-id/230185) ,

do you have any news for me?

Thank you.

Gianmarco Ventura

---

<div class="post-metadata">

**Author:** ![HubSpot\_Corey](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hubspot_corey/32/77072_2.png) [@HubSpot\_Corey](https://community.hubspot.com/u/HubSpot_Corey)\
**Post date:** [July 16, 2024, 2:34am UTC](https://community.hubspot.com/t/parsing-error-using-hubspot-associations-api/91881/4 "2024-07-16T02:34:28Z")

</div>

Hi @GianVentura  
I understand this post is a little old, but I thought I’d post the answer here for anyone else having similiar issues. It looks like there’s a few things potentially wrong with your code. I’ve outlined them below:

**1. API Endpoint Construction**

It looks like your API endpoint doesn’t follow HubSpots documentation. I would suggest using the suggested structure of:

`const apiResponse = await hubspotClient.crm.associations.v4.batchApi.create(fromObjectType, toObjectType, BatchInputPublicAssociationMultiPost);`

**2. Request Body Format**

The structure of your BatchInputPublicAssociationMultiPost seems off. It looks like you’re using a variable called ‘x’ but I can’t see this declared anywhere? The ‘associationTypeId’ should instead be 340 for Company to Ticket and the ‘\_from’ should be the RecordID of the other object as below (Assuming company\_hs\_object\_id and ticket\_hs\_object\_id had been declared):

`const BatchInputPublicAssociationMultiPost = { inputs: [{"types":[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":340}],"_from":{"id":company_hs_object_id},"to":{"id":ticket_hs_object_id}}] };`

If you continue having issues, I would suggest using console.log() to review ‘BatchInputPublicAssociationMultiPost’, ‘fromObjectType’ and ‘toObjectType’ to ensure that they match the documentation and expected format.
