Sample code for 30+ languages & platforms
PHP

Shopify Receive Count of All Products in a Collection

See more Shopify Examples

Get a count of all products of a given collection

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\JsonObject;
use Chilkat2\Rest;
use Chilkat2\StringBuilder;

$rest = new Rest();

$rest->SetAuthBasic('SHOPIFY_PRIVATE_API_KEY', 'SHOPIFY_PRIVATE_API_KEY');

try {
    $rest->Connect('chilkat.myshopify.com', 443, true, true);

    $sbJson = new StringBuilder();
    $rest->FullRequestNoBodySb('GET', '/admin/products/count.json?collection_id=841564295 ', $sbJson);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

if ($rest->ResponseStatusCode != 200) {
    echo 'Received error response code: ', $rest->ResponseStatusCode, "\n";
    echo "Response body:\n";
    echo $sbJson->GetAsString(), "\n";
    exit;
}

$json = new JsonObject();
$json->LoadSb($sbJson);

// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.

$count = $json->IntOf('count');

// A sample JSON response body that is parsed by the above code:

// {
//   "count": 1
// }

echo "Example Completed.\n";