Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C) Lightspeed - Create a ProductCreate a new product based on the given parameters. For more information, see https://developers.lightspeedhq.com/ecom/endpoints/product/#post-create-a-product
#include <C_CkHttp.h> #include <C_CkJsonObject.h> #include <C_CkHttpResponse.h> #include <C_CkStringBuilder.h> void ChilkatSample(void) { HCkHttp http; BOOL success; HCkJsonObject json; HCkHttpResponse resp; HCkStringBuilder sbResponseBody; HCkJsonObject jResp; int respStatusCode; int productId; const char *productCreatedAt; const char *productUpdatedAt; BOOL productIsVisible; const char *productVisibility; BOOL productHasMatrix; const char *productData01; const char *productData02; const char *productData03; const char *productUrl; const char *productTitle; const char *productFulltitle; const char *productDescription; const char *productContent; BOOL productSet; int productBrandResourceId; const char *productBrandResourceUrl; const char *productBrandResourceLink; BOOL productCategoriesResourceId; const char *productCategoriesResourceUrl; const char *productCategoriesResourceLink; int productDeliverydateResourceId; const char *productDeliverydateResourceUrl; const char *productDeliverydateResourceLink; BOOL productImage; BOOL productImages; BOOL productRelationsResourceId; const char *productRelationsResourceUrl; const char *productRelationsResourceLink; BOOL productMetafieldsResourceId; const char *productMetafieldsResourceUrl; const char *productMetafieldsResourceLink; BOOL productReviewsResourceId; const char *productReviewsResourceUrl; const char *productReviewsResourceLink; BOOL productType; BOOL productAttributesResourceId; const char *productAttributesResourceUrl; const char *productAttributesResourceLink; int productSupplierResourceId; const char *productSupplierResourceUrl; const char *productSupplierResourceLink; BOOL productTagsResourceId; const char *productTagsResourceUrl; const char *productTagsResourceLink; BOOL productVariantsResourceId; const char *productVariantsResourceUrl; const char *productVariantsResourceLink; BOOL productMovementsResourceId; const char *productMovementsResourceUrl; const char *productMovementsResourceLink; // 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 -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 CkHttp_putLogin(http,"API_KEY"); CkHttp_putPassword(http,"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 = CkJsonObject_Create(); CkJsonObject_UpdateString(json,"product.visibility","visible"); CkJsonObject_UpdateString(json,"product.data01",""); CkJsonObject_UpdateString(json,"product.data02",""); CkJsonObject_UpdateString(json,"product.data03",""); CkJsonObject_UpdateString(json,"product.title","Lookin Sharp T-Shirt"); CkJsonObject_UpdateString(json,"product.fulltitle","Lookin Sharp T-Shirt"); CkJsonObject_UpdateString(json,"product.description","Description of the Lookin Sharp T-Shirt"); CkJsonObject_UpdateString(json,"product.content","Long Description of the Lookin Sharp T-Shirt"); CkJsonObject_UpdateInt(json,"product.deliverydate",6488); CkJsonObject_UpdateInt(json,"product.supplier",78794); CkJsonObject_UpdateInt(json,"product.brand",1171202); CkHttp_SetRequestHeader(http,"Content-Type","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 = CkHttp_PostJson3(http,"https://api.webshopapp.com/en/products.json","application/json",json); if (CkHttp_getLastMethodSuccess(http) == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkJsonObject_Dispose(json); 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"); CkHttpResponse_Dispose(resp); CkHttp_Dispose(http); CkJsonObject_Dispose(json); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); return; } CkHttpResponse_Dispose(resp); // 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 = CkJsonObject_IntOf(jResp,"product.id"); productCreatedAt = CkJsonObject_stringOf(jResp,"product.createdAt"); productUpdatedAt = CkJsonObject_stringOf(jResp,"product.updatedAt"); productIsVisible = CkJsonObject_BoolOf(jResp,"product.isVisible"); productVisibility = CkJsonObject_stringOf(jResp,"product.visibility"); productHasMatrix = CkJsonObject_BoolOf(jResp,"product.hasMatrix"); productData01 = CkJsonObject_stringOf(jResp,"product.data01"); productData02 = CkJsonObject_stringOf(jResp,"product.data02"); productData03 = CkJsonObject_stringOf(jResp,"product.data03"); productUrl = CkJsonObject_stringOf(jResp,"product.url"); productTitle = CkJsonObject_stringOf(jResp,"product.title"); productFulltitle = CkJsonObject_stringOf(jResp,"product.fulltitle"); productDescription = CkJsonObject_stringOf(jResp,"product.description"); productContent = CkJsonObject_stringOf(jResp,"product.content"); productSet = CkJsonObject_BoolOf(jResp,"product.set"); productBrandResourceId = CkJsonObject_IntOf(jResp,"product.brand.resource.id"); productBrandResourceUrl = CkJsonObject_stringOf(jResp,"product.brand.resource.url"); productBrandResourceLink = CkJsonObject_stringOf(jResp,"product.brand.resource.link"); productCategoriesResourceId = CkJsonObject_BoolOf(jResp,"product.categories.resource.id"); productCategoriesResourceUrl = CkJsonObject_stringOf(jResp,"product.categories.resource.url"); productCategoriesResourceLink = CkJsonObject_stringOf(jResp,"product.categories.resource.link"); productDeliverydateResourceId = CkJsonObject_IntOf(jResp,"product.deliverydate.resource.id"); productDeliverydateResourceUrl = CkJsonObject_stringOf(jResp,"product.deliverydate.resource.url"); productDeliverydateResourceLink = CkJsonObject_stringOf(jResp,"product.deliverydate.resource.link"); productImage = CkJsonObject_BoolOf(jResp,"product.image"); productImages = CkJsonObject_BoolOf(jResp,"product.images"); productRelationsResourceId = CkJsonObject_BoolOf(jResp,"product.relations.resource.id"); productRelationsResourceUrl = CkJsonObject_stringOf(jResp,"product.relations.resource.url"); productRelationsResourceLink = CkJsonObject_stringOf(jResp,"product.relations.resource.link"); productMetafieldsResourceId = CkJsonObject_BoolOf(jResp,"product.metafields.resource.id"); productMetafieldsResourceUrl = CkJsonObject_stringOf(jResp,"product.metafields.resource.url"); productMetafieldsResourceLink = CkJsonObject_stringOf(jResp,"product.metafields.resource.link"); productReviewsResourceId = CkJsonObject_BoolOf(jResp,"product.reviews.resource.id"); productReviewsResourceUrl = CkJsonObject_stringOf(jResp,"product.reviews.resource.url"); productReviewsResourceLink = CkJsonObject_stringOf(jResp,"product.reviews.resource.link"); productType = CkJsonObject_BoolOf(jResp,"product.type"); productAttributesResourceId = CkJsonObject_BoolOf(jResp,"product.attributes.resource.id"); productAttributesResourceUrl = CkJsonObject_stringOf(jResp,"product.attributes.resource.url"); productAttributesResourceLink = CkJsonObject_stringOf(jResp,"product.attributes.resource.link"); productSupplierResourceId = CkJsonObject_IntOf(jResp,"product.supplier.resource.id"); productSupplierResourceUrl = CkJsonObject_stringOf(jResp,"product.supplier.resource.url"); productSupplierResourceLink = CkJsonObject_stringOf(jResp,"product.supplier.resource.link"); productTagsResourceId = CkJsonObject_BoolOf(jResp,"product.tags.resource.id"); productTagsResourceUrl = CkJsonObject_stringOf(jResp,"product.tags.resource.url"); productTagsResourceLink = CkJsonObject_stringOf(jResp,"product.tags.resource.link"); productVariantsResourceId = CkJsonObject_BoolOf(jResp,"product.variants.resource.id"); productVariantsResourceUrl = CkJsonObject_stringOf(jResp,"product.variants.resource.url"); productVariantsResourceLink = CkJsonObject_stringOf(jResp,"product.variants.resource.link"); productMovementsResourceId = CkJsonObject_BoolOf(jResp,"product.movements.resource.id"); productMovementsResourceUrl = CkJsonObject_stringOf(jResp,"product.movements.resource.url"); productMovementsResourceLink = CkJsonObject_stringOf(jResp,"product.movements.resource.link"); CkHttp_Dispose(http); CkJsonObject_Dispose(json); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.