Trying to pull through a contract (or billing start date)
SOLVE
Hi there,
I'm trying to extract (integrate to) the hs_recurring_billing_start_date field which I have selected as a custom date when entering the line items for a deal. I am able to extract all other information I need from the line items and other info from the deal - including the Company name.
The problem I have is that the 'hs_recurring_billing_start_date' seems to be in the Subscription Information Group and I cannot seem to link to it. Is there any way I can do this or do I need to request all users of our app create a custom field for the start date (a potential issue with this is that each line item could have a different start date). Here is an example of how I'm extracing the line items in python "
Trying to pull through a contract (or billing start date)
SOLVE
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.
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.
My real problem is how to get the billing start date (which is effectively) the contract start date for each line item when the 'hs_recurring_billing_start_date' resides in the Subscription Information group
Trying to pull through a contract (or billing start date)
SOLVE
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.
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.