Go
Go
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 Go Downloads
success := false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := chilkat.NewHttp()
// 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 := chilkat.NewJsonObject()
json.UpdateString("product.name","T-shirt")
json.UpdateString("product.productType","physical")
json.UpdateNumber("product.priceData.price","10.5")
json.UpdateString("product.description","nice summer t-shirt")
json.UpdateString("product.sku","123df")
json.UpdateBool("product.visible",false)
json.UpdateNumber("product.weight","0.2")
json.UpdateString("product.discount.type","AMOUNT")
json.UpdateInt("product.discount.value",1)
json.UpdateBool("product.manageVariants",true)
json.UpdateString("product.productOptions[0].name","Size")
json.UpdateString("product.productOptions[0].choices[0].value","S")
json.UpdateString("product.productOptions[0].choices[0].description","S")
json.UpdateString("product.productOptions[0].choices[1].value","L")
json.UpdateString("product.productOptions[0].choices[1].description","L")
http.SetAuthToken("ACCESS_TOKEN")
resp := chilkat.NewHttpResponse()
success = http.HttpJson("POST","https://www.wixapis.com/stores/v1/products",json,"application/json",resp)
if success == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
json.DisposeJsonObject()
resp.DisposeHttpResponse()
return
}
sbResponseBody := chilkat.NewStringBuilder()
resp.GetBodySb(sbResponseBody)
jResp := chilkat.NewJsonObject()
jResp.LoadSb(sbResponseBody)
jResp.SetEmitCompact(false)
fmt.Println("Response Body:")
fmt.Println(*jResp.Emit())
respStatusCode := resp.StatusCode()
fmt.Println("Response Status Code = ", respStatusCode)
if respStatusCode >= 400 {
fmt.Println("Response Header:")
fmt.Println(resp.Header())
fmt.Println("Failed.")
http.DisposeHttp()
json.DisposeJsonObject()
resp.DisposeHttpResponse()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
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
var optionType *string = new(string)
var name *string = new(string)
var j int
var count_j int
var value *string = new(string)
var description *string = new(string)
var inStock bool
var visible bool
var id *string = new(string)
var choicesSize *string = new(string)
var variantPriceDataCurrency *string = new(string)
var variantPriceDataPrice *string = new(string)
var variantPriceDataDiscountedPrice *string = new(string)
var variantPriceDataFormattedPrice *string = new(string)
var variantPriceDataFormattedDiscountedPrice *string = new(string)
var variantWeight int
var variantVisible bool
productId := jResp.StringOf("product.id")
productName := jResp.StringOf("product.name")
productSlug := jResp.StringOf("product.slug")
productVisible := jResp.BoolOf("product.visible")
productProductType := jResp.StringOf("product.productType")
productDescription := jResp.StringOf("product.description")
productStockTrackInventory := jResp.BoolOf("product.stock.trackInventory")
productStockInStock := jResp.BoolOf("product.stock.inStock")
productPriceCurrency := jResp.StringOf("product.price.currency")
productPricePrice := jResp.StringOf("product.price.price")
productPriceDiscountedPrice := jResp.StringOf("product.price.discountedPrice")
productPriceFormattedPrice := jResp.StringOf("product.price.formatted.price")
productPriceFormattedDiscountedPrice := jResp.StringOf("product.price.formatted.discountedPrice")
productPriceDataCurrency := jResp.StringOf("product.priceData.currency")
productPriceDataPrice := jResp.StringOf("product.priceData.price")
productPriceDataDiscountedPrice := jResp.StringOf("product.priceData.discountedPrice")
productPriceDataFormattedPrice := jResp.StringOf("product.priceData.formatted.price")
productPriceDataFormattedDiscountedPrice := jResp.StringOf("product.priceData.formatted.discountedPrice")
productManageVariants := jResp.BoolOf("product.manageVariants")
productProductPageUrlBase := jResp.StringOf("product.productPageUrl.base")
productProductPageUrlPath := jResp.StringOf("product.productPageUrl.path")
productNumericId := jResp.StringOf("product.numericId")
productInventoryItemId := jResp.StringOf("product.inventoryItemId")
productDiscountType := jResp.StringOf("product.discount.type")
productDiscountValue := jResp.IntOf("product.discount.value")
i := 0
count_i := jResp.SizeOfArray("product.additionalInfoSections")
for i < count_i {
jResp.SetI(i)
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("product.ribbons")
for i < count_i {
jResp.SetI(i)
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("product.media.items")
for i < count_i {
jResp.SetI(i)
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("product.customTextFields")
for i < count_i {
jResp.SetI(i)
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("product.productOptions")
for i < count_i {
jResp.SetI(i)
optionType = jResp.StringOf("product.productOptions[i].optionType")
name = jResp.StringOf("product.productOptions[i].name")
j = 0
count_j = jResp.SizeOfArray("product.productOptions[i].choices")
for j < count_j {
jResp.SetJ(j)
value = jResp.StringOf("product.productOptions[i].choices[j].value")
description = jResp.StringOf("product.productOptions[i].choices[j].description")
inStock = jResp.BoolOf("product.productOptions[i].choices[j].inStock")
visible = jResp.BoolOf("product.productOptions[i].choices[j].visible")
j = j + 1
}
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("product.collectionIds")
for i < count_i {
jResp.SetI(i)
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("product.variants")
for i < count_i {
jResp.SetI(i)
id = jResp.StringOf("product.variants[i].id")
choicesSize = jResp.StringOf("product.variants[i].choices.Size")
variantPriceDataCurrency = jResp.StringOf("product.variants[i].variant.priceData.currency")
variantPriceDataPrice = jResp.StringOf("product.variants[i].variant.priceData.price")
variantPriceDataDiscountedPrice = jResp.StringOf("product.variants[i].variant.priceData.discountedPrice")
variantPriceDataFormattedPrice = jResp.StringOf("product.variants[i].variant.priceData.formatted.price")
variantPriceDataFormattedDiscountedPrice = jResp.StringOf("product.variants[i].variant.priceData.formatted.discountedPrice")
variantWeight = jResp.IntOf("product.variants[i].variant.weight")
variantVisible = jResp.BoolOf("product.variants[i].variant.visible")
i = i + 1
}
http.DisposeHttp()
json.DisposeJsonObject()
resp.DisposeHttpResponse()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()