Skip to content

Instantly share code, notes, and snippets.

@verygoodplugins
Created August 4, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verygoodplugins/44d99983acb74139f228f11c8377f674 to your computer and use it in GitHub Desktop.
Save verygoodplugins/44d99983acb74139f228f11c8377f674 to your computer and use it in GitHub Desktop.
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