Passing formId, hutk, pageUri and pageName with the new API

Hello everyone. I’m having an issue with creating contacts with the PHP basic API call:

<?php
use HubSpot\Factory;
use HubSpot\Client\Crm\Contacts\ApiException;

$client = Factory::createWithAccessToken('YOUR_ACCESS_TOKEN');

try {
 $apiResponse = $client->crm()->contacts()->basicApi()->getPage(10, false);
 var_dump($apiResponse);
} catch (ApiException $e) {
 echo "Exception when calling basic_api->get_page: ", $e->getMessage();
}

The issue is that documentation doesn’t specify how to pass Hubspot’s cookie ID, form ID, url and page name when the contact is created. I tried passing the $context as an additional option but I understood that it won’t be processed by the PHP class, so I’m stuck at this point:

 $context = [
 'formId' => $request->context['formId'],
 'hutk' => $request->context['hutk'],
 'pageUri' => $request->context['pageUri'],
 'pageName' => $request->context['pageName']
 ];

 $createContact = new SimplePublicObjectInputForCreate([
 'associations' => null,
 'properties' => $properties,
 'context' => $context,
 ]);

Can I do it with the Hubspot PHP code or is it better to use the legacy API? Thanks in advance.

Hi, @DTPRO :waving_hand: Welcome to our community! Thanks for your question.

I’d like to invite a few of our community champions who have PHP-experience to the converstaion. Hey, @Teun @stefen @MatthiasWeber, do you have any feedback for @DTPRO?

Thank you for having a look! — Jaycee

@Jaycee_Lewis @DTPRO you can get the cookie value by using the `$_COOKIE` PHP function like so:

$_COOKIE["hubspotutk"];

The Form ID you can get from the URL when you’re editing the form or from the form’s embed code.

The URL can be accessed via PHP via the `$_SERVER` function like so:

$_SERVER['REQUEST_URI']

There’s not an easy way to get the page name via PHP so you may just want to re-use the URL or something else for that one. Hope that helps!``