Custom fields not inserting using WHMCS API with curl

113 views Asked by At

I am trying to add an order with whmcs API but custom fields are not getting posted to whmcs the fields are blank when I check the order in the whmcs dashboard. here is the code. the ids of the custom fields are 183 and 184. The script execute successfully but doesn't add the custom field values in the order

i changewd it to this but its still empty in whmcs panel the id of the custom field is correct

`<?php
// Initialize cURL session
$ch = curl_init();

// Set other API parameters as needed
$postfields = array(
    'action' => 'AddOrder',
    'username' => 'username',
    'password' => 'password',
    'accesskey' => '12345678', // Include the access key here
    'clientid' => '456',
    'pid' => '37',
    // Set the custom field values individually
    'customfields' => array(base64_encode(serialize(array("183" => "Google")))),
    'paymentmethod' => 'banktransfer',
    'responsetype' => 'json',
);

// Set cURL options
curl_setopt($ch, CURLOPT_URL, 'https://example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Execute cURL request and get the response
$response = curl_exec($ch);

// Check for cURL errors
if (curl_errno($ch)) {
    echo 'cURL Error: ' . curl_error($ch);
}

// Close cURL session
curl_close($ch);

// Output the response
echo $response;
?>
`
1

There are 1 answers

0
M. Haseeb Akhtar On

You don't need to provide the customfields in an array. Just pass serialized & base64 encoded array to customfields, like:

'customfields' => base64_encode(serialize(array('183' => 'Google', '184' => 'Another Google')))