Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) Akeneo: Create New Product

Demonstrates how to create a new product.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Variant vJson
    Handle hoJson
    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": "Dbardeur",
    //         "locale": "fr_FR",
    //         "scope": null
    //       }
    //     ],
    //     "description": [
    //       {
    //         "data": "Summer top",
    //         "locale": "en_US",
    //         "scope": "ecommerce"
    //       },
    //       {
    //         "data": "Top",
    //         "locale": "en_US",
    //         "scope": "tablet"
    //       },
    //       {
    //         "data": "Dbardeur pour l't",
    //         "locale": "fr_FR",
    //         "scope": "ecommerce"
    //       },
    //       {
    //         "data": "Dbardeur",
    //         "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" "Dbardeur" 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" "Dbardeur 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" "Dbardeur" 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-2019 Chilkat Software, Inc. All Rights Reserved.