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
(Objective-C) WiX Create ProductCreates a new product. Note: If you get a 403 error response, try refreshing the access token. For more information, see https://dev.wix.com/api/rest/wix-stores/catalog/product/create-product
#import <CkoHttp.h> #import <CkoJsonObject.h> #import <CkoHttpResponse.h> #import <CkoStringBuilder.h> #import <NSString.h> // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkoHttp *http = [[CkoHttp alloc] init]; BOOL success; // 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" // } // ] // } // ] // } // } CkoJsonObject *json = [[CkoJsonObject alloc] init]; [json UpdateString: @"product.name" value: @"T-shirt"]; [json UpdateString: @"product.productType" value: @"physical"]; [json UpdateNumber: @"product.priceData.price" numericStr: @"10.5"]; [json UpdateString: @"product.description" value: @"nice summer t-shirt"]; [json UpdateString: @"product.sku" value: @"123df"]; [json UpdateBool: @"product.visible" value: NO]; [json UpdateNumber: @"product.weight" numericStr: @"0.2"]; [json UpdateString: @"product.discount.type" value: @"AMOUNT"]; [json UpdateInt: @"product.discount.value" value: [NSNumber numberWithInt: 1]]; [json UpdateBool: @"product.manageVariants" value: YES]; [json UpdateString: @"product.productOptions[0].name" value: @"Size"]; [json UpdateString: @"product.productOptions[0].choices[0].value" value: @"S"]; [json UpdateString: @"product.productOptions[0].choices[0].description" value: @"S"]; [json UpdateString: @"product.productOptions[0].choices[1].value" value: @"L"]; [json UpdateString: @"product.productOptions[0].choices[1].description" value: @"L"]; http.AuthToken = @"ACCESS_TOKEN"; [http SetRequestHeader: @"Content-Type" value: @"application/json"]; CkoHttpResponse *resp = [http PostJson3: @"https://www.wixapis.com/stores/v1/products" contentType: @"application/json" json: json]; if (http.LastMethodSuccess == NO) { NSLog(@"%@",http.LastErrorText); return; } CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init]; [resp GetBodySb: sbResponseBody]; CkoJsonObject *jResp = [[CkoJsonObject alloc] init]; [jResp LoadSb: sbResponseBody]; jResp.EmitCompact = NO; NSLog(@"%@",@"Response Body:"); NSLog(@"%@",[jResp Emit]); int respStatusCode = [resp.StatusCode intValue]; NSLog(@"%@%d",@"Response Status Code = ",respStatusCode); if (respStatusCode >= 400) { NSLog(@"%@",@"Response Header:"); NSLog(@"%@",resp.Header); NSLog(@"%@",@"Failed."); 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 NSString *optionType = 0; NSString *name = 0; int j; int count_j; NSString *value = 0; NSString *description = 0; BOOL inStock; BOOL visible; NSString *id = 0; NSString *choicesSize = 0; NSString *variantPriceDataCurrency = 0; NSString *variantPriceDataPrice = 0; NSString *variantPriceDataDiscountedPrice = 0; NSString *variantPriceDataFormattedPrice = 0; NSString *variantPriceDataFormattedDiscountedPrice = 0; int variantWeight; BOOL variantVisible; NSString *productId = [jResp StringOf: @"product.id"]; NSString *productName = [jResp StringOf: @"product.name"]; NSString *productSlug = [jResp StringOf: @"product.slug"]; BOOL productVisible = [jResp BoolOf: @"product.visible"]; NSString *productProductType = [jResp StringOf: @"product.productType"]; NSString *productDescription = [jResp StringOf: @"product.description"]; BOOL productStockTrackInventory = [jResp BoolOf: @"product.stock.trackInventory"]; BOOL productStockInStock = [jResp BoolOf: @"product.stock.inStock"]; NSString *productPriceCurrency = [jResp StringOf: @"product.price.currency"]; NSString *productPricePrice = [jResp StringOf: @"product.price.price"]; NSString *productPriceDiscountedPrice = [jResp StringOf: @"product.price.discountedPrice"]; NSString *productPriceFormattedPrice = [jResp StringOf: @"product.price.formatted.price"]; NSString *productPriceFormattedDiscountedPrice = [jResp StringOf: @"product.price.formatted.discountedPrice"]; NSString *productPriceDataCurrency = [jResp StringOf: @"product.priceData.currency"]; NSString *productPriceDataPrice = [jResp StringOf: @"product.priceData.price"]; NSString *productPriceDataDiscountedPrice = [jResp StringOf: @"product.priceData.discountedPrice"]; NSString *productPriceDataFormattedPrice = [jResp StringOf: @"product.priceData.formatted.price"]; NSString *productPriceDataFormattedDiscountedPrice = [jResp StringOf: @"product.priceData.formatted.discountedPrice"]; BOOL productManageVariants = [jResp BoolOf: @"product.manageVariants"]; NSString *productProductPageUrlBase = [jResp StringOf: @"product.productPageUrl.base"]; NSString *productProductPageUrlPath = [jResp StringOf: @"product.productPageUrl.path"]; NSString *productNumericId = [jResp StringOf: @"product.numericId"]; NSString *productInventoryItemId = [jResp StringOf: @"product.inventoryItemId"]; NSString *productDiscountType = [jResp StringOf: @"product.discount.type"]; int productDiscountValue = [[jResp IntOf: @"product.discount.value"] intValue]; int i = 0; int count_i = [[jResp SizeOfArray: @"product.additionalInfoSections"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"product.ribbons"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"product.media.items"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"product.customTextFields"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"product.productOptions"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: 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"] intValue]; while (j < count_j) { jResp.J = [NSNumber numberWithInt: 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"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"product.variants"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: 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"] intValue]; variantVisible = [jResp BoolOf: @"product.variants[i].variant.visible"]; i = i + 1; } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.