Get associations with deals from crm objects deals endpoint

SOLVE
antonr12
Member

Hello,

 

I'm working on interation with Hubspot's API in order to extract our deals using the 

"https://api.hubapi.com/crm/v3/objects/deals" endpoint.

 

At the beginnig, I tried the "V1" endpoint - https://api.hubapi.com/deals/v1/deal/paged

but the properties field didn't work for me - it didn't return the required fields

 
Therefore, I moved to the "https://api.hubapi.com/crm/v3/objects/deals" endpoint.
It worked fine except to the fact that at this endpoint, it doesn't return association.
I tried to add "includeAssociations=true" or "associations=" with Associtation ID or Associations' name
 
Example:
or
 
(associations - Array of stringsQuery param.A comma separated list of the properties to be returned in the response. If any of the specified properties are not present on the requested object(s), they will be ignored.)

 

 

Neither of them worked.
My question is how can I use the "api.hubapi.com/crm/v3/objects/deals" endpoint to include also associations? Or should I use the "https://api.hubapi.com/deals/v1/deal/paged" and find a way to pass the parameters correctly?
 

 

 

Thank you,

Anton.

 
1 Accepted solution

Accepted Solutions
MCullenSSG
Solution
Member

I added as part of the Query String;

https://api.hubapi.com/crm/v3/objects/deals?hapikey= KEY &associations=companies

And I get this returned from the beta endpoints:

"associations": {
   "companies": {
      "results": [
         {
            "id": "123456789"
         }
      ]
   }
},

You can then add more e.g.;

 

&associations=companies,contacts

And get more responses of associations;

"associations": {
"companies": { "results": [ { "id": "123456789" } ] }, "contacts": { "results": [ { "id": "1234345678" } ] } },

View solution in original post

7 Replies 7
Willson
HubSpot Employee

Hi @antonr12 

 

Taking a look through your question, I cannot see specifically the required query parameters needed to return associations for deals (feel free to correct me if I am mistaken).

 

As per the documenatation found here, you can find associations for deals using the associations.{objectType} pseudo-property. 

 

For Deals, these are the supported association filters:

Object type

Filter propertyName

deals

associations.company,
associations.contact,
associations.ticket

 

As an example, your request URL would be the following:

POST https://api.hubapi.com/crm/v3/objects/Deals/search?hapikey={{hapikey}}

You'll then include the sample request body as your filters:

      {
        "propertyName": "associations.contact",
        "operator": "EQ",
        "value": "ASSOCIATED_CONTACT_ID"
      }

You'll then get a response along the lines of:

    "total": 21,
    "results": [
        {
            "id": "id",
            "properties": {
                "amount": "17700",
                "closedate": "2019-06-30T07:43:15.076Z",
                "dealname": "Test",
                "dealstage": "c51cd404-82cc-4c1c-9d95-a8a89f125251",
                "pipeline": "default"
            },
            "createdAt": "2019-06-21T07:43:15.077Z",
            "updatedAt": "2019-06-21T07:43:39.521Z",
            "archived": false
        },

// SNIPPET CUT //

 

I hope this helps!

Product Expert | Customer Support
HubSpot
0 Upvotes
antonr12
Member

Thank you for your response.

 

It helps but my intentions are to find out how to get the associations using the deals API

https://api.hubapi.com/crm/v3/objects/deals?hapikey=my_api_key&properties=hs_object_id,hs_lastmodifi...??

 

The options to specify the association exists as a query field, I would like to find out in which format I should enter the parms there.

 

Thanks again,

Anton.

 

0 Upvotes
MCullenSSG
Member

I added as part of the Query String;

https://api.hubapi.com/crm/v3/objects/deals?hapikey= KEY &associations=companies

And I get this returned from the beta endpoints:

"associations": {
   "companies": {
      "results": [
         {
            "id": "123456789"
         }
      ]
   }
},

You can then add more e.g.;

 

&associations=companies,contacts

And get more responses of associations;

"associations": {
"companies": { "results": [ { "id": "123456789" } ] }, "contacts": { "results": [ { "id": "1234345678" } ] } },
0 Upvotes
MCullenSSG
Solution
Member

I added as part of the Query String;

https://api.hubapi.com/crm/v3/objects/deals?hapikey= KEY &associations=companies

And I get this returned from the beta endpoints:

"associations": {
   "companies": {
      "results": [
         {
            "id": "123456789"
         }
      ]
   }
},

You can then add more e.g.;

 

&associations=companies,contacts

And get more responses of associations;

"associations": {
"companies": { "results": [ { "id": "123456789" } ] }, "contacts": { "results": [ { "id": "1234345678" } ] } },

View solution in original post

antonr12
Member

Thanks, it works great!

0 Upvotes
Willson
HubSpot Employee

Hi @antonr12 

 

The solution there from @MCullenSSG is correct with how the query parameters should be passed. 

 

Simply appending the parameter to the Request URL with the form &associations=OBJECT should suffice to then return the ID of the associatied object.

 

I hope this helps!

Product Expert | Customer Support
HubSpot
0 Upvotes
jarbot001
Contributor

It's been over a year since this was solved, I've tried the &associations=companies approach, and I'm not getting 'associations' in they returned payload.  I tried adding it in the post payload similar to 'properties' as an array, but that did not work either.

Is this still supposed to be working?

 

Update: this does work when using crm/v3/objects/deals/ but not crm/v3/objects/deals/search

0 Upvotes