Using Xenforo Validation API

Hello!
Im trying to make a validation for WHMCS, but the API returns: Please enter a validation token

PHP:
<?php

add_hook('ShoppingCartValidateProductUpdate', 1, function($vars) {
   
    $json = json_encode($vars[customfield]);
    $transform = json_decode($json, true);

    $url = 'https://xenforo.com/customer-api/license-lookup.json';

    $data = array(
        'token' => $transform[6],
        'domain' => $transform[2]
    );
   
    $payload = json_encode($data);
   
    echo 'console.log(' . $payload . ')';

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    $result = curl_exec($ch);
    curl_close($ch);
    //print_r ($result);
   
    $message = json_decode($result, true);
    return [$message[error_message]];
   
});

$payload is returning this structure:
JSON:
{"token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","domain":"https:\/\/www.test.com"}

What am I doing wrong?
 
Are you still sending JSON?

Use
PHP:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
instead of
PHP:
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
 
Top Bottom