APIs & Integrations

JNichel
Participant

Add contact to deal after deal created

SOLVE

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:

 

https://developers.hubspot.com/docs/api/crm/deals#associations

 

You'll see a link for association type IDs (https://developers.hubspot.com/docs/api/crm/associations#association-type-id-values) but it 404's.

 

I've tried sending a post to the following URL:

 

https://api.hubapi.com/crm/v3/objects/deals/20901987235

 The number at the end of the URL is the deal ID, and this is the payload:

 

 

{
	"associations": [
		{
			"to": {"id": " . $custid . "},
			"types": [
				{
					"associationCategory": "HUBSPOT_DEFINED",
					"associationTypeId": 3
				}
			]
		}
	]
}

 

 

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?

0 Upvotes
1 Accepted solution
SteveHTM
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Add contact to deal after deal created

SOLVE

@JNichel - I'm suspecting that the PATCH Deal API call you are making: 

https://api.hubapi.com/crm/v3/objects/deals/{dealId}

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:

https://api.hubapi.com/crm/v4/objects/{objectType}/{objectId}/associations/{toObjectType}/{toObjectI...

 

Best of luck!

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature

View solution in original post

0 Upvotes
4 Replies 4
SteveHTM
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Add contact to deal after deal created

SOLVE

@JNichel - I'm suspecting that the PATCH Deal API call you are making: 

https://api.hubapi.com/crm/v3/objects/deals/{dealId}

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:

https://api.hubapi.com/crm/v4/objects/{objectType}/{objectId}/associations/{toObjectType}/{toObjectI...

 

Best of luck!

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Upvotes
JNichel
Participant

Add contact to deal after deal created

SOLVE

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

 

Thanks for the assistance!

0 Upvotes
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Add contact to deal after deal created

SOLVE

Hey @JNichel 

Check out this link for the V4 associatrion api endpoints. HS recently rolled out a new documentation website, and thats why you're seeing the 404s.

 

Hope this gets you going!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Upvotes
JNichel
Participant

Add contact to deal after deal created

SOLVE

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.  🙂

0 Upvotes