Hi, I’m trying to automate the association between a deal and existing contacts, the first approach was
1. Create a custom property called “email” on deals
2. Create an association type between the <email> of contacts (which already exist) and the <email> of deals
The expectation was something like
When I sent a request to the endpoint
`https://api.hubspot.com/crm/v3/objects/deals`
With body
{
"properties": {
"amount": "3213.00",
"closedate": "2019-12-07T16:50:06.678Z",
"dealname": "Deal 3",
"pipeline": "default",
"dealstage": "closedwon",
"hubspot_owner_id": "703759541",
"email": "<email>"
}
}
Then the new deal will be associated with the <email> from Contacts. This doesn’t work.
The second approach was to send a request to the endpoint.
`https://api.hubspot.com/crm/v3/objects/deals`
With body
{
"properties": {
"amount": "1500.00",
"closedate": "2019-12-07T16:50:06.678Z",
"dealname": "New deal",
"pipeline": "default",
"dealstage": "contractsent",
"hubspot_owner_id": "703759541"
},
"associations": [
{
"to": {
"email": <email>
},
"types": [
{
"associationCategory": "USER_DEFINED",
"associationTypeId": <value>
}
]
}
]
}
Where <email> is the email shared by the contact and deal, and value is as you expected, the associationTypeId, this approach won’t work, the API will send as response `Some required fields have not been set: [id]`, if email is chaged by id, the response is `Object not found. objectId are usually numeric`, again I do not want to use the objectId because this will add another request to the proccess. Maybe and and association type is not designed for what I need?
So, in summary, so far I can’t figure out how to make this association without the contactId, the other big issue is that this endpoint seems to accept a body with only one deal, this implies making n requests when I have n deals to create, any workarounds on this case?
If it helps, here are the two ways I can associate a deal with a contact (using the contactId or contactId/dealId as dependencies)
1. Request to
`https://api.hubspot.com/crm/v3/objects/deals`
with body
{
"properties": {
"amount": "1500.00",
"closedate": "2019-12-07T16:50:06.678Z",
"dealname": "New deal",
"pipeline": "default",
"dealstage": "contractsent",
"hubspot_owner_id": "703759541"
},
"associations": [
{
"to": {
"id": <contact_id>
},
"types": [
{
"associationCategory": "HUBSPOT_DEFINED",
"associationTypeId": 3
}
]
}
]
}
2. Request to
`https://api.hubspot.com/crm/v4/objects/contact/<contact_id>/associations/deal/<deal_id>`
With body
[
{
"associationCategory": "USER_DEFINED",
"associationTypeId": 1
}
]
Thank you so much in advance.