Hi, as the title says, I'm trying to associate a contact with a deal when the deal already exists. I've spent hours on the forums and can't find one that helps me, mainly because all the links to HubSpot docs on associations are 404'ing. Like, if you look at deal associations here:
But I'm not getting anything back. No error, no status, no nothing and the record isn't updating. Anyone have a working solution or links that don't 404?
does not offer the option to update associations. It may well be that you need to use an association API call to link the deal and contact records in a specific direction:
does not offer the option to update associations. It may well be that you need to use an association API call to link the deal and contact records in a specific direction:
Thank you for this. I had tried this earlier. and got stuck trying to figure out the ID's. Gave it another shot just now and it worked (seems I had the deal ID and contact ID reversed the first time) For future reference, this works (for me at least):
$hs_headers = array (
"Accept: application/json",
"Content-Type: application/json",
"authorization: Bearer " . YOUR_TOKEN_HERE
);
$useragent = "YOUR_USERAGENT_HERE";
function hs_post_curl($url, $headers, $useragent, $payload) {
$resource = curl_init($url);
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, true);
curl_setopt($resource, CURLOPT_ENCODING, "");
curl_setopt($resource, CURLOPT_MAXREDIRS, 10);
curl_setopt($resource, CURLOPT_TIMEOUT, 30);
curl_setopt($resource, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($resource, CURLOPT_POST, true);
// CUSTOMREQUEST must be PUT here instead of POST
curl_setopt($resource, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($resource, CURLOPT_HTTPHEADER, $headers);
curl_setopt($resource, CURLOPT_USERAGENT, $useragent);
curl_setopt($resource, CURLOPT_VERBOSE, 0);
curl_setopt($resource, CURLOPT_HEADER, 0);
curl_setopt($resource, CURLOPT_POSTFIELDS, $payload );
$response = curl_exec($resource);
curl_close($resource);
return json_decode($response);
}
// Deal ID is 20921572366
// Contact ID is 20921572366
$url = "https://api.hubapi.com/crm/v4/objects/deal/20921572366/associations/contacts/41547783742";
$assoc_payload = '[{"associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 3}]';
$result = hs_post_curl($url, $hs_headers, $useragent, $assoc_payload);
Kevin, I appreciate the response. It helps a little, I think. Still can't get it working. No real examples there and when I Google, I find all kinds of Q&A on these forums and on Stack, but when trying them, they don't work, and/or I get the 404 error. Kind of impossible to do this when many of the actual documentation links are not working. To make matters worse, I am getting nothing returned by my cURL call. No error, no response, no nothing. Been staring at this code for the better part of today, so I'm going to sleep on it. Hopefully the light goes on by the morning. 🙂