only export contacts having associated companies via API

Is there a way to create an export containing only the contacts having a company associated with them using an API request?
Right now I’m using a POST on https://api.hubapi.com/crm/v3/exports/export/async

as an example, with a JSON containing the following:

{
 "exportType": "VIEW",
 "exportName": "All contacts with companies",
 "format": "csv",
 "objectType": "CONTACT",
 "objectProperties": [
 "email",
 "firstname",
 "lastname",
 "phone"
 ],
 "filters": [
 {
 "propertyName": "associations.company",
 "operator": "NOT_IN",
 "values": [""]
 }
 ],
 "associatedObjectType": "COMPANY"
}

The filters trying to filter the empty (or non-existent) associations out. This obviously doesn’t work. I still get all the contacts in the export. But I hope it does make clear what I’m trying to achieve.

Hi @SwanJarno ,

You can use this json to get the contacts with Companies

{
 "exportType": "VIEW",
 "format": "CSV",
 "exportName": "Contacts with Companies",
 "objectProperties": [
 "firstname",
 "lastname",
 "email"
 ],
 "associatedObjectType": "companies",
 "objectType": "contacts",
 "language": "EN",
 "publicCrmSearchRequest": {
 "filters": [
 {
 "propertyName": "company",
 "operator": "HAS_PROPERTY"
 }
 ],
 "sorts": [
 "-createdate"
 ]
 }
 }

:check_mark: Mark this as solution to help community if it solved your problem.

Hi @SwanJarno

Here is the CURL to get all contacts with the association. From the result in the response body, you can filter out the contacts that are associated with the company

curl --request GET \
 --url 'https://api.hubapi.com/crm/v3/objects/contacts?limit=10&associations=companies&archived=false' \
 --header 'authorization: Bearer YOUR_ACCESS_TOKEN'

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.
Thanks!