APIs & Integrations

eibach-cv
Contributor

CRM API v4 Line Item Association Not Working (Python)

I am using the Python request shown in the Hubspot v4 CRM API docs to associate a line item to a deal, but I am getting an error saying the attribute the docs provide doesn't exist:

 

 

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:

 

 

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)

 

 

7 Replies 7
CIPS
Contributor | Diamond Partner
Contributor | Diamond Partner

CRM API v4 Line Item Association Not Working (Python)

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'"

0 Upvotes
ChehakWadhdwa
Member | Diamond Partner
Member | Diamond Partner

CRM API v4 Line Item Association Not Working (Python)

Hey  @eibach-cv

 

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

 

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.

0 Upvotes
CIPS
Contributor | Diamond Partner
Contributor | Diamond Partner

CRM API v4 Line Item Association Not Working (Python)

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

0 Upvotes
eibach-cv
Contributor

CRM API v4 Line Item Association Not Working (Python)

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

 

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)

 

0 Upvotes
ChehakWadhdwa
Member | Diamond Partner
Member | Diamond Partner

CRM API v4 Line Item Association Not Working (Python)

Hey  @eibach-cv

 

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"

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.

0 Upvotes
eibach-cv
Contributor

CRM API v4 Line Item Association Not Working (Python)

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

{"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

0 Upvotes
ChehakWadhdwa
Member | Diamond Partner
Member | Diamond Partner

CRM API v4 Line Item Association Not Working (Python)

Hey  @eibach-cv

 

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_it...

 

Hope this helps!

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

Thanks and Regards.

0 Upvotes