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.