Parsing Error using HubSpot Associations API

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) 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

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 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 :slightly_smiling_face:
I appreciate your feedback on this, thank you very much!
Have a lovely day!
Best,
Bérangère

Hi @BérangèreL ,

do you have any news for me?

Thank you.

Gianmarco Ventura

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.