Jump to content

Update Configurable Custom Field using updateclientproduct api


dixonjoseph.k

Recommended Posts

Hi,

 

We have to update client products dynamically. For that we developed a script, it should update configurable custom field (which is a hidden filed) with static values. But it is not updating even it shows "Success" message. Please see the code below.

 

<?php
$url = "https://example.com:8081/includes/api.php";
$postfields["username"] ="test";
$postfields["password"] = md5("test");								 
$postfields["action"] = "updateclientproduct";
$postfields["serviceid"] = 229; 
$postfields["pid"] = 152; 
$postfields["autorecalc"] = 1;

$postfields["configoptions"] = base64_encode(serialize(array(537 => array('optionid' => '7613', 'qty' => '1'))));
$postfields["responsetype"] = "xml";

$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$xmldata = curl_exec($ch);	

if (curl_error($ch))
{
die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
}
else
{
print_r($xmldata);
}
?>

 

The above script is trying to update product data in test licensed whmcs site and it is running from live whmcs directory. When it executes it shows as 'Success', but not updated. Please help.

Link to comment
Share on other sites

  • 2 years later...

Solved. This is what I learned from this issue and hopefully it can help someone else.

When specifying an array in configoptions, the syntax is : array(xxx1 => yyy1, xxx2 => yyy2). 

xxx is the optionid while yyy is the value. In above line, there are two options. Each option pair is separated by comma.

Another important thing is to check your parameters in the API. For example,  API AddOrder has a parameter pid. It must use an integer array. If you just pass it with a single value, the order is added, but the configoptions is totally ignored by the API and without generating a warning message.

This is one area WHMCS can improve upon. APIs should generate more warning messages.

Thanks

Mike

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated