Jump to content

CreateQuote API Failure


aquiss

Recommended Posts

I'm trying to use the CreateQuote (Curl Method) as shown https://developers.whmcs.com/api-reference/createquote/ 

I'm using the following test code

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'url snipped');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'CreateQuote',
            'username' => '',
            'password' => '',
            'subject' => 'Test Quote Subject',
            'stage' => 'Draft',
            'validuntil' => '30/01/2020',
'lineitems' => base64_encode(serialize(array(array("desc"=>"Test Description 1","qty"=>1,"up"=>"10.00","discount"=>"10.00",
"taxable"=>true),array("desc"=>"Test Description 2","qty"=>4,"up"=>"15.00","discount"=>"0.00",
"taxable"=>false))));,
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
			
?>

However, I just can't get it working at all.  Just seems to return an error.

Docs don't mention any other Required elements, however, I'm getting an error saying it must be an array. However, the example code is being used exactly as given from the docs page.

Error appearing in logs is:

Error: TypeError: Argument 20 passed to saveQuote() must be of the type array, null given, called in /var/www/vhosts/snippedurl/httpdocs/includes/api/createquote.php on line 0 and defined in /var/www/vhosts/snippedurl/httpdocs/includes/quotefunctions.php:0 Stack trace: #0 /var/www/vhosts/snippedurl/httpdocs/includes/api/createquote.php(0): saveQuote('', 'Test Quote Subj...', 'Draft', '2019-12-31', '30/01/2020', 'new', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, '') #1 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Api/V1/Api.php(0): unknown() #2 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Api/V1/Api.php(0): WHMCS\Api\V1\Api->executeApiCall() #3 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Api/ApplicationSupport/Route/Middleware/HandleProcessor.php(0): WHMCS\Api\V1\Api->call() #4 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Api/ApplicationSupport/Route/Middleware/HandleProcessor.php(0): WHMCS\Api\ApplicationSupport\Route\Middleware\HandleProcessor->processV1Request(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest)) #5 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Route/Middleware/Strategy/DelegatingMiddlewareTrait.php(0): WHMCS\Api\ApplicationSupport\Route\Middleware\HandleProcessor->_process(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest), Object(Middlewares\Utils\Delegate)) #6 /var/www/vhosts/snippedurl/httpdocs/vendor/middlewares/utils/src/Dispatcher.php(76): WHMCS\Api\ApplicationSupport\Route\Middleware\HandleProcessor->process(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest), Object(Middlewares\Utils\Delegate)) #7 [internal function]: Middlewares\Utils\Dispatcher->Middlewares\Utils\{closure}(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest)) #8 /var/www/vhosts/snippedurl/httpdocs/vendor/middlewares/utils/src/Delegate.php(31): call_user_func(Object(Closure), Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest)) #9 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Api/ApplicationSupport/Route/Middleware/ActionResponseFormat.php(0): Middlewares\Utils\Delegate->process(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest)) #10 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Route/Middleware/Strategy/AssumingMiddlewareTrait.php(0): WHMCS\Api\ApplicationSupport\Route\Middleware\ActionResponseFormat->_process(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest), Object(Middlewares\Utils\Delegate)) #11 /var/www/vhosts/snippedurl/httpdocs/vendor/middlewares/utils/src/Dispatcher.php(76): WHMCS\Api\ApplicationSupport\Route\Middleware\ActionResponseFormat->process(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest), Object(Middlewares\Utils\Delegate)) #12 [internal function]: Middlewares\Utils\Dispatcher->Middlewares\Utils\{closure}(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest)) #13 /var/www/vhosts/snippedurl/httpdocs/vendor/middlewares/utils/src/Delegate.php(31): call_user_func(Object(Closure), Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest)) #14 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Route/Middleware/Strategy/DelegatingMiddlewareTrait.php(0): Middlewares\Utils\Delegate->process(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest)) #15 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Security/Middleware/Authorization.php(0): WHMCS\Security\Middleware\Authorization->delegateProcess(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest), Object(Middlewares\Utils\Delegate)) #16 /var/www/vhosts/snippedurl/httpdocs/vendor/whmcs/whmcs-foundation/lib/Route/Middleware/AbstractProxyMiddleware.php(0): WHMCS\Security\Middleware\Authorization->process(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest), Object(Middlewares\Utils\Delegate)) 

snip ........

 

Any ideas, because all I can find online is someone having similar but admin side, but claimed to be fixed in 7.7.1?

Link to comment
Share on other sites

WHMCS Support have confirmed the docs are incorrect and are getting them updated. In the meantime, this is correct:

 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://yourwhmcs.com/whmcs/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'CreateQuote',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'USERNAME',
            'password' => 'PASSWORD',
            'subject' => 'Test Quote Subject',
            'stage' => 'Draft',
            'userid' => '1',
            'validuntil' => '01/01/2016',
            'lineitems' => base64_encode(serialize(array(array("desc"=>"Test Description 1","qty"=>1,"up"=>"10.00","discount"=>"10.00",
"taxable"=>true),array("desc"=>"Test Description 2","qty"=>4,"up"=>"15.00","discount"=>"0.00","taxable"=>false)))),
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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