# Getting billing effective date from Deals using API

**URL:** <https://community.hubspot.com/t/getting-billing-effective-date-from-deals-using-api/89611>\
**Category:** APIs & Integrations\
**Tags:** python, oauth, object, professional\
**Created:** [September 13, 2023, 11:25pm UTC](https://community.hubspot.com/t/getting-billing-effective-date-from-deals-using-api/89611 "2023-09-13T23:25:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmiao](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@hmiao](https://community.hubspot.com/u/hmiao)\
**Post date:** [September 13, 2023, 11:25pm UTC](https://community.hubspot.com/t/getting-billing-effective-date-from-deals-using-api/89611/1 "2023-09-13T23:25:00Z")

</div>

I am trying to extract data from hubspot deals using the access token given by my mentor. Blow is my code for the extraction,

```lia-code-sample
import requests
import json
import urllib
import csv
# Set your variables
max_results = 3100
access_token = 'my access token'
limit = 100
deal_list = []
get_all_deals_url = "https://api.hubapi.com/crm/v3/objects/deals"

# Set up the headers, including the OAuth 2.0 access token
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}

# Set up the initial parameters
parameter_dict = {
'limit': limit,
}

while True:
# Make the API request
response = requests.get(get_all_deals_url, headers=headers, params=parameter_dict)

# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response
data = response.json()

# Print the first deal data to inspect the structure
if data['results']:
print(json.dumps(data['results'][0], indent=4))
deal_list.extend(data['results'])

# Check if there are more pages
if data.get('paging', {}).get('next', {}).get('after'):
parameter_dict['after'] = data['paging']['next']['after']
else:
break
else:
# If the request was not successful, print the error
print(f"Failed to retrieve deals: {response.status_code}")
print(response.text)
break

# Extract the necessary properties and write to a CSV
with open('deals.csv', 'w', newline='', encoding='utf-8') as output_file:
writer = csv.writer(output_file)
writer.writerow(['id', 'created_at', 'updated_at', 'deal_name', 'is_archived']) # Header

for deal in deal_list:
deal_id = deal.get('id')
created_at = deal.get('createdAt')
updated_at = deal.get('updatedAt')
deal_name = deal.get('properties', {}).get('dealname')
is_archived = deal.get('archived')

writer.writerow([deal_id, created_at, updated_at, deal_name, is_archived])

```

here is the output that I have,

{  
&nbsp;&nbsp;&nbsp;&nbsp;“id”: “…”,  
&nbsp;&nbsp;&nbsp;&nbsp;“properties”: {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“amount”: “4342”,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“closedate”: “2019-10-22T06:00:00Z”,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“createdate”: “2018-10-04T07:00:00Z”,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“dealname”: “A Good Timeout - New Deal”,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“dealstage”: “closedlost”,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“hs\_lastmodifieddate”: “2019-10-09T06:15:20.930Z”,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“hs\_object\_id”: “…”,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“pipeline”: “default”  
&nbsp;&nbsp;&nbsp;&nbsp;},  
&nbsp;&nbsp;&nbsp;&nbsp;“createdAt”: “2020-10-05T07:00:00Z”,  
&nbsp;&nbsp;&nbsp;&nbsp;“updatedAt”: “2023-09-06T06:15:20.930Z”,  
&nbsp;&nbsp;&nbsp;&nbsp;“archived”: false  
}

the issue that I have is that it does not return the source of a deal property named ‘billing effective date’.

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [September 14, 2023, 1:10am UTC](https://community.hubspot.com/t/getting-billing-effective-date-from-deals-using-api/89611/2 "2023-09-14T01:10:44Z")

</div>

Hi @hmiao 👋

The endpoint you are calling allows you to specify properties to be returned using the “properties” querystring parameter. In this case, an individual property is specified using its internal “name”. Assuming your target property, ‘Billing Effective Date’, has the internal name “billing\_effective\_date”, you can add this to your request parameters like this:

```lia-code-sample
...
# Set up the initial parameters
parameter_dict = {
'limit': limit,
'properties': 'billing_effective_date'
}
...

```

_Note, to return multiple properties, separate them with a comma (e.g. ‘billing\_effective\_date,example\_property\_x’)_

Finding the internal “name” of a property can be done by:

1. HubSpot web UI
  - Settings \> Properties \> _{Object Type}_ \> _{Property}_ Edit \> Click the “\</\>” icon to the right of the property “Label”

2. [HubSpot Properties API](https://developers.hubspot.com/docs/api/crm/properties)
  - **GET** [https://api.hubapi.com/crm/v3/properties/:OBJECT\_TYPE](https://api.hubapi.com/crm/v3/properties/:OBJECT_TYPE)
  - **Headers** :
    - Accept: application/json
    - Authorization: Bearer _{{your\_access\_token}}_

  - Retrieve internal property name from response JSON:
    - _results[n].name_

I hope this proves useful. Please let me know if you have any follow-up questions.

---

<div class="post-metadata">

**Author:** ![hmiao](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@hmiao](https://community.hubspot.com/u/hmiao)\
**Post date:** [September 14, 2023, 1:57am UTC](https://community.hubspot.com/t/getting-billing-effective-date-from-deals-using-api/89611/3 "2023-09-14T01:57:28Z")

</div>

Thank you so much for response, I tried and my output looks like this,

{ “id”: “…”, “properties”: { “createdate”: “2020-10-05T07:00:00Z”, “hs\_lastmodifieddate”: “2023-09-06T06:15:20.930Z”, “hs\_object\_id”: “…” }, “createdAt”: “2020-10-05T07:00:00Z”, “updatedAt”: “2023-09-06T06:15:20.930Z”, “archived”: false }

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [September 14, 2023, 2:14am UTC](https://community.hubspot.com/t/getting-billing-effective-date-from-deals-using-api/89611/4 "2023-09-14T02:14:20Z")

</div>

Hi @hmiao 👋

Looks like your target property was not returned. I recommend double-checking the following:

1. The ‘billing effective date’ property is in fact a Deal property within the HubSpot portal you are querying.
2. You are referencing the property’s internal name exactly in your request. This can be checked by following the instructions from my previous message.

Let me know how you go 🙂

---

<div class="post-metadata">

**Author:** ![webwarriors](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/webwarriors/32/66085_2.png) [@webwarriors](https://community.hubspot.com/u/webwarriors)\
**Post date:** [November 28, 2023, 7:21am UTC](https://community.hubspot.com/t/getting-billing-effective-date-from-deals-using-api/89611/5 "2023-11-28T07:21:06Z")

</div>

@hmiao - I also found out this:

- If the Billing Start Date is a specific date, the

- If the Billing Start Date is a delay of days or months, then check the values for hs\_billing\_start\_delay\_days or hs\_billing\_start\_delay\_months - these are automatically set by HubSpot
