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.