Add Records to an Existing List - Formatting RecordID Request

Trying to build an API integration that involves two steps

1. Creating a contact

2. Using the corresponding ContactID from Step 1 to add that contact to a specific list within a HubSpot account

Having no problem with Step 1, but a little confused with Step 2. I am using the “Add Records to an Existing List” method found at this link

The API document says to post a “list of RecordIDs” in the request body. But every request I make I get a JSON formatting error response from the API. My question is pretty simple- What would the request body look like for this particular PUT request? Ie. Let’s say I’m trying to add record ID 123456 to a list. What does that request body look like? Sorry for the rudimentary question, but just can’t seem to get the body of this request formatted correctly and the API reference doc doesn’t have any examples to build off

Thanks in advance!

Hi @SDenoon :waving_hand:

If you haven’t already, try clicking into the “Endpoints” tab at the top of the documentation you’ve been reviewing. Here you should see a list of endpoints offered by the given API, alongside example requests for each. For the endpoint you’re interested in using, “Add Records to a List”, the example request (cURL format) is:

curl --request PUT \
 --url https://api.hubapi.com/crm/v3/lists/{listId}/memberships/add \
 --header 'authorization: Bearer YOUR_ACCESS_TOKEN' \
 --header 'content-type: application/json' \
 --data '[
 {record_id_1},
 {record_id_2}
]'

I hope this proves useful. Please let me know if you have any follow-up questions.