APIs & Integrations

SLoomb
Participant

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 "

https://api.hubapi.com/crm/v3/objects/deals/{deal_id}/associations/line_items".  Thanks, any assistance would be greatly appreciated. 
0 Upvotes
1 Accepted solution
MichaelMa
Solution
Contributor

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. 

 

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.

 

View solution in original post

4 Replies 4
MichaelMa
Contributor

Trying to pull through a contract (or billing start date)

SOLVE
After you run that association API request, are you then running another request on the Line Item IDs to retrieve the properties of each Line Item?
 
If you don't want to do multiple calls, you might consider doing a GraphQL call which can pull all the data in a single go.
0 Upvotes
SLoomb
Participant

Trying to pull through a contract (or billing start date)

SOLVE

Hi Michael,

 

I don't mind running multiple requests i.e. this is what I'm doing to get the company name

 
# Fetch associated company
company_response = requests.get(f"https://api.hubapi.com/crm/v3/objects/deals/{deal_id}?associations=companies", headers=headers)
company_id = company_response.json().get("associations", {}).get("companies", {}).get("results", [{}])[0].get("id")

# Fetch company name
company_name = "Unknown"
if company_id:
company_name_response = requests.get(f"https://api.hubapi.com/crm/v3/objects/companies/{company_id}?properties=name", headers=headers)
company_name = company_name_response.json().get("properties", {}).get("name", "Unknown")
 
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
 
 
 

 

0 Upvotes
MichaelMa
Solution
Contributor

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. 

 

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.

 

SLoomb
Participant

Trying to pull through a contract (or billing start date)

SOLVE

Thanks that worked!

0 Upvotes