I am trying to extract company data with multiple properites, but I can only add one property to one request.
max_results = 500
hapikey = ‘***’
limit = 250
property_list = []
property_list.append(‘name’)
properties = ‘’
company_list = []
get_all_companies_url = “https://api.hubapi.com/companies/v2/companies/paged? ”
parameter_dict = {‘hapikey’: hapikey, ‘limit’: limit, ‘properties’: properties}
headers = {}
# Paginate your request using offset
has_more = True
while has_more:
parameters = urllib.parse.urlencode(parameter_dict)
get_url = get_all_companies_url + parameters
r = requests.get(url= get_url, headers = headers )
response_dict = json.loads(r.text)
has_more = response_dict[‘has-more’]
company_list.extend(response_dict[‘companies’])
parameter_dict[‘offset’]= response_dict[‘offset’]
if len(company_list) >= max_results: # Exit pagination, based on whatever value you’ve set your max results variable to.
print(‘maximum number of results exceeded’)
break
print(‘loop finished’)
list_length = len(company_list)
print(“You’ve succesfully parsed through {} company records and added them to a list”.format(list_length))
I bet @taran42 can help out here
@dennisedson Actually, I can.
@VDrigin You want to get your company properties through URL parameters. See below.
get_all_companies_url = "https://api.hubapi.com/companies/v2/companies/paged?&properties=property1&properties=property1&"
You’ll want to remove that bit of properties code you have under your parameter_dict .
Hi,
I am facing different issue, I can access multilpe properties now, but not all of them.
It seems like I do not know API names for them. For example, I can not access ‘Last activity date’.
@VDrigin ,
Two methods of getting the property internal names
1. through the properties api
2. Via the Portal UI
Thank you, that works.
Now I am facing a different issue as ‘Last activity date’ I am getting numbers such as 1623062746000.
I have no idea what they mean and how to convert them to dates. At first I thought those were datetimestamps, but python does not understand them.
Could you advise how to covrert those numbers to dates, ideally in Python?
Thank you!
@VDrigin
That is unix time code in milliseconds which is the typical method HubSpot will return dates
@taran42 is my go to for these types of questions. Gonna make a Community Champion out of you yet
I did a quick google as python is not in my vocabularly, sadly
Here is what I got. @taran42 , correct whatever is wrong
import datetime
print(
datetime.datetime.fromtimestamp(
int("1284105682")
).strftime('%Y-%m-%d %H:%M:%S')
)
I have tried the code above before.
Python does not understand this timestamp.
Thank you for your time! HubSpot Community is really supportive
@dennisedson Does that mean I’ll be making the big bucks, like you?
@VDrigin What Dennis posted is correct. I threw it into a quick script and got the proper output. See below.
system
June 7, 2021, 11:06am
11
Hi @VDrigin ,
Please check and use this :
Add properties with url for fetching.
Example 1 for fetch properties with single
<?php
$get_all_companies_url = “https://api.hubapi.com/companies/v2/companies/paged?properties=name&properties=xvz ”
?>
OR
if you want more properties details for that then fetch full contacts details usings loop.
<?php
foreach($get_all_companies_url as $k => $val){
$vid = $val->vid;
$get_all_companies_url = “https://api.hubapi.com/contacts/v1/contact/vid/“.$vid.”/profile?hapikey=demo ”;
}
?>
Hope this helps!
If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.