Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to add configurable options value using add order WHMCS API? #126

Open
sg34 opened this issue Feb 27, 2019 · 8 comments
Open

Comments

@sg34
Copy link

sg34 commented Feb 27, 2019

I want to update the quantity value in the "tblhostingconfigoptions" table by using addorder api. I have tried the config parameter mentioned in the addorder api but it picks the minimum value assigned in the WHMCS config option.

@AbdullahValley
Copy link

AbdullahValley commented Mar 4, 2020

Yes.
WHMCS Developers API allows you to add configurable options when placing an order through API.

Documentation Link : https://developers.whmcs.com/api-reference/addorder/

Check Parameter : configoptions : an array of base64 encoded serialized array of product configurable options values.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'AddOrder',
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'clientid' => '1',
            'pid' => array(1,1),
            'domain' => array('domain1.com', 'domain2.com'),
            'billingcycle' => array('monthly','semiannually'),
            'addons' => array('1,3,9', ''),
            'customfields' => array(base64_encode(serialize(array("1" => "Google"))), base64_encode(serialize(array("1" => "Google")))),
            'configoptions' => array(base64_encode(serialize(array("1" => 999))), base64_encode(serialize(array("1" => 999)))),
            'domaintype' => array('register', 'register'),
            'regperiod' => array(1, 2),
            'dnsmanagement' => array(0 => false, 1 => true),
            'nameserver1' => 'ns1.demo.com',
            'nameserver2' => 'ns2.demo.com',
            'paymentmethod' => 'mailin',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

check here :

'configoptions' => array(base64_encode(serialize(array("1" => 999))), base64_encode(serialize(array("1" => 999)))),

@jgupta
Copy link

jgupta commented Mar 28, 2020

Same issue here. Can't make configoptions work. Others have also reported this issue.

@jgupta
Copy link

jgupta commented Mar 28, 2020

In place of an array and giving base64 encoded string works.

@AbdullahValley
Copy link

But I have passed like this and its worked for me :

Getting IDs for config options

$operating_system = ["2" => 2];
$cpanel_cloud_license = ["10" => 21];

Config Options Array Merge for multiple config options

$configoptions_array_merge = $operating_system + $cpanel_cloud_license;

Config Options Array Formatted for WHMCS API

$configoptions_array[] = base64_encode(serialize($configoptions_array_merge));

Sending to API

'configoptions' => isset($configoptions_array) ? $configoptions_array : '',

MUST Remember :
Someones Output is : [YToxOntpOjI7aToyO30=, YToxOntpOjEwO2k6MjE7fQ==]

But Correct Output will be only one always, doesn't matter how many arrays you have passed.

Correct Output will be : [YToxOntpOjI7aToyO30=]

@aiso-net
Copy link

That doesnt work for optiontype 4

@Samanw
Copy link

Samanw commented Dec 5, 2021

that doesnt work even for option and dropdown

@Jiroun
Copy link

Jiroun commented Dec 5, 2021

@Samanw it worked for me I can help you if you want

I will tell you you should see HTML code inspect
see the number of the dropdown option

then the number of options

then you do it like this

'configoptions' => array(base64_encode(serialize(array($co_id => (int)$co)))),

@jgarcianewemage
Copy link

VERY important if it's only 1 item, dont place it inside an array
do 'configoptions' => base64_encode(serialize(array($co_id => (int)$co))),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants