# CRM API v4 Line Item Association Not Working (Python)

**URL:** <https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [October 17, 2022, 3:34pm UTC](https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290 "2022-10-17T15:34:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![eibach-cv](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/eibach-cv/32/52876_2.png) [@eibach-cv](https://community.hubspot.com/u/eibach-cv)\
**Post date:** [October 17, 2022, 3:34pm UTC](https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290/1 "2022-10-17T15:34:37Z")

</div>

I am using the Python request shown in the [Hubspot v4 CRM API docs](https://developers.hubspot.com/docs/api/crm/line-items) to associate a line item to a deal, but I am getting an error saying the attribute the docs provide doesn’t exist:

```lia-code-sample
api_response = client.crm.line_items.associations_api.items_line_item_id_associations_to_object_type_to_object_id_association_type(line_item_id=lineitem_id, to_object_type="deal", to_object_id=hs_deal_id, association_type="line_item_to_deal")
AttributeError: 'AssociationsApi' object has no attribute 'items_line_item_id_associations_to_object_type_to_object_id_association_type'

```

Here is my request:

```lia-code-sample
try:
	api_response = client.crm.line_items.associations_api.items_line_item_id_associations_to_object_type_to_object_id_association_type(line_item_id=lineitem_id, to_object_type="deal", to_object_id=hs_deal_id, association_type="line_item_to_deal")
	pprint(api_response)
	pprint("Line Item associated to Deal ID " + hs_deal_id)
except ApiException as e:
	print("Exception when calling associations_api->items_line_item_id_associations_to_object_type_to_object_id_association_type: %s\n" % e)

```

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [October 18, 2022, 9:10am UTC](https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290/2 "2022-10-18T09:10:28Z")

</div>

Hey [@](https://community.hubspot.com/t5/user/viewprofilepage/user-id/379041)[eibach-cv](https://community.hubspot.com/t5/user/viewprofilepage/user-id/148664)

**Hey there, this is the structure for associating a line item to a deal**

**API Endpoint :**

**POST Request :**

[**https://api.hubapi.com/crm/v3/associations/Line\_items/Deal/batch/create?hapikey=YOUR-API-KEY**](https://api.hubapi.com/crm/v3/associations/Line_items/Deal/batch/create?hapikey=fe4d5d68-a78a-4335-910a-b9f6180da15a)

**Association Type :**

**Line\_item\_to\_deal**

**Body parameters :**

**{**

**“inputs”: [**

**{**

**“from”: {**

**“id”: “line\_item\_id”**

**},**

**“to”: {**

**“id”: “deal\_id”**

**},**

**“type”: "Line\_item\_to\_deal”**

**}**

**]**

**}**

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

---

<div class="post-metadata">

**Author:** ![eibach-cv](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/eibach-cv/32/52876_2.png) [@eibach-cv](https://community.hubspot.com/u/eibach-cv)\
**Post date:** [October 18, 2022, 3:06pm UTC](https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290/3 "2022-10-18T15:06:59Z")

</div>

I am using the **v4 CRM API** , which doesn’t have anywhere to put that

```lia-code-sample
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.items_line_item_id_associations_to_object_type_to_object_id_association_type(line_item_id="lineItemId", to_object_type="toObjectType", to_object_id="toObjectId", association_type="associationType")
 pprint(api_response)
except ApiException as e:
 print("Exception when calling associations_api->items_line_item_id_associations_to_object_type_to_object_id_association_type: %s\n" % e)

```

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [October 19, 2022, 9:44am UTC](https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290/4 "2022-10-19T09:44:49Z")

</div>

Hey [@](https://community.hubspot.com/t5/user/viewprofilepage/user-id/379041)[eibach-cv](https://community.hubspot.com/t5/user/viewprofilepage/user-id/148664)

Hey there this is the Python Requests method code of V4 associations between line item and a deal - \>

import requests

import json

url = “[https://api.hubapi.com/crm/v4/associations/Line\_items/Deal/batch/create](https://api.hubapi.com/crm/v4/associations/Line_items/Deal/batch/create)”

payload = json.dumps({

“from”: {

“id”: “3896954000”

},

“to”: {

“id”: “10248246000”

},

“type”: “line\_item\_to\_deal”

})

headers = {

‘authorization’: 'Bearer YOUR-TOKEN,

‘Content-Type’: ‘application/json’

}

response = requests.request(“POST”, url, headers=headers, data=payload)

print(response.text)

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

---

<div class="post-metadata">

**Author:** ![eibach-cv](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/eibach-cv/32/52876_2.png) [@eibach-cv](https://community.hubspot.com/u/eibach-cv)\
**Post date:** [October 19, 2022, 3:01pm UTC](https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290/5 "2022-10-19T15:01:00Z")

</div>

Can you point me to the docs for this request? I am unable to find them.

When I run this request, I’m getting empty results and no line items are being assigned

```lia-code-sample
{"from": {"id": "3909146497"}, "to": {"id": "10614779689"}, "type": "line_item_to_deal"}

{"status":"COMPLETE","results":[],"startedAt":"2022-10-19T14:47:25.395Z","completedAt":"2022-10-19T14:47:25.395Z"}

```

Why do you use/why are you recommending I use that request instead of the one from the line item documentation page pictured below? I use this one for all my other associations, but there seems to be an issue on Hubspot’s end that I am trying to point out/resolve.

 ![Screenshot_4.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/4/b/4b717aab6467fe4e1bbdebe50d99a66888b60394.png)

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [October 20, 2022, 7:41am UTC](https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290/6 "2022-10-20T07:41:10Z")

</div>

Hey [@](https://community.hubspot.com/t5/user/viewprofilepage/user-id/379041)[eibach-cv](https://community.hubspot.com/t5/user/viewprofilepage/user-id/148664)

V3 is working fine

V4 is having some issues as V4 versions of the APIs are still in development phase, they will work properly after 30th November as HubSpot is sunsetting many API endpoints and versions and updating some changes to the existing ones,

[https://api.hubapi.com/crm/v3/objects/line\_items/{line-item-id}/associations/deals/{deal id}/line\_item\_to\_deal](https://api.hubapi.com/crm/v3/objects/line_items/%7Bline-item-id%7D/associations/deals/%7Bdeal%20id%7D/line_item_to_deal)

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

---

<div class="post-metadata">

**Author:** ![CIPS](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@CIPS](https://community.hubspot.com/u/CIPS)\
**Post date:** [October 18, 2022, 5:02pm UTC](https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290/7 "2022-10-18T17:02:08Z")

</div>

V3 works for me, thanks. I had to fix the last ‘"’ since its a diff char than the rest.

---

<div class="post-metadata">

**Author:** ![CIPS](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@CIPS](https://community.hubspot.com/u/CIPS)\
**Post date:** [October 18, 2022, 4:50pm UTC](https://community.hubspot.com/t/crm-api-v4-line-item-association-not-working-python/67290/8 "2022-10-18T16:50:58Z")

</div>

Not working for me either! Also the cURL request doesn’t change when modifying the association type id which seems wrong

“AttributeError: ‘AssociationsApi’ object has no attribute ‘items\_line\_item\_id\_associations\_to\_object\_type\_to\_object\_id\_association\_type’”
