Sample code for 30+ languages & platforms
React Native

Shopify Receive Count of All Products in a Collection

See more Shopify Examples

Get a count of all products of a given collection

Chilkat React Native Downloads

React Native
import { JsonObject, Rest, StringBuilder } from '@chilkat/react-native'

async function chilkatExample() {
  const rest = new Rest();

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

  try {
    await rest.connectAsync('chilkat.myshopify.com', 443, true, true);
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  const sbJson = new StringBuilder();
  try {
    await rest.fullRequestNoBodySbAsync('GET', '/admin/products/count.json?collection_id=841564295 ', sbJson);
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

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

  const json = new JsonObject();
  json.loadSb(sbJson);

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

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

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

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

  console.log('Example Completed.');
}