Sample code for 30+ languages & platforms
Objective-C

WiX - Get all Products in a Store

See more WiX Examples

Gets the first page of products in a store.

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>
#import <CkoStringBuilder.h>
#import <NSString.h>

BOOL success = NO;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoHttp *http = [[CkoHttp alloc] init];

// Implements the following CURL command:

// curl -X POST -H "Content-Type: application/json" \
//    -d '{
//   "includeVariants": true
//   }' https://www.wixapis.com/stores/v1/products/query

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateBool: @"includeVariants" value: YES];

http.AuthToken = @"ACCESS_TOKEN";

CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
success = [http HttpJson: @"POST" url: @"https://www.wixapis.com/stores/v1/products/query" json: json contentType: @"application/json" response: resp];
if (success == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
[resp GetBodySb: sbResponseBody];
CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);

int respStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",resp.Header);
    NSLog(@"%@",@"Failed.");
    return;
}

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

// {
//   "products": [
//     {
//       "id": "58fcbb51-ff87-08ff-d97b-646726676e4a",
//       "name": "webhook test",
//       "slug": "webhook-test",
//       "visible": true,
//       "productType": "physical",
//       "description": "<p>fasdf<\/p>",
//       "stock": {
//         "trackInventory": true,
//         "quantity": 0,
//         "inStock": false
//       },
//       "price": {
//         "currency": "ILS",
//         "price": 234,
//         "discountedPrice": 234,
//         "formatted": {
//           "price": "234.00 ₪",
//           "discountedPrice": "234.00 ₪"
//         }
//       },
//       "priceData": {
//         "currency": "ILS",
//         "price": 234,
//         "discountedPrice": 234,
//         "formatted": {
//           "price": "234.00 ₪",
//           "discountedPrice": "234.00 ₪"
//         }
//       },
//       "additionalInfoSections": [
//       ],
//       "ribbons": [
//         {
//           "text": "ribby"
//         }
//       ],
//       "media": {
//         "items": [
//         ]
//       },
//       "customTextFields": [
//       ],
//       "manageVariants": true,
//       "productOptions": [
//       ],
//       "productPageUrl": {
//         "base": "https://www.my-website.com/",
//         "path": "/product-page/webhook-test"
//       },
//       "numericId": "1567078000586000",
//       "inventoryItemId": "a70344ae-0078-f700-2684-9b98d99891b5",
//       "discount": {
//         "type": "NONE",
//         "value": 0
//       },
//       "collectionIds": [
//       ],
//       "variants": [
//       ]
//     },
//     {
//       "id": "6507fd67-94e5-10af-73e4-d2167852d5bc",
//       "name": "digital product",
//       "slug": "digital-product",
//       "visible": true,
//       "productType": "digital",
//       "description": "",
//       "sku": "",
//       "weight": 0,
//       "stock": {
//         "trackInventory": false,
//         "inStock": true
//       },
//       "price": {
//         "currency": "ILS",
//         "price": 123,
//         "discountedPrice": 123,
//         "formatted": {
//           "price": "123.00 ₪",
//           "discountedPrice": "123.00 ₪"
//         }
//       },
//       "priceData": {
//         "currency": "ILS",
//         "price": 123,
//         "discountedPrice": 123,
//         "formatted": {
//           "price": "123.00 ₪",
//           "discountedPrice": "123.00 ₪"
//         }
//       },
//       "additionalInfoSections": [
//       ],
//       "ribbons": [
//       ],
//       "media": {
//         "items": [
//         ]
//       },
//       "customTextFields": [
//       ],
//       "manageVariants": false,
//       "productOptions": [
//       ],
//       "productPageUrl": {
//         "base": "https://www.my-website.com/",
//         "path": "/product-page/digital-product"
//       },
//       "numericId": "1544009414325000",
//       "inventoryItemId": "9af80298-6b1a-ef50-8c1b-2de987ad2a43",
//       "discount": {
//         "type": "NONE",
//         "value": 0
//       },
//       "collectionIds": [
//         "ae886d55-2572-eee8-b2c4-13219844b5e4"
//       ],
//       "variants": [
//       ]
//     }
//   ],
//   "metadata": {
//     "items": 100,
//     "offset": 0
//   },
//   "totalResults": 2
// }

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

NSString *id = 0;
NSString *name = 0;
NSString *slug = 0;
BOOL visible;
NSString *productType = 0;
NSString *description = 0;
BOOL stockTrackInventory;
int stockQuantity;
BOOL stockInStock;
NSString *priceCurrency = 0;
int pricePrice;
int priceDiscountedPrice;
NSString *priceFormattedPrice = 0;
NSString *priceFormattedDiscountedPrice = 0;
NSString *priceDataCurrency = 0;
int priceDataPrice;
int priceDataDiscountedPrice;
NSString *priceDataFormattedPrice = 0;
NSString *priceDataFormattedDiscountedPrice = 0;
BOOL manageVariants;
NSString *productPageUrlBase = 0;
NSString *productPageUrlPath = 0;
NSString *numericId = 0;
NSString *inventoryItemId = 0;
NSString *discountType = 0;
int discountValue;
NSString *sku = 0;
int weight;
int j;
int count_j;
NSString *text = 0;
NSString *strVal = 0;

int metadataItems = [[jResp IntOf: @"metadata.items"] intValue];
int metadataOffset = [[jResp IntOf: @"metadata.offset"] intValue];
int totalResults = [[jResp IntOf: @"totalResults"] intValue];
int i = 0;
int count_i = [[jResp SizeOfArray: @"products"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    id = [jResp StringOf: @"products[i].id"];
    name = [jResp StringOf: @"products[i].name"];
    slug = [jResp StringOf: @"products[i].slug"];
    visible = [jResp BoolOf: @"products[i].visible"];
    productType = [jResp StringOf: @"products[i].productType"];
    description = [jResp StringOf: @"products[i].description"];
    stockTrackInventory = [jResp BoolOf: @"products[i].stock.trackInventory"];
    stockQuantity = [[jResp IntOf: @"products[i].stock.quantity"] intValue];
    stockInStock = [jResp BoolOf: @"products[i].stock.inStock"];
    priceCurrency = [jResp StringOf: @"products[i].price.currency"];
    pricePrice = [[jResp IntOf: @"products[i].price.price"] intValue];
    priceDiscountedPrice = [[jResp IntOf: @"products[i].price.discountedPrice"] intValue];
    priceFormattedPrice = [jResp StringOf: @"products[i].price.formatted.price"];
    priceFormattedDiscountedPrice = [jResp StringOf: @"products[i].price.formatted.discountedPrice"];
    priceDataCurrency = [jResp StringOf: @"products[i].priceData.currency"];
    priceDataPrice = [[jResp IntOf: @"products[i].priceData.price"] intValue];
    priceDataDiscountedPrice = [[jResp IntOf: @"products[i].priceData.discountedPrice"] intValue];
    priceDataFormattedPrice = [jResp StringOf: @"products[i].priceData.formatted.price"];
    priceDataFormattedDiscountedPrice = [jResp StringOf: @"products[i].priceData.formatted.discountedPrice"];
    manageVariants = [jResp BoolOf: @"products[i].manageVariants"];
    productPageUrlBase = [jResp StringOf: @"products[i].productPageUrl.base"];
    productPageUrlPath = [jResp StringOf: @"products[i].productPageUrl.path"];
    numericId = [jResp StringOf: @"products[i].numericId"];
    inventoryItemId = [jResp StringOf: @"products[i].inventoryItemId"];
    discountType = [jResp StringOf: @"products[i].discount.type"];
    discountValue = [[jResp IntOf: @"products[i].discount.value"] intValue];
    sku = [jResp StringOf: @"products[i].sku"];
    weight = [[jResp IntOf: @"products[i].weight"] intValue];
    j = 0;
    count_j = [[jResp SizeOfArray: @"products[i].additionalInfoSections"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"products[i].ribbons"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        text = [jResp StringOf: @"products[i].ribbons[j].text"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"products[i].media.items"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"products[i].customTextFields"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"products[i].productOptions"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"products[i].collectionIds"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"products[i].collectionIds[j]"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"products[i].variants"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        j = j + 1;
    }

    i = i + 1;
}