Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(DataFlex) Faire - Update Inventory Levels

See more Faire Examples

Update the inventory levels for multiple product options in one request.

For more information, see https://faire.github.io/external-api-docs/#update-inventory-levels

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sId
    String sProduct_id
    Boolean iActive
    Boolean iDeleted
    String sName
    String sSku
    Integer iAvailable_quantity
    String sCreated_at
    String sUpdated_at
    Integer iRetail_price_cents
    Integer iWholesale_price_cents
    String sBackordered_until
    Integer j
    Integer iCount_j
    String sValue
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

    // This example assumes 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

    // Implements the following CURL command:

    // curl -X PATCH 
    //     -H "Content-Type: application/json" 
    //     -H "X-FAIRE-ACCESS-TOKEN: <access_token>"
    //     -d '{
    //   "inventories": [
    //     {
    //       "sku": "vanilla-candle",
    //       "current_quantity": 24,
    //       "discontinued": false,
    //       "backordered_until": null
    //     },
    //     {
    //       "sku": "cinnamon-candle",
    //       "current_quantity": 0,
    //       "discontinued": false,
    //       "backordered_until": "20190314T000915.000Z"
    //     },
    //     {
    //       "sku": "fall-candle",
    //       "current_quantity": 0,
    //       "discontinued": true,
    //       "backordered_until": null
    //     },
    //     {
    //       "sku": "fall-candle",
    //       "current_quantity": null,
    //       "discontinued": false,
    //       "backordered_until": null
    //     }
    //   ]
    // }' https://www.faire.com/api/v1/products/options/inventory-levels

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

    // {
    //   "inventories": [
    //     {
    //       "sku": "vanilla-candle",
    //       "current_quantity": 24,
    //       "discontinued": false,
    //       "backordered_until": null
    //     },
    //     {
    //       "sku": "cinnamon-candle",
    //       "current_quantity": 0,
    //       "discontinued": false,
    //       "backordered_until": "20190314T000915.000Z"
    //     },
    //     {
    //       "sku": "fall-candle",
    //       "current_quantity": 0,
    //       "discontinued": true,
    //       "backordered_until": null
    //     },
    //     {
    //       "sku": "fall-candle",
    //       "current_quantity": null,
    //       "discontinued": false,
    //       "backordered_until": null
    //     }
    //   ]
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "inventories[0].sku" "vanilla-candle" To iSuccess
    Get ComUpdateInt Of hoJson "inventories[0].current_quantity" 24 To iSuccess
    Get ComUpdateBool Of hoJson "inventories[0].discontinued" False To iSuccess
    Get ComUpdateNull Of hoJson "inventories[0].backordered_until" To iSuccess
    Get ComUpdateString Of hoJson "inventories[1].sku" "cinnamon-candle" To iSuccess
    Get ComUpdateInt Of hoJson "inventories[1].current_quantity" 0 To iSuccess
    Get ComUpdateBool Of hoJson "inventories[1].discontinued" False To iSuccess
    Get ComUpdateString Of hoJson "inventories[1].backordered_until" "20190314T000915.000Z" To iSuccess
    Get ComUpdateString Of hoJson "inventories[2].sku" "fall-candle" To iSuccess
    Get ComUpdateInt Of hoJson "inventories[2].current_quantity" 0 To iSuccess
    Get ComUpdateBool Of hoJson "inventories[2].discontinued" True To iSuccess
    Get ComUpdateNull Of hoJson "inventories[2].backordered_until" To iSuccess
    Get ComUpdateString Of hoJson "inventories[3].sku" "fall-candle" To iSuccess
    Get ComUpdateNull Of hoJson "inventories[3].current_quantity" To iSuccess
    Get ComUpdateBool Of hoJson "inventories[3].discontinued" False To iSuccess
    Get ComUpdateNull Of hoJson "inventories[3].backordered_until" To iSuccess

    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
    Send ComSetRequestHeader To hoHttp "X-FAIRE-ACCESS-TOKEN" "<access_token>"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess

    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComPTextSb Of hoHttp "PATCH" "https://www.faire.com/api/v1/products/options/inventory-levels" vSbRequestBody "utf-8" "application/json" False False 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 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "options": [
    //     {
    //       "id": "po_012",
    //       "product_id": "p_ghi",
    //       "active": false,
    //       "deleted": false,
    //       "name": "Fall Scent",
    //       "sku": "fall-candle",
    //       "available_quantity": 0,
    //       "created_at": "20190313T000915.000Z",
    //       "updated_at": "20190315T000915.000Z",
    //       "variations": [
    //         {
    //           "name": "Scent",
    //           "value": "Fall"
    //         }
    //       ],
    //       "retail_price_cents": 599,
    //       "wholesale_price_cents": 300
    //     },
    //     {
    //       "id": "po_789",
    //       "product_id": "p_def",
    //       "active": false,
    //       "deleted": false,
    //       "name": "Cinnamon Scent",
    //       "sku": "cinnamon-candle",
    //       "available_quantity": 0,
    //       "created_at": "20190312T000915.000Z",
    //       "updated_at": "20190315T000915.000Z",
    //       "backordered_until": "20190314T000915.000Z",
    //       "variations": [
    //         {
    //           "name": "Scent",
    //           "value": "Cinnamon"
    //         }
    //       ],
    //       "retail_price_cents": 599,
    //       "wholesale_price_cents": 300
    //     },
    //     {
    //       "id": "po_456",
    //       "product_id": "p_abc",
    //       "active": true,
    //       "deleted": false,
    //       "name": "Vanilla Scent",
    //       "sku": "vanilla-candle",
    //       "available_quantity": 24,
    //       "created_at": "20190314T000915.000Z",
    //       "updated_at": "20190315T000915.000Z",
    //       "variations": [
    //         {
    //           "name": "Scent",
    //           "value": "Vanilla"
    //         }
    //       ],
    //       "retail_price_cents": 599,
    //       "wholesale_price_cents": 300
    //     }
    //   ]
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "options" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "options[i].id" To sId
        Get ComStringOf Of hoJResp "options[i].product_id" To sProduct_id
        Get ComBoolOf Of hoJResp "options[i].active" To iActive
        Get ComBoolOf Of hoJResp "options[i].deleted" To iDeleted
        Get ComStringOf Of hoJResp "options[i].name" To sName
        Get ComStringOf Of hoJResp "options[i].sku" To sSku
        Get ComIntOf Of hoJResp "options[i].available_quantity" To iAvailable_quantity
        Get ComStringOf Of hoJResp "options[i].created_at" To sCreated_at
        Get ComStringOf Of hoJResp "options[i].updated_at" To sUpdated_at
        Get ComIntOf Of hoJResp "options[i].retail_price_cents" To iRetail_price_cents
        Get ComIntOf Of hoJResp "options[i].wholesale_price_cents" To iWholesale_price_cents
        Get ComStringOf Of hoJResp "options[i].backordered_until" To sBackordered_until
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "options[i].variations" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "options[i].variations[j].name" To sName
            Get ComStringOf Of hoJResp "options[i].variations[j].value" To sValue
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop



End_Procedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.