Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, HttpResponse, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
optionType: PWideChar;
name: PWideChar;
j: Integer;
count_j: Integer;
value: PWideChar;
description: PWideChar;
inStock: Boolean;
visible: Boolean;
id: PWideChar;
choicesSize: PWideChar;
variantPriceDataCurrency: PWideChar;
variantPriceDataPrice: PWideChar;
variantPriceDataDiscountedPrice: PWideChar;
variantPriceDataFormattedPrice: PWideChar;
variantPriceDataFormattedDiscountedPrice: PWideChar;
variantWeight: Integer;
variantVisible: Boolean;
productId: PWideChar;
productName: PWideChar;
productSlug: PWideChar;
productVisible: Boolean;
productProductType: PWideChar;
productDescription: PWideChar;
productStockTrackInventory: Boolean;
productStockInStock: Boolean;
productPriceCurrency: PWideChar;
productPricePrice: PWideChar;
productPriceDiscountedPrice: PWideChar;
productPriceFormattedPrice: PWideChar;
productPriceFormattedDiscountedPrice: PWideChar;
productPriceDataCurrency: PWideChar;
productPriceDataPrice: PWideChar;
productPriceDataDiscountedPrice: PWideChar;
productPriceDataFormattedPrice: PWideChar;
productPriceDataFormattedDiscountedPrice: PWideChar;
productManageVariants: Boolean;
productProductPageUrlBase: PWideChar;
productProductPageUrlPath: PWideChar;
productNumericId: PWideChar;
productInventoryItemId: PWideChar;
productDiscountType: PWideChar;
productDiscountValue: Integer;
i: Integer;
count_i: Integer;

begin
success := False;

// 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 -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 := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'product.name','T-shirt');
CkJsonObject_UpdateString(json,'product.productType','physical');
CkJsonObject_UpdateNumber(json,'product.priceData.price','10.5');
CkJsonObject_UpdateString(json,'product.description','nice summer t-shirt');
CkJsonObject_UpdateString(json,'product.sku','123df');
CkJsonObject_UpdateBool(json,'product.visible',False);
CkJsonObject_UpdateNumber(json,'product.weight','0.2');
CkJsonObject_UpdateString(json,'product.discount.type','AMOUNT');
CkJsonObject_UpdateInt(json,'product.discount.value',1);
CkJsonObject_UpdateBool(json,'product.manageVariants',True);
CkJsonObject_UpdateString(json,'product.productOptions[0].name','Size');
CkJsonObject_UpdateString(json,'product.productOptions[0].choices[0].value','S');
CkJsonObject_UpdateString(json,'product.productOptions[0].choices[0].description','S');
CkJsonObject_UpdateString(json,'product.productOptions[0].choices[1].value','L');
CkJsonObject_UpdateString(json,'product.productOptions[0].choices[1].description','L');

CkHttp_putAuthToken(http,'ACCESS_TOKEN');

resp := CkHttpResponse_Create();
success := CkHttp_HttpJson(http,'POST','https://www.wixapis.com/stores/v1/products',json,'application/json',resp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

// 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

productId := CkJsonObject__stringOf(jResp,'product.id');
productName := CkJsonObject__stringOf(jResp,'product.name');
productSlug := CkJsonObject__stringOf(jResp,'product.slug');
productVisible := CkJsonObject_BoolOf(jResp,'product.visible');
productProductType := CkJsonObject__stringOf(jResp,'product.productType');
productDescription := CkJsonObject__stringOf(jResp,'product.description');
productStockTrackInventory := CkJsonObject_BoolOf(jResp,'product.stock.trackInventory');
productStockInStock := CkJsonObject_BoolOf(jResp,'product.stock.inStock');
productPriceCurrency := CkJsonObject__stringOf(jResp,'product.price.currency');
productPricePrice := CkJsonObject__stringOf(jResp,'product.price.price');
productPriceDiscountedPrice := CkJsonObject__stringOf(jResp,'product.price.discountedPrice');
productPriceFormattedPrice := CkJsonObject__stringOf(jResp,'product.price.formatted.price');
productPriceFormattedDiscountedPrice := CkJsonObject__stringOf(jResp,'product.price.formatted.discountedPrice');
productPriceDataCurrency := CkJsonObject__stringOf(jResp,'product.priceData.currency');
productPriceDataPrice := CkJsonObject__stringOf(jResp,'product.priceData.price');
productPriceDataDiscountedPrice := CkJsonObject__stringOf(jResp,'product.priceData.discountedPrice');
productPriceDataFormattedPrice := CkJsonObject__stringOf(jResp,'product.priceData.formatted.price');
productPriceDataFormattedDiscountedPrice := CkJsonObject__stringOf(jResp,'product.priceData.formatted.discountedPrice');
productManageVariants := CkJsonObject_BoolOf(jResp,'product.manageVariants');
productProductPageUrlBase := CkJsonObject__stringOf(jResp,'product.productPageUrl.base');
productProductPageUrlPath := CkJsonObject__stringOf(jResp,'product.productPageUrl.path');
productNumericId := CkJsonObject__stringOf(jResp,'product.numericId');
productInventoryItemId := CkJsonObject__stringOf(jResp,'product.inventoryItemId');
productDiscountType := CkJsonObject__stringOf(jResp,'product.discount.type');
productDiscountValue := CkJsonObject_IntOf(jResp,'product.discount.value');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'product.additionalInfoSections');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'product.ribbons');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'product.media.items');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'product.customTextFields');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'product.productOptions');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    optionType := CkJsonObject__stringOf(jResp,'product.productOptions[i].optionType');
    name := CkJsonObject__stringOf(jResp,'product.productOptions[i].name');
    j := 0;
    count_j := CkJsonObject_SizeOfArray(jResp,'product.productOptions[i].choices');
    while j < count_j do
      begin
        CkJsonObject_putJ(jResp,j);
        value := CkJsonObject__stringOf(jResp,'product.productOptions[i].choices[j].value');
        description := CkJsonObject__stringOf(jResp,'product.productOptions[i].choices[j].description');
        inStock := CkJsonObject_BoolOf(jResp,'product.productOptions[i].choices[j].inStock');
        visible := CkJsonObject_BoolOf(jResp,'product.productOptions[i].choices[j].visible');
        j := j + 1;
      end;

    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'product.collectionIds');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'product.variants');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    id := CkJsonObject__stringOf(jResp,'product.variants[i].id');
    choicesSize := CkJsonObject__stringOf(jResp,'product.variants[i].choices.Size');
    variantPriceDataCurrency := CkJsonObject__stringOf(jResp,'product.variants[i].variant.priceData.currency');
    variantPriceDataPrice := CkJsonObject__stringOf(jResp,'product.variants[i].variant.priceData.price');
    variantPriceDataDiscountedPrice := CkJsonObject__stringOf(jResp,'product.variants[i].variant.priceData.discountedPrice');
    variantPriceDataFormattedPrice := CkJsonObject__stringOf(jResp,'product.variants[i].variant.priceData.formatted.price');
    variantPriceDataFormattedDiscountedPrice := CkJsonObject__stringOf(jResp,'product.variants[i].variant.priceData.formatted.discountedPrice');
    variantWeight := CkJsonObject_IntOf(jResp,'product.variants[i].variant.weight');
    variantVisible := CkJsonObject_BoolOf(jResp,'product.variants[i].variant.visible');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkHttpResponse_Dispose(resp);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

end;