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
(DataFlex) Akeneo: Create New ProductDemonstrates how to create a new product.
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Variant vJson Handle hoJson Boolean iSuccess String sUrl Variant vResp Handle hoResp String sLocation String sTemp1 Integer iTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End // Use your previously obtained access token. // See Get Akeneo Access Token Set ComAuthToken Of hoHttp To "access_token" // Build the following JSON to be sent in the request body: // Use this online tool to generate the code from sample JSON: // Generate Code to Create JSON // { // "identifier": "top", // "enabled": true, // "family": "tshirt", // "categories": [ // "summer_collection" // ], // "groups": [], // "parent": null, // "values": { // "name": [ // { // "data": "Top", // "locale": "en_US", // "scope": null // }, // { // "data": "D�bardeur", // "locale": "fr_FR", // "scope": null // } // ], // "description": [ // { // "data": "Summer top", // "locale": "en_US", // "scope": "ecommerce" // }, // { // "data": "Top", // "locale": "en_US", // "scope": "tablet" // }, // { // "data": "D�bardeur pour l'�t�", // "locale": "fr_FR", // "scope": "ecommerce" // }, // { // "data": "D�bardeur", // "locale": "fr_FR", // "scope": "tablet" // } // ], // "price": [ // { // "locale": null, // "scope": null, // "data": [ // { // "amount": "150.5", // "currency": "EUR" // }, // { // "amount": "150", // "currency": "USD" // } // ] // } // ], // "color": [ // { // "locale": null, // "scope": null, // "data": "black" // } // ], // "size": [ // { // "locale": null, // "scope": null, // "data": "m" // } // ] // }, // "associations": { // "PACK": { // "products": [ // "sunglass" // ], // "groups": [] // } // } // } // Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComUpdateString Of hoJson "identifier" "top" To iSuccess Get ComUpdateBool Of hoJson "enabled" True To iSuccess Get ComUpdateString Of hoJson "family" "tshirt" To iSuccess Get ComUpdateString Of hoJson "categories[0]" "summer_collection" To iSuccess Get ComUpdateNewArray Of hoJson "groups" To iSuccess Get ComUpdateNull Of hoJson "parent" To iSuccess Get ComUpdateString Of hoJson "values.name[0].data" "Top" To iSuccess Get ComUpdateString Of hoJson "values.name[0].locale" "en_US" To iSuccess Get ComUpdateNull Of hoJson "values.name[0].scope" To iSuccess Get ComUpdateString Of hoJson "values.name[1].data" "D�bardeur" To iSuccess Get ComUpdateString Of hoJson "values.name[1].locale" "fr_FR" To iSuccess Get ComUpdateNull Of hoJson "values.name[1].scope" To iSuccess Get ComUpdateString Of hoJson "values.description[0].data" "Summer top" To iSuccess Get ComUpdateString Of hoJson "values.description[0].locale" "en_US" To iSuccess Get ComUpdateString Of hoJson "values.description[0].scope" "ecommerce" To iSuccess Get ComUpdateString Of hoJson "values.description[1].data" "Top" To iSuccess Get ComUpdateString Of hoJson "values.description[1].locale" "en_US" To iSuccess Get ComUpdateString Of hoJson "values.description[1].scope" "tablet" To iSuccess Get ComUpdateString Of hoJson "values.description[2].data" "D�bardeur pour l'�t�" To iSuccess Get ComUpdateString Of hoJson "values.description[2].locale" "fr_FR" To iSuccess Get ComUpdateString Of hoJson "values.description[2].scope" "ecommerce" To iSuccess Get ComUpdateString Of hoJson "values.description[3].data" "D�bardeur" To iSuccess Get ComUpdateString Of hoJson "values.description[3].locale" "fr_FR" To iSuccess Get ComUpdateString Of hoJson "values.description[3].scope" "tablet" To iSuccess Get ComUpdateNull Of hoJson "values.price[0].locale" To iSuccess Get ComUpdateNull Of hoJson "values.price[0].scope" To iSuccess Get ComUpdateString Of hoJson "values.price[0].data[0].amount" "150.5" To iSuccess Get ComUpdateString Of hoJson "values.price[0].data[0].currency" "EUR" To iSuccess Get ComUpdateString Of hoJson "values.price[0].data[1].amount" "150" To iSuccess Get ComUpdateString Of hoJson "values.price[0].data[1].currency" "USD" To iSuccess Get ComUpdateNull Of hoJson "values.color[0].locale" To iSuccess Get ComUpdateNull Of hoJson "values.color[0].scope" To iSuccess Get ComUpdateString Of hoJson "values.color[0].data" "black" To iSuccess Get ComUpdateNull Of hoJson "values.size[0].locale" To iSuccess Get ComUpdateNull Of hoJson "values.size[0].scope" To iSuccess Get ComUpdateString Of hoJson "values.size[0].data" "m" To iSuccess Get ComUpdateString Of hoJson "associations.PACK.products[0]" "sunglass" To iSuccess Get ComUpdateNewArray Of hoJson "associations.PACK.groups" To iSuccess Set ComEmitCompact Of hoJson To False // Show the JSON to be sent.. Get ComEmit Of hoJson To sTemp1 Showln sTemp1 Move "http://pim.my-akeneo-site.com/api/rest/v1/products" To sUrl Get pvComObject of hoJson to vJson Get ComPostJson3 Of hoHttp sUrl "application/json" vJson To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get ComStatusCode Of hoResp To iTemp1 Showln "Response Status Code: " iTemp1 Showln "Response Body: " Get ComBodyStr Of hoResp To sTemp1 Showln sTemp1 // The akeneo response will include a "Location" header, such as the following: // HTTP/1.1 201 Created // Date: Tue, 22 Jan 2019 10:36:35 GMT // Server: Apache/2 // X-Powered-By: PHP/7.1.25 // Cache-Control: max-age=0, private, must-revalidate, no-cache, private // Set-Cookie: abcdefg; path=/; HttpOnly // Location: http://xyz.example.com/api/rest/v1/products/L0000123 // Vary: User-Agent // Content-Length: 0 // Keep-Alive: timeout=2, max=100 // Connection: Keep-Alive // Content-Type: application/json // Get the location header using resp.GetHeaderField Get ComGetHeaderField Of hoResp "Location" To sLocation Showln "Location: " sLocation Send Destroy of hoResp End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.