AutoIt
AutoIt
Lightspeed - Create a Product
See more Lightspeed Examples
Create a new product based on the given parameters.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
; 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
$oHttp.Login = "API_KEY"
$oHttp.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
; }
; }
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("product.visibility","visible")
$oJson.UpdateString("product.data01","")
$oJson.UpdateString("product.data02","")
$oJson.UpdateString("product.data03","")
$oJson.UpdateString("product.title","Lookin Sharp T-Shirt")
$oJson.UpdateString("product.fulltitle","Lookin Sharp T-Shirt")
$oJson.UpdateString("product.description","Description of the Lookin Sharp T-Shirt")
$oJson.UpdateString("product.content","Long Description of the Lookin Sharp T-Shirt")
$oJson.UpdateInt("product.deliverydate",6488)
$oJson.UpdateInt("product.supplier",78794)
$oJson.UpdateInt("product.brand",1171202)
$oHttp.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/
$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpJson("POST","https://api.webshopapp.com/en/products.json",$oJson,"application/json",$oResp)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oResp.Header & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; 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
Local $iProductId = $oJResp.IntOf("product.id")
Local $sProductCreatedAt = $oJResp.StringOf("product.createdAt")
Local $sProductUpdatedAt = $oJResp.StringOf("product.updatedAt")
Local $bProductIsVisible = $oJResp.BoolOf("product.isVisible")
Local $sProductVisibility = $oJResp.StringOf("product.visibility")
Local $bProductHasMatrix = $oJResp.BoolOf("product.hasMatrix")
Local $sProductData01 = $oJResp.StringOf("product.data01")
Local $sProductData02 = $oJResp.StringOf("product.data02")
Local $sProductData03 = $oJResp.StringOf("product.data03")
Local $sProductUrl = $oJResp.StringOf("product.url")
Local $sProductTitle = $oJResp.StringOf("product.title")
Local $sProductFulltitle = $oJResp.StringOf("product.fulltitle")
Local $sProductDescription = $oJResp.StringOf("product.description")
Local $sProductContent = $oJResp.StringOf("product.content")
Local $bProductSet = $oJResp.BoolOf("product.set")
Local $iProductBrandResourceId = $oJResp.IntOf("product.brand.resource.id")
Local $sProductBrandResourceUrl = $oJResp.StringOf("product.brand.resource.url")
Local $sProductBrandResourceLink = $oJResp.StringOf("product.brand.resource.link")
Local $bProductCategoriesResourceId = $oJResp.BoolOf("product.categories.resource.id")
Local $sProductCategoriesResourceUrl = $oJResp.StringOf("product.categories.resource.url")
Local $sProductCategoriesResourceLink = $oJResp.StringOf("product.categories.resource.link")
Local $iProductDeliverydateResourceId = $oJResp.IntOf("product.deliverydate.resource.id")
Local $sProductDeliverydateResourceUrl = $oJResp.StringOf("product.deliverydate.resource.url")
Local $sProductDeliverydateResourceLink = $oJResp.StringOf("product.deliverydate.resource.link")
Local $bProductImage = $oJResp.BoolOf("product.image")
Local $bProductImages = $oJResp.BoolOf("product.images")
Local $bProductRelationsResourceId = $oJResp.BoolOf("product.relations.resource.id")
Local $sProductRelationsResourceUrl = $oJResp.StringOf("product.relations.resource.url")
Local $sProductRelationsResourceLink = $oJResp.StringOf("product.relations.resource.link")
Local $bProductMetafieldsResourceId = $oJResp.BoolOf("product.metafields.resource.id")
Local $sProductMetafieldsResourceUrl = $oJResp.StringOf("product.metafields.resource.url")
Local $sProductMetafieldsResourceLink = $oJResp.StringOf("product.metafields.resource.link")
Local $bProductReviewsResourceId = $oJResp.BoolOf("product.reviews.resource.id")
Local $sProductReviewsResourceUrl = $oJResp.StringOf("product.reviews.resource.url")
Local $sProductReviewsResourceLink = $oJResp.StringOf("product.reviews.resource.link")
Local $bProductType = $oJResp.BoolOf("product.type")
Local $bProductAttributesResourceId = $oJResp.BoolOf("product.attributes.resource.id")
Local $sProductAttributesResourceUrl = $oJResp.StringOf("product.attributes.resource.url")
Local $sProductAttributesResourceLink = $oJResp.StringOf("product.attributes.resource.link")
Local $iProductSupplierResourceId = $oJResp.IntOf("product.supplier.resource.id")
Local $sProductSupplierResourceUrl = $oJResp.StringOf("product.supplier.resource.url")
Local $sProductSupplierResourceLink = $oJResp.StringOf("product.supplier.resource.link")
Local $bProductTagsResourceId = $oJResp.BoolOf("product.tags.resource.id")
Local $sProductTagsResourceUrl = $oJResp.StringOf("product.tags.resource.url")
Local $sProductTagsResourceLink = $oJResp.StringOf("product.tags.resource.link")
Local $bProductVariantsResourceId = $oJResp.BoolOf("product.variants.resource.id")
Local $sProductVariantsResourceUrl = $oJResp.StringOf("product.variants.resource.url")
Local $sProductVariantsResourceLink = $oJResp.StringOf("product.variants.resource.link")
Local $bProductMovementsResourceId = $oJResp.BoolOf("product.movements.resource.id")
Local $sProductMovementsResourceUrl = $oJResp.StringOf("product.movements.resource.url")
Local $sProductMovementsResourceLink = $oJResp.StringOf("product.movements.resource.link")