Hi! I would like to be able to access the ids of deals and tasks for a contact.
If I make the call from the docs everything works:
But when I make the call from my app with the same code, the associations are empty:
HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations Object
(
[container:protected] => Array
(
[id] => 1062
[properties] => Array
(
[createdate] => 2021-08-18T15:57:17.663Z
[hs_object_id] => 1062
[lastmodifieddate] => 2023-06-13T13:54:52.301Z
)
[properties_with_history] =>
[created_at] => DateTime Object
(
[date] => 2021-08-18 15:57:17.663000
[timezone_type] => 2
[timezone] => Z
)
[updated_at] => DateTime Object
(
[date] => 2023-06-13 13:54:52.301000
[timezone_type] => 2
[timezone] => Z
)
[archived] =>
[archived_at] =>
[associations] =>
)
)
How can I solve this?
Hi, @thatbluntman
Thanks for including those details. Do you have any additional code examples you can share?
Hey, @Teun @MatthiasWeber @stefen, do you have any PHP-wisdom you can share with @thatbluntman?
Thank you! — Jaycee
Hi @Jaycee_Lewis, my problem remains unsolved but thank you for trying to help me.
I can share the full code I’m using to make the call and get that response:
require __DIR__.'/vendor/autoload.php';
use HubSpot\Factory;
use HubSpot\Client\Crm\Objects\Tasks\ApiException;
define("CALLBACK_URL", "https://*******/index.php");
define("AUTH_URL", "https://app-eu1.hubspot.com/oauth/authorize");
define("ACCESS_TOKEN_URL", "https://api.hubapi.com/oauth/v1/token");
define("CLIENT_ID", "*********");
define("CLIENT_SECRET", "********");
define("SCOPE", "crm.objects.contacts.read crm.schemas.contacts.read crm.objects.deals.read crm.schemas.companies.read crm.schemas.deals.read");
define("REFRESH_TOKEN", $row['refreshToken']);
function getTokenWithRefresh(){
$curl = curl_init();
$params = array(
CURLOPT_URL => ACCESS_TOKEN_URL."?"
."grant_type=refresh_token"
."&client_id=". CLIENT_ID
."&client_secret=". CLIENT_SECRET
."&refresh_token=". REFRESH_TOKEN,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_NOBODY => false,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
),
);
curl_setopt_array($curl, $params);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #01: " . $err;
} else {
$response = json_decode($response, true);
if(array_key_exists("access_token", $response)) return $response;
if(array_key_exists("error", $response)) echo $response["error_description"];
echo "cURL Error #02: Something went wrong! Please contact admin.";
}
}
$a = getTokenWithRefresh();
$accessToken = $a['access_token'];
$client = Factory::createWithAccessToken($accessToken);
try {
$apiResponse = $client->crm()->contacts()->basicApi()->getById('1062', ['deals,tasks'], false);
echo "<pre>";
print_r($apiResponse);
echo "</pre>";
} catch (ApiException $e) {
echo "Exception when calling basic_api->get_by_id: ", $e->getMessage();
}