Deals API / params not clear

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

But when I try this, GET https://api.hubapi.com/crm/v3/objects/associations/product/deal/types?hapikey=xxxx

Nothing is returned. Does that mean that we cannot link products and deals?

What am I missing? Thanks for your help.

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.

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 Accounts Dashboard | HubSpot

Thanks for your help

Hi inouire,

To create a line item you need the CREATE endpoint here: Accounts Dashboard | HubSpot.

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: Accounts Dashboard | HubSpot.

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 - Accounts Dashboard | HubSpot

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.

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? :downcast_face_with_sweat:

Thanks again

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

Happy to help :+1: