WHMCS API GetProducts – How to get visible products only

WHMCS API GetProducts – How to get visible products only
October 30, 2017 David Rosendo

Currently GetProducts (https://developers.whmcs.com/api-reference/getproducts/) retrieves all products and no information regarding if the product is active or not.

So I just created my own API call to handle this and only retrieve the visible (not hidden) products.

Just upload to /includes/api .

Request Parameters “GetProductsActive”

ParameterTypeDescriptionRequired
actionstring“GetProductsActive”Required
pidintstringObtain a specific product id configuration. Can be a list of ids comma separated
gidintRetrieve products in a specific group idOptional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
totalresultsintThe total number of results available
startnumberintThe starting number for the returned results
numreturnedintThe number of results returned
productsarrayAn array of products matching the criteria passed

Example Request (CURL)

$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' => 'GetProductsActive',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'pid' => '1',
            'responsetype' => 'json',
        )
    )
);
$response = curl_exec($ch);
curl_close($ch);

 

Example Request (Local API)

$command = 'GetProductsActive';
$postData = array(
    'pid' => '1', // or gid => '1' or both
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

 

Have a better code or add something? Please do!

You can download the code here: GITHUB WHMCS API getproductsactive

Cheers,

David

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.