hubspothubspot-crm

How to assign an Owner using the Hubspot API?


I'm using the Hubspot API to create new contacts and would like to automatically set the owner when the contact is created. I know this is possible without using the API via Workflows, however I'd like to use the API for that.

Here's my code right now (which works, just missing the contact owner):

$data = [
    'properties' => [
                        ['property' => 'firstname', 'value' => $contact->first_name],
                        ['property' => 'lastname', 'value' => $contact->last_name],
                    ]
];

$body = json_encode($data);
$response = $client->request('POST', '/contacts/v1/contact/email/'.$user->email.'/profile',
                ['query' => ['hapikey' => $hubspot_key, 'body' => $body]);

Solution

  • I eventually found a way to achieve this:

    1. Go to your Hubspot instance, then Settings and Properties
    2. Search for "Contact Owner" and click on Edit
    3. In "Field type", identify the Owner's ID value

    Then in your API call, simply pass this property:

    $data['properties'][] = ['property' => 'hubspot_owner_id', 'value' => 123456];
    

    You can find out more about the hubspot_owner_id property (which is internal to Hubspot, this is not a custom property) in Hubspot's documentation.

    It will automatically assign the newly created (or updated) Hubspot contact to the related Owner (Hubspot User).