Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Uses a saved company_id to lookup the company for a HubSpot contact over the Companies API
<?php
function example_hubspot_company_lookup( $user_id ) {
$company_id = get_user_meta( $user_id, 'company_id', true );
$request = 'https://api.hubapi.com/crm/v3/objects/companies/' . $company_id; // see https://developers.hubspot.com/docs/api/crm/companies
$response = wp_remote_get( $request, wp_fusion()->crm->get_params() );
if ( is_wp_error( $response ) ) {
wpf_log( 'error', 0, $response->get_error_message() );
}
$response = json_decode( wp_remote_retrieve_body( $response ) );
/* Example response
{
'properties': {
'city': 'Cambridge',
'createdate': '2019-10-30T03:30:17.883Z',
'domain': 'biglytics.net',
'hs_lastmodifieddate': '2019-12-07T16:50:06.678Z',
'industry': 'Technology',
'name': 'Biglytics',
'phone': '(877) 929-0687',
'state': 'Massachusetts'
}
} */
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment