Your code is a perfect example of what you would need to do to get the data.
To reiterate, you want to retrieve the property “hs_recurring_billing_start_date” from the Line Items of the deal (if more than 1 Line Item, then there are more than 1 “hs_recurring_billing_start_date” even if they might be the same value).
In part 1 of your code, you’re pulling the IDs of the company associated with the Deal.
In part 2, you’re using the ID you pulled to pull in the rest of the data (the name) that you need.
You would need to do the same with Line Items. You first fetch all the Line Items associated with the deal.
Rough code below:
# Fetch associated line items
line_items_response = requests.get(f"https://api.hubapi.com/crm/v3/objects/deals/{deal_id}?associations=line_items", headers=headers)
line_item_ids = line_items_response.json().get("associations", {}).get("line items", {}).get("results", [{}])
Once you have the Line Item IDs, you can then retrieve the Line Item data. You likely should do a BATCH request to get them all at once instead of multiple requests.
# Request line items from deal
line_items = line_item_ids.get("associations", {}).get("line items", {}).get("results", [{}])
# Builds the basic batch data request payload
line_item_request = {"inputs": [], "properties": ["hs_recurring_billing_start_date"]}
# Add the Line Item IDs to the request
for l in line_items:
line_item_request["inputs"].append({"id": l["id"]})
# BATCH request from hubspot
line_item_data = requests.post(f"https://api.hubapi.com/crm/v3/objects/line_items/batch/read", headers=headers, json=line_item_request)
Once you do your batch request, you then have to iterate over response to obtain the data that you want which is the “hs_recurring_billing_start_date” value.
All rough code so sorry if it doesn’t compile.
An alternative is doing a GraphQL request which you can retrieve all the data in a single request.