unable to create new Deal with association to contacts

Hi,

I’m unable to create new Deal with association to contacts.
I get associationTypeId & associationCategory from /crm/v4/associations/deals/contacts/labels

and here is JSON Body of request

{
 "properties": {
 "pipeline": "14520202",
 "dealstage": "39676476",
 "hubspot_owner_id": "387376030"
 },
 "associations": [
 {
 "to": {
 "id": 11175751
 },
 "types": [
 {
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 3
 }
 ]
 }
 ]
}

Can you please advice where I’m going wrong?
Thanks

@MKiyani where is this code? Is it a custom coded workflow? An integration?

Hi,
Yes its for an Integration to create deal on Hubspot with one contact.

@MKiyani what’s the integration?

I’ll tag my friends @jolle, @Jnix284, and @Kevin-C for some help.

@danmoyle sorry didnt get that what you mean, we got an application built in PHP, and want to create a method to create the deal on hubspot once our application got details and keep updating the deal on hubspot as soon as we get some update to that deal on our system, and for testing purpose right now I’m using postman to create deals.

for the above request I get this response

{
 "status": "error",
 "message": "one or more associations are not valid",
 "correlationId": "af980868-bdce-464e-a1b2-32989678a554",
 "category": "BAD_REQUEST"
}

Code Snippet:

<?php
$client = new Client();
$headers = [
 'Content-Type' => 'application/json',
 'Authorization' => 'Bearer pat-na1-***********-33a32646496a'
];
$body = '{
 "properties": {
 "pipeline": "14520202",
 "dealstage": "39676476",
 "hubspot_owner_id": "387376030"
 },
 "associations": [
 {
 "to": {
 "id": 11175751
 },
 "types": [
 {
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 3
 }
 ]
 }
 ]
}';
$request = new Request('POST', 'https://api.hubapi.com/crm/v3/objects/deals', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();

Thanks @Dan

Hey @MKiyani
Associations are bi-directional, meaning 1 direction number for contacts > Deal and another for Deals > Contacts. The direction numbers escape me at the moment, but I would try “4”. “3” may be the contact > Deal.

EDIT:

I was mistaken on the suggested direction IDs above:

  • Contact > Deal = 4
  • Deal > Contact = 3

Hi @Kevin-C

Tried with associationTypeId: 4 and get this error Response:

{
 "status": "error",
 "message": "invalid from object type 0-3 for associations to be created. expected: 0-1",
 "correlationId": "7ea972ec-b5f8-4a73-bcd5-b3b6205b49b7",
 "category": "VALIDATION_ERROR"
}

any update about this problem? I am getting the same error here

@Kevin-C you’re a rock star.

@danmoyle Yes it an integration, right now to understand the structure of request using postman to create deal with contact

Hi @danmoyle @Kevin-C
Response to this URI /crm/v4/associations/contacts/deals/labels:

{
 "results": [
 {
 "category": "HUBSPOT_DEFINED",
 "typeId": 4,
 "label": null
 }
 ]
}

Is label being null to this association a problem ?