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
(Node.js) 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
var os = require('os'); if (os.platform() == 'win32') { if (os.arch() == 'ia32') { var chilkat = require('@chilkat/ck-node21-win-ia32'); } else { var chilkat = require('@chilkat/ck-node21-win64'); } } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { var chilkat = require('@chilkat/ck-node21-arm'); } else if (os.arch() == 'x86') { var chilkat = require('@chilkat/ck-node21-linux32'); } else { var chilkat = require('@chilkat/ck-node21-linux64'); } } else if (os.platform() == 'darwin') { if (os.arch() == 'arm64') { var chilkat = require('@chilkat/ck-node21-mac-m1'); } else { var chilkat = require('@chilkat/ck-node21-macosx'); } } function chilkatExample() { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. var http = new chilkat.Http(); var success; // 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 http.Login = "API_KEY"; http.Password = "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 // } // } var json = new chilkat.JsonObject(); json.UpdateString("product.visibility","visible"); json.UpdateString("product.data01",""); json.UpdateString("product.data02",""); json.UpdateString("product.data03",""); json.UpdateString("product.title","Lookin Sharp T-Shirt"); json.UpdateString("product.fulltitle","Lookin Sharp T-Shirt"); json.UpdateString("product.description","Description of the Lookin Sharp T-Shirt"); json.UpdateString("product.content","Long Description of the Lookin Sharp T-Shirt"); json.UpdateInt("product.deliverydate",6488); json.UpdateInt("product.supplier",78794); json.UpdateInt("product.brand",1171202); http.SetRequestHeader("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: HttpResponse var resp = http.PostJson3("https://api.webshopapp.com/en/products.json","application/json",json); if (http.LastMethodSuccess == false) { console.log(http.LastErrorText); return; } var sbResponseBody = new chilkat.StringBuilder(); resp.GetBodySb(sbResponseBody); var jResp = new chilkat.JsonObject(); jResp.LoadSb(sbResponseBody); jResp.EmitCompact = false; console.log("Response Body:"); console.log(jResp.Emit()); var respStatusCode = resp.StatusCode; console.log("Response Status Code = " + respStatusCode); if (respStatusCode >= 400) { console.log("Response Header:"); console.log(resp.Header); console.log("Failed."); 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 var productId = jResp.IntOf("product.id"); var productCreatedAt = jResp.StringOf("product.createdAt"); var productUpdatedAt = jResp.StringOf("product.updatedAt"); var productIsVisible = jResp.BoolOf("product.isVisible"); var productVisibility = jResp.StringOf("product.visibility"); var productHasMatrix = jResp.BoolOf("product.hasMatrix"); var productData01 = jResp.StringOf("product.data01"); var productData02 = jResp.StringOf("product.data02"); var productData03 = jResp.StringOf("product.data03"); var productUrl = jResp.StringOf("product.url"); var productTitle = jResp.StringOf("product.title"); var productFulltitle = jResp.StringOf("product.fulltitle"); var productDescription = jResp.StringOf("product.description"); var productContent = jResp.StringOf("product.content"); var productSet = jResp.BoolOf("product.set"); var productBrandResourceId = jResp.IntOf("product.brand.resource.id"); var productBrandResourceUrl = jResp.StringOf("product.brand.resource.url"); var productBrandResourceLink = jResp.StringOf("product.brand.resource.link"); var productCategoriesResourceId = jResp.BoolOf("product.categories.resource.id"); var productCategoriesResourceUrl = jResp.StringOf("product.categories.resource.url"); var productCategoriesResourceLink = jResp.StringOf("product.categories.resource.link"); var productDeliverydateResourceId = jResp.IntOf("product.deliverydate.resource.id"); var productDeliverydateResourceUrl = jResp.StringOf("product.deliverydate.resource.url"); var productDeliverydateResourceLink = jResp.StringOf("product.deliverydate.resource.link"); var productImage = jResp.BoolOf("product.image"); var productImages = jResp.BoolOf("product.images"); var productRelationsResourceId = jResp.BoolOf("product.relations.resource.id"); var productRelationsResourceUrl = jResp.StringOf("product.relations.resource.url"); var productRelationsResourceLink = jResp.StringOf("product.relations.resource.link"); var productMetafieldsResourceId = jResp.BoolOf("product.metafields.resource.id"); var productMetafieldsResourceUrl = jResp.StringOf("product.metafields.resource.url"); var productMetafieldsResourceLink = jResp.StringOf("product.metafields.resource.link"); var productReviewsResourceId = jResp.BoolOf("product.reviews.resource.id"); var productReviewsResourceUrl = jResp.StringOf("product.reviews.resource.url"); var productReviewsResourceLink = jResp.StringOf("product.reviews.resource.link"); var productType = jResp.BoolOf("product.type"); var productAttributesResourceId = jResp.BoolOf("product.attributes.resource.id"); var productAttributesResourceUrl = jResp.StringOf("product.attributes.resource.url"); var productAttributesResourceLink = jResp.StringOf("product.attributes.resource.link"); var productSupplierResourceId = jResp.IntOf("product.supplier.resource.id"); var productSupplierResourceUrl = jResp.StringOf("product.supplier.resource.url"); var productSupplierResourceLink = jResp.StringOf("product.supplier.resource.link"); var productTagsResourceId = jResp.BoolOf("product.tags.resource.id"); var productTagsResourceUrl = jResp.StringOf("product.tags.resource.url"); var productTagsResourceLink = jResp.StringOf("product.tags.resource.link"); var productVariantsResourceId = jResp.BoolOf("product.variants.resource.id"); var productVariantsResourceUrl = jResp.StringOf("product.variants.resource.url"); var productVariantsResourceLink = jResp.StringOf("product.variants.resource.link"); var productMovementsResourceId = jResp.BoolOf("product.movements.resource.id"); var productMovementsResourceUrl = jResp.StringOf("product.movements.resource.url"); var productMovementsResourceLink = jResp.StringOf("product.movements.resource.link"); } chilkatExample(); |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.