API Find All Contacts that are unassigned

Hi there,

I am using the API and would like to find all contacts that are unassigned.

This is the Python code that I have so far.

import requests
import json
import pprint

BASE_URL = "https://api.hubapi.com/crm/v3"
API_KEY = "INSERT-KEY-HERE"

# https://developers.hubspot.com/docs/api/crm/contacts ## SEARCH
def owner_contacts(owner_id): 
 url = f"{BASE_URL}/objects/contacts/search"
 querystring = {"hapikey":API_KEY}
 payload = {
 "filterGroups":[{
 "filters":[
 {
 "value": owner_id,
 "propertyName": "hubspot_owner_id",
 "operator": "EQ"
 }
 ]
 }],
 "limit":100,
 "after":0
 }
 headers = {
 "accept": "application/json",
 "content-type": "application/json"
 }

 response = requests.request("POST", url, data=json.dumps(payload), headers=headers, params=querystring)

 return json.loads(response.text)

owner_contacts(84150642)

Is it possible to know the hubspot_owner_id for an Unassigned user.

Thanks in advance,

Luke

Here is the answer.

import requests
import json
import pprint

BASE_URL = "https://api.hubapi.com/crm/v3"
API_KEY = "INSERT-KEY-HERE"

def ownerless_contacts(): 
 url = f"{BASE_URL}/objects/contacts/search"
 querystring = {"hapikey":API_KEY}
 payload = {
 "filterGroups":[{
 "filters":[
 { 
 "propertyName": "hubspot_owner_id",
 "operator": "NOT_HAS_PROPERTY"
 }
 ]
 }],
 "limit":100,
 "after":0
 }
 headers = {
 "accept": "application/json",
 "content-type": "application/json"
 }

 response = requests.request("POST", url, data=json.dumps(payload), headers=headers, params=querystring)
 response = json.loads(response.text)

 return response["total"], response["results"]

ownerless_contacts()

The key setting the operator to NOT_HAS_PROPERTY.