Sample code for 30+ languages & platforms
Dart

Shopify Receive Count of All Products in a Collection

See more Shopify Examples

Get a count of all products of a given collection

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final rest = CkRest();

  rest.setAuthBasic('SHOPIFY_PRIVATE_API_KEY', 'SHOPIFY_PRIVATE_API_KEY');

  try {
    rest.connect('chilkat.myshopify.com', 443, true, true);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final sbJson = CkStringBuilder();
  try {
    rest.fullRequestNoBodySb('GET', '/admin/products/count.json?collection_id=841564295 ', sbJson);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  if (rest.responseStatusCode != 200) {
    print('Received error response code: ${rest.responseStatusCode}');
    print('Response body:');
    print(sbJson.getAsString());
    return;
  }

  final json = CkJsonObject();
  json.loadSb(sbJson);

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

  final count = json.intOf('count');

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

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

  print('Example Completed.');
}