Data Export of Foreign Keys

Hi there,

I know there are a few ways to export data from HubSpot. What I’d like to know is, we need to export our Companies and Contacts into our own db tables. For contacts associated with a company, this is the equivalent to a foreign key. I can see in the Portal view of Contact that I can choose the the Contact--> Company. However, this is just the Text Name for the company. Is there a way to export the CompanyRecordId for the Contact Object?

If I were to use the Export API (/crm/v3/exports/export/async) can I define the ComapnyRecordId as part of the objectProperties in the JSON request?

Thank you

Hello @THa51
you can export the CompanyRecordId for the Contact Object. You can do this by using the Export API (/crm/v3/exports/export/async) and defining the CompanyRecordId as part of the objectProperties in the JSON request.
create a JSON object that contains the following properties. The name of the object that you want to export. In this case, the objectType is “contacts”. objectProperties: A list of properties that you want to export. In this case, you want to export the CompanyRecordId property.
you can use to export the CompanyRecordId property

{
 "objectType": "contacts",
 "objectProperties": [
 "companyRecordId"
 ]
}

make a POST request to the following URL

https://api.hubspot.com/crm/v3/exports/export/async

example of a curl command that you can use to export the CompanyRecordId property

curl -X POST \
 -H "Authorization: Bearer <your_access_token>" \
 -H "Content-Type: application/json" \
 -d '{
 "objectType": "contacts",
 "objectProperties": [
 "companyRecordId"
 ]
 }' \
 https://api.hubspot.com/crm/v3/exports/export/async

Once you have made the request, HubSpot will start exporting the data. The export process can take several minutes to complete. Once the export is complete, HubSpot will send you an email with a link to download the exported data.

Thanks for the lead himanshurauthan ! I managed to get it to work using the following JSON body:

{

“exportType”: “VIEW”,

“exportName”: “All contacts”,

“objectType”: “CONTACT”,

“language”: “EN”,

“format”: “xls”,

“objectProperties”: [“hs_object_id”],

“associatedObjectType”: “COMPANY”

}

I tried your solution and got errors because companyRecordId wasn’t a property of CONTACTS etc. But your solution lead me into the right path. Thanks!

For anyone else in the future who would need to do the same, I got the clue from : Accounts Dashboard | HubSpot

Basically, you can export 1 FK associated object. You don’t need to specify the properties of the associated object (as you can’t). HS will just include the recordId of the associated object + the primary propert used to display the associated object. So for the above JSON spec, I was able to export the recordId (of contact), recordId (of company) , CompanyName.