Hallo, I try to accsess some data via an api call and Python:
"client.crm.companies.basic_api.get_page()"
In the documentation its written that the response is a json file.
When i try to save the response as a jason file I encounter several errors.
Im not experienced when it comes to the use of json so I might miss something here. First I tried to save the response with json.dump() wich led to several serialization errors. I tried some workarounds but none of them solved the problem and everything got far to complicated. Shouldnt it be possbile to just save the api response as a JSON file with a simple command.
Nov 30, 20238:26 AM - edited Nov 30, 20238:30 AM
Member
How to use the JSON API response
No need to create custom serialization classes (and obviously you can't change hubspot api classes as well), as others suggested!
All you have to do, is to search for a to_dict function inside the desired class, e.g. for PublicUser class I've searched (and found) to_dict function. This function is there for any model in hubspot api!
Code sample showcasing how to serialize the results list (where item in my example is of a PublicUser class type):
match self.hubspot_object: case "USERS": write_ndjson_to_s3(hubspot_dump_s3_path, list(map(lambda item: json.dumps(item.to_dict()), results)), custom_serialized=True) # noqa: E501 case _: write_ndjson_to_s3(hubspot_dump_s3_path, results)
May 24, 202210:48 AM - edited May 24, 202210:49 AM
Participant
How to use the JSON API response
But im just using the API response not my own Python Class. Why cant I just take the api response that already should be a json file and save it somewehre?
I looked up your suggestions, but how should I edit a class that comes from Hubspot. class 'hubspot.crm.companies.models.collection_response_simple_public_object_with_associations_forward_paging.CollectionResponseSimplePublicObjectWithAssociationsForwardPaging'
Have you received an update on your problem or were you able to solve it yourself? I am currently facing the same issue and would be thankful for some input 🙂