APIs & Integrations

inouire
Participant

Deals API / params not clear

SOLVE
Hi folks,
 
I'm working on the integration of Hubspot API. I want to link a Deal with some Products through the API, but the API doc does not tell me much about it.

The doc tells me things about the endpoints, but not really about the possible values to use as params https://developers.hubspot.com/docs/api/crm/deals > Associate a deal with another object
In that precise case I don't know what to put under "associationType"
 
I also had a look at the association API, https://developers.hubspot.com/docs/api/crm/associations
Nothing is returned. Does that mean that we cannot link products and deals?
 
What am I missing? Thanks for your help.
 
0 Upvotes
1 Accepted solution
WaydeChristie1
Solution
Contributor

Deals API / params not clear

SOLVE

Hi inouire,

 

To create a line item you need the CREATE endpoint here: https://developers.hubspot.com/docs/api/crm/line-items.

 

Here's an example POST body:

 

{
"name": "1 year implementation consultation",
"hs_product_id": "191902",
"hs_recurring_billing_period": "24",
"recurringbillingfrequency": "monthly",
"quantity": "2",
"price": "6000.00"
}

 
Ideally the line item should include a reference to a Hubspot product ID ("hs_product_id"), as line-items are a subset of products.

 

When the line item has been created the API will return the line item object ID. You'll need this ID to then associate the line item with a deal.

 

You associate the line item with the deal using the"Associate a line item with another object" endpoint here: https://developers.hubspot.com/docs/api/crm/line-items.

 

To do so, send a PUT request using this URL format:

 

https://api.hubapi.com/crm/v3/objects/line_items/{{yourline item object id}}/associations/deal/{{your deal object ID}}/line_item_to_deal (not including the curly brackets).

 

The "line_item_to_deal" segment of the URL tells Hubspot how to associate the two objects. You can use this format for associating most objects. eg. Associating a deal to a contact uses this endpoint URL:  https://api.hubapi.com/crm/v3/objects/deals/{{deal ID}}/associations/contact/{{contactID}}/deal_to_contact

 

You can also use the Associations API to batch associate multiple line items to a single deal - https://developers.hubspot.com/docs/api/crm/associations

 

The endpoint URL you'll need for that is:

 

https://api.hubapi.com/crm/v3/associations/line_items/deals/batch/create

 

And this is the body you'll need to POST:

 

{
    "inputs": [
        {
            "from": {
                "id": "{{line item ID}}"
            },
            "to": {
                "id": "{{deal ID}}"
            },
            "type": "line_item_to_deal"
        },
        {
            "from": {
                "id": "{{another line item ID}}"
            },
            "to": {
                "id": "{{deal ID}}"
            },
            "type": "line_item_to_deal"
        }
    ]
}

 

Unfortunately there isn't a way to create a line item and associate it with a deal in one step, like there used to be in the old API. Now it's necessary to use object association methods, or the associations API.

 

Hope this helps.

View solution in original post

WaydeChristie1
Solution
Contributor

Deals API / params not clear

SOLVE

Hi inouire,

 

To create a line item you need the CREATE endpoint here: https://developers.hubspot.com/docs/api/crm/line-items.

 

Here's an example POST body:

 

{
"name": "1 year implementation consultation",
"hs_product_id": "191902",
"hs_recurring_billing_period": "24",
"recurringbillingfrequency": "monthly",
"quantity": "2",
"price": "6000.00"
}

 
Ideally the line item should include a reference to a Hubspot product ID ("hs_product_id"), as line-items are a subset of products.

 

When the line item has been created the API will return the line item object ID. You'll need this ID to then associate the line item with a deal.

 

You associate the line item with the deal using the"Associate a line item with another object" endpoint here: https://developers.hubspot.com/docs/api/crm/line-items.

 

To do so, send a PUT request using this URL format:

 

https://api.hubapi.com/crm/v3/objects/line_items/{{yourline item object id}}/associations/deal/{{your deal object ID}}/line_item_to_deal (not including the curly brackets).

 

The "line_item_to_deal" segment of the URL tells Hubspot how to associate the two objects. You can use this format for associating most objects. eg. Associating a deal to a contact uses this endpoint URL:  https://api.hubapi.com/crm/v3/objects/deals/{{deal ID}}/associations/contact/{{contactID}}/deal_to_contact

 

You can also use the Associations API to batch associate multiple line items to a single deal - https://developers.hubspot.com/docs/api/crm/associations

 

The endpoint URL you'll need for that is:

 

https://api.hubapi.com/crm/v3/associations/line_items/deals/batch/create

 

And this is the body you'll need to POST:

 

{
    "inputs": [
        {
            "from": {
                "id": "{{line item ID}}"
            },
            "to": {
                "id": "{{deal ID}}"
            },
            "type": "line_item_to_deal"
        },
        {
            "from": {
                "id": "{{another line item ID}}"
            },
            "to": {
                "id": "{{deal ID}}"
            },
            "type": "line_item_to_deal"
        }
    ]
}

 

Unfortunately there isn't a way to create a line item and associate it with a deal in one step, like there used to be in the old API. Now it's necessary to use object association methods, or the associations API.

 

Hope this helps.

inouire
Participant

Deals API / params not clear

SOLVE

Thanks a lot @WaydeChristie1 , it seems exactly what I need, I'll try it today.
Why isn't the API doc as clear as your comment? 😓

Thanks again

0 Upvotes
WaydeChristie1
Contributor

Deals API / params not clear

SOLVE

You'll have an a-ha moment with the docs eventually, like I did. They're actually very well written,

 

Happy to help 👍

0 Upvotes
Teun
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Deals API / params not clear

SOLVE

Hi @inouire ,

 

If you link a product to a deal, it becomes a line item. It has its own API, so that should get you started.



Did my answer solve your issue? Help the community by marking it as the solution.
inouire
Participant

Deals API / params not clear

SOLVE

Thank you @Teun  for your reply.

 

I understand the concept, but it does not make sense when I look at the existing endpoints in API v3.
I find no endpoint to "create" a line item directly. And I don't understand which association to use to link a product to a deal (my initial question, GET https://api.hubapi.com/crm/v3/objects/associations/product/deal/types?hapikey=xxxx returns empty results, what association key should I use when I associate a product and a deal ?)

 

Strangely, I feel like it's more logical in previous version of the API like this one https://legacydocs.hubspot.com/docs/methods/line-items/create-line-item

 

Thanks for your help

0 Upvotes