unable to record conversion url in hs contex through php curl

I am using this code to pass all fields :

$formGuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
$fields = array(
'fields' => [
array('name'=>'firstname','value'=>$_POST['first_name']),
array('name'=>'company','value'=>$_POST['company']),
]
);

$hubspotutk = $_COOKIE['hubspotutk']; //grab the cookie from the visitors browser.
$ip_addr = $_SERVER['REMOTE_ADDR']; //IP address too.
$pageUrl = $_SERVER['HTTP_REFERER']; //IP address too.

$hs_context = array(
'hutk' => $hubspotutk,
'ipAddress' => $ip_addr,
'pageUrl' => $pageUrl,
'pageName' => 'Hybrent Test'
);
$hs_context_json = json_encode($hs_context, true);

$fields['hs_context'] = $hs_context_json;

$endpoint = 'https://api.hsforms.com/submissions/v3/integration/submit/xxxxxxxx/'.$formGuid;

$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
@curl_setopt($ch, CURLOPT_URL, $endpoint);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

@curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($fields)
));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch); //Log the response from HubSpot as needed.
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
echo $status_code;
@curl_close($ch);

Welcome, @gurmeetHyb.

It looks like you’re trying to use PHP cURL code tailored to the v2 Forms API endpoint to make requests to the v3 Forms API endpoint.

Per the documentation, the v3 endpoint accepts a context object containing the hutk, pageUri, pageName, and ipAddress fields.

Your code uses the hs_context object and pageUrl fields, which are only supported by the v2 endpoint.