Unicode C
Unicode C
Lightspeed - Create a Product
See more Lightspeed Examples
Create a new product based on the given parameters.Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkJsonObjectW json;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
int productId;
const wchar_t *productCreatedAt;
const wchar_t *productUpdatedAt;
BOOL productIsVisible;
const wchar_t *productVisibility;
BOOL productHasMatrix;
const wchar_t *productData01;
const wchar_t *productData02;
const wchar_t *productData03;
const wchar_t *productUrl;
const wchar_t *productTitle;
const wchar_t *productFulltitle;
const wchar_t *productDescription;
const wchar_t *productContent;
BOOL productSet;
int productBrandResourceId;
const wchar_t *productBrandResourceUrl;
const wchar_t *productBrandResourceLink;
BOOL productCategoriesResourceId;
const wchar_t *productCategoriesResourceUrl;
const wchar_t *productCategoriesResourceLink;
int productDeliverydateResourceId;
const wchar_t *productDeliverydateResourceUrl;
const wchar_t *productDeliverydateResourceLink;
BOOL productImage;
BOOL productImages;
BOOL productRelationsResourceId;
const wchar_t *productRelationsResourceUrl;
const wchar_t *productRelationsResourceLink;
BOOL productMetafieldsResourceId;
const wchar_t *productMetafieldsResourceUrl;
const wchar_t *productMetafieldsResourceLink;
BOOL productReviewsResourceId;
const wchar_t *productReviewsResourceUrl;
const wchar_t *productReviewsResourceLink;
BOOL productType;
BOOL productAttributesResourceId;
const wchar_t *productAttributesResourceUrl;
const wchar_t *productAttributesResourceLink;
int productSupplierResourceId;
const wchar_t *productSupplierResourceUrl;
const wchar_t *productSupplierResourceLink;
BOOL productTagsResourceId;
const wchar_t *productTagsResourceUrl;
const wchar_t *productTagsResourceLink;
BOOL productVariantsResourceId;
const wchar_t *productVariantsResourceUrl;
const wchar_t *productVariantsResourceLink;
BOOL productMovementsResourceId;
const wchar_t *productMovementsResourceUrl;
const wchar_t *productMovementsResourceLink;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Implements the following CURL command:
// curl -u API_KEY:API_SECRET \
// -H "Content-Type: application/json" \
// -X POST \
// -d '{
// "product": {
// "visibility": "visible",
// "data01": "",
// "data02": "",
// "data03": "",
// "title": "Lookin Sharp T-Shirt",
// "fulltitle": "Lookin Sharp T-Shirt",
// "description": "Description of the Lookin Sharp T-Shirt",
// "content": "Long Description of the Lookin Sharp T-Shirt",
// "deliverydate": 6488,
// "supplier": 78794,
// "brand": 1171202
// }
// }' \
// "https://api.webshopapp.com/en/products.json"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
CkHttpW_putLogin(http,L"API_KEY");
CkHttpW_putPassword(http,L"API_SECRET");
// 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": {
// "visibility": "visible",
// "data01": "",
// "data02": "",
// "data03": "",
// "title": "Lookin Sharp T-Shirt",
// "fulltitle": "Lookin Sharp T-Shirt",
// "description": "Description of the Lookin Sharp T-Shirt",
// "content": "Long Description of the Lookin Sharp T-Shirt",
// "deliverydate": 6488,
// "supplier": 78794,
// "brand": 1171202
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"product.visibility",L"visible");
CkJsonObjectW_UpdateString(json,L"product.data01",L"");
CkJsonObjectW_UpdateString(json,L"product.data02",L"");
CkJsonObjectW_UpdateString(json,L"product.data03",L"");
CkJsonObjectW_UpdateString(json,L"product.title",L"Lookin Sharp T-Shirt");
CkJsonObjectW_UpdateString(json,L"product.fulltitle",L"Lookin Sharp T-Shirt");
CkJsonObjectW_UpdateString(json,L"product.description",L"Description of the Lookin Sharp T-Shirt");
CkJsonObjectW_UpdateString(json,L"product.content",L"Long Description of the Lookin Sharp T-Shirt");
CkJsonObjectW_UpdateInt(json,L"product.deliverydate",6488);
CkJsonObjectW_UpdateInt(json,L"product.supplier",78794);
CkJsonObjectW_UpdateInt(json,L"product.brand",1171202);
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
// Use the correct cluster for your shop. Here are the choices:
// eu1 https://api.webshopapp.com/en/
// us1 https://api.shoplightspeed.com/en/
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpJson(http,L"POST",L"https://api.webshopapp.com/en/products.json",json,L"application/json",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
return;
}
sbResponseBody = CkStringBuilderW_Create();
CkHttpResponseW_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpResponseW_getStatusCode(resp);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpResponseW_header(resp));
wprintf(L"Failed.\n");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "product": {
// "id": 20974460,
// "createdAt": "2019-05-28T20:14:26+00:00",
// "updatedAt": "2019-05-28T20:14:26+00:00",
// "isVisible": true,
// "visibility": "visible",
// "hasMatrix": false,
// "data01": "",
// "data02": "",
// "data03": "",
// "url": "lookin-sharp-t-shirt",
// "title": "Lookin' Sharp T-Shirt",
// "fulltitle": "Lookin' Sharp T-Shirt",
// "description": "Description of the Lookin' Sharp T-Shirt",
// "content": "<p>Long Description of the Lookin' Sharp T-Shirt</p>",
// "set": false,
// "brand": {
// "resource": {
// "id": 1171202,
// "url": "brands/1171202",
// "link": "https://api.shoplightspeed.com/us/brands/1171202.json"
// }
// },
// "categories": {
// "resource": {
// "id": false,
// "url": "categories/products?product=20974460",
// "link": "https://api.shoplightspeed.com/us/categories/products.json?product=20974460"
// }
// },
// "deliverydate": {
// "resource": {
// "id": 6488,
// "url": "deliverydates/6488",
// "link": "https://api.shoplightspeed.com/us/deliverydates/6488.json"
// }
// },
// "image": false,
// "images": false,
// "relations": {
// "resource": {
// "id": false,
// "url": "products/20974460/relations",
// "link": "https://api.shoplightspeed.com/us/products/20974460/relations.json"
// }
// },
// "metafields": {
// "resource": {
// "id": false,
// "url": "products/20974460/metafields",
// "link": "https://api.shoplightspeed.com/us/products/20974460/metafields.json"
// }
// },
// "reviews": {
// "resource": {
// "id": false,
// "url": "reviews?product=20974460",
// "link": "https://api.shoplightspeed.com/us/reviews.json?product=20974460"
// }
// },
// "type": false,
// "attributes": {
// "resource": {
// "id": false,
// "url": "products/20974460/attributes",
// "link": "https://api.shoplightspeed.com/us/products/20974460/attributes.json"
// }
// },
// "supplier": {
// "resource": {
// "id": 78794,
// "url": "suppliers/78794",
// "link": "https://api.shoplightspeed.com/us/suppliers/78794.json"
// }
// },
// "tags": {
// "resource": {
// "id": false,
// "url": "tags/products?product=20974460",
// "link": "https://api.shoplightspeed.com/us/tags/products.json?product=20974460"
// }
// },
// "variants": {
// "resource": {
// "id": false,
// "url": "variants?product=20974460",
// "link": "https://api.shoplightspeed.com/us/variants.json?product=20974460"
// }
// },
// "movements": {
// "resource": {
// "id": false,
// "url": "variants/movements?product=20974460",
// "link": "https://api.shoplightspeed.com/us/variants/movements.json?product=20974460"
// }
// }
// }
// }
// 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 = CkJsonObjectW_IntOf(jResp,L"product.id");
productCreatedAt = CkJsonObjectW_stringOf(jResp,L"product.createdAt");
productUpdatedAt = CkJsonObjectW_stringOf(jResp,L"product.updatedAt");
productIsVisible = CkJsonObjectW_BoolOf(jResp,L"product.isVisible");
productVisibility = CkJsonObjectW_stringOf(jResp,L"product.visibility");
productHasMatrix = CkJsonObjectW_BoolOf(jResp,L"product.hasMatrix");
productData01 = CkJsonObjectW_stringOf(jResp,L"product.data01");
productData02 = CkJsonObjectW_stringOf(jResp,L"product.data02");
productData03 = CkJsonObjectW_stringOf(jResp,L"product.data03");
productUrl = CkJsonObjectW_stringOf(jResp,L"product.url");
productTitle = CkJsonObjectW_stringOf(jResp,L"product.title");
productFulltitle = CkJsonObjectW_stringOf(jResp,L"product.fulltitle");
productDescription = CkJsonObjectW_stringOf(jResp,L"product.description");
productContent = CkJsonObjectW_stringOf(jResp,L"product.content");
productSet = CkJsonObjectW_BoolOf(jResp,L"product.set");
productBrandResourceId = CkJsonObjectW_IntOf(jResp,L"product.brand.resource.id");
productBrandResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.brand.resource.url");
productBrandResourceLink = CkJsonObjectW_stringOf(jResp,L"product.brand.resource.link");
productCategoriesResourceId = CkJsonObjectW_BoolOf(jResp,L"product.categories.resource.id");
productCategoriesResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.categories.resource.url");
productCategoriesResourceLink = CkJsonObjectW_stringOf(jResp,L"product.categories.resource.link");
productDeliverydateResourceId = CkJsonObjectW_IntOf(jResp,L"product.deliverydate.resource.id");
productDeliverydateResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.deliverydate.resource.url");
productDeliverydateResourceLink = CkJsonObjectW_stringOf(jResp,L"product.deliverydate.resource.link");
productImage = CkJsonObjectW_BoolOf(jResp,L"product.image");
productImages = CkJsonObjectW_BoolOf(jResp,L"product.images");
productRelationsResourceId = CkJsonObjectW_BoolOf(jResp,L"product.relations.resource.id");
productRelationsResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.relations.resource.url");
productRelationsResourceLink = CkJsonObjectW_stringOf(jResp,L"product.relations.resource.link");
productMetafieldsResourceId = CkJsonObjectW_BoolOf(jResp,L"product.metafields.resource.id");
productMetafieldsResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.metafields.resource.url");
productMetafieldsResourceLink = CkJsonObjectW_stringOf(jResp,L"product.metafields.resource.link");
productReviewsResourceId = CkJsonObjectW_BoolOf(jResp,L"product.reviews.resource.id");
productReviewsResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.reviews.resource.url");
productReviewsResourceLink = CkJsonObjectW_stringOf(jResp,L"product.reviews.resource.link");
productType = CkJsonObjectW_BoolOf(jResp,L"product.type");
productAttributesResourceId = CkJsonObjectW_BoolOf(jResp,L"product.attributes.resource.id");
productAttributesResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.attributes.resource.url");
productAttributesResourceLink = CkJsonObjectW_stringOf(jResp,L"product.attributes.resource.link");
productSupplierResourceId = CkJsonObjectW_IntOf(jResp,L"product.supplier.resource.id");
productSupplierResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.supplier.resource.url");
productSupplierResourceLink = CkJsonObjectW_stringOf(jResp,L"product.supplier.resource.link");
productTagsResourceId = CkJsonObjectW_BoolOf(jResp,L"product.tags.resource.id");
productTagsResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.tags.resource.url");
productTagsResourceLink = CkJsonObjectW_stringOf(jResp,L"product.tags.resource.link");
productVariantsResourceId = CkJsonObjectW_BoolOf(jResp,L"product.variants.resource.id");
productVariantsResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.variants.resource.url");
productVariantsResourceLink = CkJsonObjectW_stringOf(jResp,L"product.variants.resource.link");
productMovementsResourceId = CkJsonObjectW_BoolOf(jResp,L"product.movements.resource.id");
productMovementsResourceUrl = CkJsonObjectW_stringOf(jResp,L"product.movements.resource.url");
productMovementsResourceLink = CkJsonObjectW_stringOf(jResp,L"product.movements.resource.link");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}