Sample code for 30+ languages & platforms
React Native

Faire - Get All Products

See more Faire Examples

Retrieves a list of products, ordered ascending by updated_at. By default, it only returns non-deleted products.

Chilkat React Native Downloads

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

async function chilkatExample() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const http = new Http();

  // Implements the following CURL command:

  // curl -X GET -H "X-FAIRE-ACCESS-TOKEN: <access_token>" -d "limit=50" -d "page=1" https://www.faire.com/api/v1/products

  // Use the following online tool to generate HTTP code from a CURL command
  // Convert a cURL Command to HTTP Source Code

  const queryParams = new JsonObject();
  queryParams.updateInt('limit', 50);
  queryParams.updateInt('page', 1);

  http.setRequestHeader('X-FAIRE-ACCESS-TOKEN', '<access_token>');

  const resp = new HttpResponse();
  try {
    await http.httpParamsAsync('GET', 'https://www.faire.com/api/v1/products', queryParams, resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  const sbResponseBody = new StringBuilder();
  resp.getBodySb(sbResponseBody);

  const jResp = new JsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  console.log('Response Body:');
  console.log(jResp.emit());

  const respStatusCode = resp.statusCode;
  console.log(`Response Status Code = ${respStatusCode}`);
  if (respStatusCode >= 400) {
    console.log('Response Header:');
    console.log(resp.header);
    console.log('Failed.');
    return;
  }

  // Sample JSON response:
  // (Sample code for parsing the JSON response is shown below)

  // {
  //   "page": 1,
  //   "limit": 50,
  //   "products": [
  //     {
  //       "id": "p_123",
  //       "brand_id": "b_abc",
  //       "short_description": "Our candles smell fantastic. Want to know how good? Read our description!",
  //       "description": "Glad you decided to read our description! We have significantly more characters to describe to you just how good our candles smell.",
  //       "wholesale_price_cents": 500,
  //       "retail_price_cents": 1000,
  //       "sale_state": "FOR_SALE",
  //       "active": true,
  //       "deleted": false,
  //       "name": "Faire's fantastic candle",
  //       "unit_multiplier": 8,
  //       "taxonomy_type": {
  //         "id": "tt_23nl3bzl00",
  //         "name": "Votive Candle"
  //       },
  //       "options": [
  //       ],
  //       "created_at": "20190314T000915.000Z",
  //       "updated_at": "20190315T000915.000Z"
  //     }
  //   ]
  // }

  // Sample code for parsing the JSON response...
  // Use the following online tool to generate parsing code from sample JSON:
  // Generate Parsing Code from JSON

  let id = '';
  let brandId = '';
  let shortDescription = '';
  let description = '';
  let wholesalePriceCents = 0;
  let retailPriceCents = 0;
  let saleState = '';
  let name = '';
  let unitMultiplier = 0;
  let taxonomyTypeId = '';
  let taxonomyTypeName = '';
  let createdAt = '';
  let updatedAt = '';
  let j = 0;
  let countJ = 0;

  const page = jResp.intOf('page');
  const limit = jResp.intOf('limit');
  let i = 0;
  const countI = jResp.sizeOfArray('products');
  while (i < countI) {
    jResp.i = i;
    id = jResp.stringOf('products[i].id');
    brandId = jResp.stringOf('products[i].brand_id');
    shortDescription = jResp.stringOf('products[i].short_description');
    description = jResp.stringOf('products[i].description');
    wholesalePriceCents = jResp.intOf('products[i].wholesale_price_cents');
    retailPriceCents = jResp.intOf('products[i].retail_price_cents');
    saleState = jResp.stringOf('products[i].sale_state');
    jResp.boolOf('products[i].active');
    jResp.boolOf('products[i].deleted');
    name = jResp.stringOf('products[i].name');
    unitMultiplier = jResp.intOf('products[i].unit_multiplier');
    taxonomyTypeId = jResp.stringOf('products[i].taxonomy_type.id');
    taxonomyTypeName = jResp.stringOf('products[i].taxonomy_type.name');
    createdAt = jResp.stringOf('products[i].created_at');
    updatedAt = jResp.stringOf('products[i].updated_at');
    j = 0;
    countJ = jResp.sizeOfArray('products[i].options');
    while (j < countJ) {
      jResp.j = j;
      j++;
    }

    i++;
  }
}