Bulk Delete Associations v4 Not Deleting Anything

I’m trying to use the v4 associaiton batch delete endpoint, and I’m pulling my hair out a bit. Short version is the API is generating a 204 response, but it isn’t actually deleting any associations. Our internal resources have not been able to identify the reason either. If I go back to v3, I can make it work. Trying to be as forward-proof as possible by using v4. Code is below:

# Function to delete the associations in batches
def delete_associations(api_key, fromObjectType, toObjectType, fromObjectId, toObjectIds, batchSize):
 headers = {
 "Authorization": f"Bearer {api_key}",
 "Content-Type": "application/json"
 }

 for i in range(0, len(toObjectIds), batchSize):
 batch_toObjectIds = toObjectIds[i:i + batchSize]
 batch_payload = {
 "inputs": [
 {
 "from": {"id": fromObjectId},
 "to": [{"id": toObjectId} for toObjectId in batch_toObjectIds]
 }
 ]
 }

 delete_url = f"{hubspot_api}v4/associations/{fromObjectType}/{toObjectType}/batch/archive"

 try:
 response = requests.post(delete_url, headers=headers, json=batch_payload)
 response.raise_for_status()

 # Print request and response details
 print(f"Request Payload: {batch_payload}")
 print(f"Response Status Code: {response.status_code}")
 print(f"Response Content: {response.text}")

 data = response.json()
 print(f"Succesfully deleted associations for {fromObjectType} {fromObjectId} and {toObjectType}")

 except requests.exceptions.RequestException as e:
 print(f"Error deleting associations using the given parameters: {e}")

 # Print more information about the error if possible
 try:
 response_content = response.json()
 print("Error details:", response_content)
 except ValueError:
 print("Error details: unable to parse response content as JSON.")

 return

As you can see, I’m trying to batch delete 100 associations at a time in line with Hubspot’s documentation for batch limits. I’ve also tried this same code with batch sizes as small as 10.
Here is the relevant portion of the log (the very end of the payload print and the following:

'5038290306']}}, {'from': {'id': '10860808346'}, 'to': {'id': '2-11264833'}}]}
Response Status Code: 204
Response Content: 
Error deleting associations using the given parameters: Expecting value: line 1 column 1 (char 0)
Error details: unable to parse response content as JSON.

Any help appreciated.

Hey, @jjones41 :waving_hand: Thanks for flagging this. I don’t have a fast answer. What’s not clear in the documentation is if this is the expected behaviour, and we should use the v3 endpoint for this use case? Or if there is something unexpected happening.

If you run a small test, on two records for example, using Postman, do you get the same result? I want to make sure I have a simple example to my internal resources. I’ll also set up a quick test.

Best,

Jaycee

Hi Jaycee, it seems to be something with the payload structure of the toObjectId array. If I use the interactive documentation and manually place a couple IDs, it runs correctly.