Unicode C++
Unicode C++
WiX Create Product
See more WiX Examples
Creates a new product.Note: If you get a 403 error response, try refreshing the access token.
Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
// Implements the following CURL command:
// curl -X POST \
// 'https://www.wixapis.com/stores/v1/products' \
// --data-binary '{
// "product": {
// "name": "T-shirt",
// "productType": "physical",
// "priceData": {
// "price": 10.5
// },
// "description": "nice summer t-shirt",
// "sku": "123df",
// "visible": false,
// "weight": 0.2,
// "discount": {
// "type": "AMOUNT",
// "value": 1
// },
// "manageVariants": true,
// "productOptions": [
// {
// "name": "Size",
// "choices": [
// {
// "value": "S",
// "description": "S"
// },
// {
// "value": "L",
// "description": "L"
// }
// ]
// }
// ]
// }
// }' \
// -H 'Content-Type: application/json' \
// -H 'Authorization: <AUTH>'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "product": {
// "name": "T-shirt",
// "productType": "physical",
// "priceData": {
// "price": 10.5
// },
// "description": "nice summer t-shirt",
// "sku": "123df",
// "visible": false,
// "weight": 0.2,
// "discount": {
// "type": "AMOUNT",
// "value": 1
// },
// "manageVariants": true,
// "productOptions": [
// {
// "name": "Size",
// "choices": [
// {
// "value": "S",
// "description": "S"
// },
// {
// "value": "L",
// "description": "L"
// }
// ]
// }
// ]
// }
// }
CkJsonObjectW json;
json.UpdateString(L"product.name",L"T-shirt");
json.UpdateString(L"product.productType",L"physical");
json.UpdateNumber(L"product.priceData.price",L"10.5");
json.UpdateString(L"product.description",L"nice summer t-shirt");
json.UpdateString(L"product.sku",L"123df");
json.UpdateBool(L"product.visible",false);
json.UpdateNumber(L"product.weight",L"0.2");
json.UpdateString(L"product.discount.type",L"AMOUNT");
json.UpdateInt(L"product.discount.value",1);
json.UpdateBool(L"product.manageVariants",true);
json.UpdateString(L"product.productOptions[0].name",L"Size");
json.UpdateString(L"product.productOptions[0].choices[0].value",L"S");
json.UpdateString(L"product.productOptions[0].choices[0].description",L"S");
json.UpdateString(L"product.productOptions[0].choices[1].value",L"L");
json.UpdateString(L"product.productOptions[0].choices[1].description",L"L");
http.put_AuthToken(L"ACCESS_TOKEN");
CkHttpResponseW resp;
success = http.HttpJson(L"POST",L"https://www.wixapis.com/stores/v1/products",json,L"application/json",resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkStringBuilderW sbResponseBody;
resp.GetBodySb(sbResponseBody);
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",jResp.emit());
int respStatusCode = resp.get_StatusCode();
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",resp.header());
wprintf(L"Failed.\n");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "product": {
// "id": "e28e4ddd-6ed0-4098-a5e5-cf4bd9c4f7b5",
// "name": "T-shirt",
// "slug": "t-shirt-1",
// "visible": false,
// "productType": "physical",
// "description": "nice summer t-shirt",
// "stock": {
// "trackInventory": false,
// "inStock": true
// },
// "price": {
// "currency": "ILS",
// "price": 10.5,
// "discountedPrice": 9.5,
// "formatted": {
// "price": "10.50",
// "discountedPrice": "9.50"
// }
// },
// "priceData": {
// "currency": "ILS",
// "price": 10.5,
// "discountedPrice": 9.5,
// "formatted": {
// "price": "10.50",
// "discountedPrice": "9.50"
// }
// },
// "additionalInfoSections": [
// ],
// "ribbons": [
// ],
// "media": {
// "items": [
// ]
// },
// "customTextFields": [
// ],
// "manageVariants": true,
// "productOptions": [
// {
// "optionType": "drop_down",
// "name": "Size",
// "choices": [
// {
// "value": "S",
// "description": "S",
// "inStock": true,
// "visible": true
// },
// {
// "value": "L",
// "description": "L",
// "inStock": true,
// "visible": true
// }
// ]
// }
// ],
// "productPageUrl": {
// "base": "https://www.itsjusttooeasy123.com/",
// "path": "/product-page/t-shirt-1"
// },
// "numericId": "1567588455405000",
// "inventoryItemId": "1d71b222-912f-bf67-5a1a-30b4263b084a",
// "discount": {
// "type": "AMOUNT",
// "value": 1
// },
// "collectionIds": [
// ],
// "variants": [
// {
// "id": "00000000-0000-0001-0005-93fc95e0514a",
// "choices": {
// "Size": "S"
// },
// "variant": {
// "priceData": {
// "currency": "ILS",
// "price": 10.5,
// "discountedPrice": 9.5,
// "formatted": {
// "price": "10.50",
// "discountedPrice": "9.50"
// }
// },
// "weight": 10,
// "visible": true
// }
// },
// {
// "id": "00000000-0000-0002-0005-93fc95e0514a",
// "choices": {
// "Size": "L"
// },
// "variant": {
// "priceData": {
// "currency": "ILS",
// "price": 10.5,
// "discountedPrice": 9.5,
// "formatted": {
// "price": "10.50",
// "discountedPrice": "9.50"
// }
// },
// "visible": true
// }
// }
// ]
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
const wchar_t *optionType = 0;
const wchar_t *name = 0;
int j;
int count_j;
const wchar_t *value = 0;
const wchar_t *description = 0;
bool inStock;
bool visible;
const wchar_t *id = 0;
const wchar_t *choicesSize = 0;
const wchar_t *variantPriceDataCurrency = 0;
const wchar_t *variantPriceDataPrice = 0;
const wchar_t *variantPriceDataDiscountedPrice = 0;
const wchar_t *variantPriceDataFormattedPrice = 0;
const wchar_t *variantPriceDataFormattedDiscountedPrice = 0;
int variantWeight;
bool variantVisible;
const wchar_t *productId = jResp.stringOf(L"product.id");
const wchar_t *productName = jResp.stringOf(L"product.name");
const wchar_t *productSlug = jResp.stringOf(L"product.slug");
bool productVisible = jResp.BoolOf(L"product.visible");
const wchar_t *productProductType = jResp.stringOf(L"product.productType");
const wchar_t *productDescription = jResp.stringOf(L"product.description");
bool productStockTrackInventory = jResp.BoolOf(L"product.stock.trackInventory");
bool productStockInStock = jResp.BoolOf(L"product.stock.inStock");
const wchar_t *productPriceCurrency = jResp.stringOf(L"product.price.currency");
const wchar_t *productPricePrice = jResp.stringOf(L"product.price.price");
const wchar_t *productPriceDiscountedPrice = jResp.stringOf(L"product.price.discountedPrice");
const wchar_t *productPriceFormattedPrice = jResp.stringOf(L"product.price.formatted.price");
const wchar_t *productPriceFormattedDiscountedPrice = jResp.stringOf(L"product.price.formatted.discountedPrice");
const wchar_t *productPriceDataCurrency = jResp.stringOf(L"product.priceData.currency");
const wchar_t *productPriceDataPrice = jResp.stringOf(L"product.priceData.price");
const wchar_t *productPriceDataDiscountedPrice = jResp.stringOf(L"product.priceData.discountedPrice");
const wchar_t *productPriceDataFormattedPrice = jResp.stringOf(L"product.priceData.formatted.price");
const wchar_t *productPriceDataFormattedDiscountedPrice = jResp.stringOf(L"product.priceData.formatted.discountedPrice");
bool productManageVariants = jResp.BoolOf(L"product.manageVariants");
const wchar_t *productProductPageUrlBase = jResp.stringOf(L"product.productPageUrl.base");
const wchar_t *productProductPageUrlPath = jResp.stringOf(L"product.productPageUrl.path");
const wchar_t *productNumericId = jResp.stringOf(L"product.numericId");
const wchar_t *productInventoryItemId = jResp.stringOf(L"product.inventoryItemId");
const wchar_t *productDiscountType = jResp.stringOf(L"product.discount.type");
int productDiscountValue = jResp.IntOf(L"product.discount.value");
int i = 0;
int count_i = jResp.SizeOfArray(L"product.additionalInfoSections");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"product.ribbons");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"product.media.items");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"product.customTextFields");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"product.productOptions");
while (i < count_i) {
jResp.put_I(i);
optionType = jResp.stringOf(L"product.productOptions[i].optionType");
name = jResp.stringOf(L"product.productOptions[i].name");
j = 0;
count_j = jResp.SizeOfArray(L"product.productOptions[i].choices");
while (j < count_j) {
jResp.put_J(j);
value = jResp.stringOf(L"product.productOptions[i].choices[j].value");
description = jResp.stringOf(L"product.productOptions[i].choices[j].description");
inStock = jResp.BoolOf(L"product.productOptions[i].choices[j].inStock");
visible = jResp.BoolOf(L"product.productOptions[i].choices[j].visible");
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"product.collectionIds");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"product.variants");
while (i < count_i) {
jResp.put_I(i);
id = jResp.stringOf(L"product.variants[i].id");
choicesSize = jResp.stringOf(L"product.variants[i].choices.Size");
variantPriceDataCurrency = jResp.stringOf(L"product.variants[i].variant.priceData.currency");
variantPriceDataPrice = jResp.stringOf(L"product.variants[i].variant.priceData.price");
variantPriceDataDiscountedPrice = jResp.stringOf(L"product.variants[i].variant.priceData.discountedPrice");
variantPriceDataFormattedPrice = jResp.stringOf(L"product.variants[i].variant.priceData.formatted.price");
variantPriceDataFormattedDiscountedPrice = jResp.stringOf(L"product.variants[i].variant.priceData.formatted.discountedPrice");
variantWeight = jResp.IntOf(L"product.variants[i].variant.weight");
variantVisible = jResp.BoolOf(L"product.variants[i].variant.visible");
i = i + 1;
}
}