C
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 C Downloads
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
HCkJsonObject json;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *optionType;
const char *name;
int j;
int count_j;
const char *value;
const char *description;
BOOL inStock;
BOOL visible;
const char *id;
const char *choicesSize;
const char *variantPriceDataCurrency;
const char *variantPriceDataPrice;
const char *variantPriceDataDiscountedPrice;
const char *variantPriceDataFormattedPrice;
const char *variantPriceDataFormattedDiscountedPrice;
int variantWeight;
BOOL variantVisible;
const char *productId;
const char *productName;
const char *productSlug;
BOOL productVisible;
const char *productProductType;
const char *productDescription;
BOOL productStockTrackInventory;
BOOL productStockInStock;
const char *productPriceCurrency;
const char *productPricePrice;
const char *productPriceDiscountedPrice;
const char *productPriceFormattedPrice;
const char *productPriceFormattedDiscountedPrice;
const char *productPriceDataCurrency;
const char *productPriceDataPrice;
const char *productPriceDataDiscountedPrice;
const char *productPriceDataFormattedPrice;
const char *productPriceDataFormattedDiscountedPrice;
BOOL productManageVariants;
const char *productProductPageUrlBase;
const char *productProductPageUrlPath;
const char *productNumericId;
const char *productInventoryItemId;
const char *productDiscountType;
int productDiscountValue;
int i;
int count_i;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
// 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"
// }
// ]
// }
// ]
// }
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"product.name","T-shirt");
CkJsonObject_UpdateString(json,"product.productType","physical");
CkJsonObject_UpdateNumber(json,"product.priceData.price","10.5");
CkJsonObject_UpdateString(json,"product.description","nice summer t-shirt");
CkJsonObject_UpdateString(json,"product.sku","123df");
CkJsonObject_UpdateBool(json,"product.visible",FALSE);
CkJsonObject_UpdateNumber(json,"product.weight","0.2");
CkJsonObject_UpdateString(json,"product.discount.type","AMOUNT");
CkJsonObject_UpdateInt(json,"product.discount.value",1);
CkJsonObject_UpdateBool(json,"product.manageVariants",TRUE);
CkJsonObject_UpdateString(json,"product.productOptions[0].name","Size");
CkJsonObject_UpdateString(json,"product.productOptions[0].choices[0].value","S");
CkJsonObject_UpdateString(json,"product.productOptions[0].choices[0].description","S");
CkJsonObject_UpdateString(json,"product.productOptions[0].choices[1].value","L");
CkJsonObject_UpdateString(json,"product.productOptions[0].choices[1].description","L");
CkHttp_putAuthToken(http,"ACCESS_TOKEN");
resp = CkHttpResponse_Create();
success = CkHttp_HttpJson(http,"POST","https://www.wixapis.com/stores/v1/products",json,"application/json",resp);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkHttpResponse_Dispose(resp);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkHttpResponse_Dispose(resp);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
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.
productId = CkJsonObject_stringOf(jResp,"product.id");
productName = CkJsonObject_stringOf(jResp,"product.name");
productSlug = CkJsonObject_stringOf(jResp,"product.slug");
productVisible = CkJsonObject_BoolOf(jResp,"product.visible");
productProductType = CkJsonObject_stringOf(jResp,"product.productType");
productDescription = CkJsonObject_stringOf(jResp,"product.description");
productStockTrackInventory = CkJsonObject_BoolOf(jResp,"product.stock.trackInventory");
productStockInStock = CkJsonObject_BoolOf(jResp,"product.stock.inStock");
productPriceCurrency = CkJsonObject_stringOf(jResp,"product.price.currency");
productPricePrice = CkJsonObject_stringOf(jResp,"product.price.price");
productPriceDiscountedPrice = CkJsonObject_stringOf(jResp,"product.price.discountedPrice");
productPriceFormattedPrice = CkJsonObject_stringOf(jResp,"product.price.formatted.price");
productPriceFormattedDiscountedPrice = CkJsonObject_stringOf(jResp,"product.price.formatted.discountedPrice");
productPriceDataCurrency = CkJsonObject_stringOf(jResp,"product.priceData.currency");
productPriceDataPrice = CkJsonObject_stringOf(jResp,"product.priceData.price");
productPriceDataDiscountedPrice = CkJsonObject_stringOf(jResp,"product.priceData.discountedPrice");
productPriceDataFormattedPrice = CkJsonObject_stringOf(jResp,"product.priceData.formatted.price");
productPriceDataFormattedDiscountedPrice = CkJsonObject_stringOf(jResp,"product.priceData.formatted.discountedPrice");
productManageVariants = CkJsonObject_BoolOf(jResp,"product.manageVariants");
productProductPageUrlBase = CkJsonObject_stringOf(jResp,"product.productPageUrl.base");
productProductPageUrlPath = CkJsonObject_stringOf(jResp,"product.productPageUrl.path");
productNumericId = CkJsonObject_stringOf(jResp,"product.numericId");
productInventoryItemId = CkJsonObject_stringOf(jResp,"product.inventoryItemId");
productDiscountType = CkJsonObject_stringOf(jResp,"product.discount.type");
productDiscountValue = CkJsonObject_IntOf(jResp,"product.discount.value");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"product.additionalInfoSections");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"product.ribbons");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"product.media.items");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"product.customTextFields");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"product.productOptions");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
optionType = CkJsonObject_stringOf(jResp,"product.productOptions[i].optionType");
name = CkJsonObject_stringOf(jResp,"product.productOptions[i].name");
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"product.productOptions[i].choices");
while (j < count_j) {
CkJsonObject_putJ(jResp,j);
value = CkJsonObject_stringOf(jResp,"product.productOptions[i].choices[j].value");
description = CkJsonObject_stringOf(jResp,"product.productOptions[i].choices[j].description");
inStock = CkJsonObject_BoolOf(jResp,"product.productOptions[i].choices[j].inStock");
visible = CkJsonObject_BoolOf(jResp,"product.productOptions[i].choices[j].visible");
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"product.collectionIds");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"product.variants");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
id = CkJsonObject_stringOf(jResp,"product.variants[i].id");
choicesSize = CkJsonObject_stringOf(jResp,"product.variants[i].choices.Size");
variantPriceDataCurrency = CkJsonObject_stringOf(jResp,"product.variants[i].variant.priceData.currency");
variantPriceDataPrice = CkJsonObject_stringOf(jResp,"product.variants[i].variant.priceData.price");
variantPriceDataDiscountedPrice = CkJsonObject_stringOf(jResp,"product.variants[i].variant.priceData.discountedPrice");
variantPriceDataFormattedPrice = CkJsonObject_stringOf(jResp,"product.variants[i].variant.priceData.formatted.price");
variantPriceDataFormattedDiscountedPrice = CkJsonObject_stringOf(jResp,"product.variants[i].variant.priceData.formatted.discountedPrice");
variantWeight = CkJsonObject_IntOf(jResp,"product.variants[i].variant.weight");
variantVisible = CkJsonObject_BoolOf(jResp,"product.variants[i].variant.visible");
i = i + 1;
}
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkHttpResponse_Dispose(resp);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}