Unable to Associate Line Item to Deal

According to Hubspot API docs, I should use this request to make a line item assocaition to a deal

import hubspot
from pprint import pprint
from hubspot.crm.line_items import ApiException

client = hubspot.Client.create(access_token="YOUR_ACCESS_TOKEN")

try:
 api_response = client.crm.line_items.associations_api.create(line_item_id=7, to_object_type="deal", to_object_id=12, association_spec=[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":20}])
 pprint(api_response)
except ApiException as e:
 print("Exception when calling associations_api->create: %s\n" % e)

But when I use that code in my program, I get an error saying

TypeError: create() missing 1 required positional argument: 'association_type'

I can’t find “association_type” anywhere in the docs, to know how to use it.

Side note, would be greatly appreciated if the docs also listed the defualt assocationTypeId’s. Took way to long to find it is 20 for line_item to deal.

Hey, @eibach-cv :waving_hand: Have you tried including

"type": "line_items_to_deal"

in your request body?

I created a similar association recently using Postman, and here’s my request body:

{"inputs": 
 {
 "from": {
 "id": "3384029484"
 },
 "to": {
 "id": "9476351578"
 },
 "type": "line_items_to_deal"
 }
}

Best,

Jaycee

Hi Jaycee,

I tried adding

association_type="line_item_to_deal"

to my request (I am using Python so I used the syntax from other examples), but then I get a new error saying not to use association_spec (but the HS docs say to use it)

Got an unexpected keyword argument 'association_spec' to method create

This is my full request with the new code

try:
 api_response = client.crm.line_items.associations_api.create(line_item_id=lineitem_id, to_object_type="deal", to_object_id=hs_deal_id, association_spec=[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":20}], association_type="line_item_to_deal")
 pprint(api_response)
except ApiException as e:
 print("Exception when calling associations_api->create: %s\n" % e)