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

PureBasic Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Bitfinex v2 REST
Bluzone
BrickLink
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Mastercard

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

 

 

 

(PureBasic) 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 PureBasic Module Download

Chilkat PureBasic Module

IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; 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
    ;     }
    ;   ]
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"inventories[0].sku","vanilla-candle")
    CkJsonObject::ckUpdateInt(json,"inventories[0].current_quantity",24)
    CkJsonObject::ckUpdateBool(json,"inventories[0].discontinued",0)
    CkJsonObject::ckUpdateNull(json,"inventories[0].backordered_until")
    CkJsonObject::ckUpdateString(json,"inventories[1].sku","cinnamon-candle")
    CkJsonObject::ckUpdateInt(json,"inventories[1].current_quantity",0)
    CkJsonObject::ckUpdateBool(json,"inventories[1].discontinued",0)
    CkJsonObject::ckUpdateString(json,"inventories[1].backordered_until","20190314T000915.000Z")
    CkJsonObject::ckUpdateString(json,"inventories[2].sku","fall-candle")
    CkJsonObject::ckUpdateInt(json,"inventories[2].current_quantity",0)
    CkJsonObject::ckUpdateBool(json,"inventories[2].discontinued",1)
    CkJsonObject::ckUpdateNull(json,"inventories[2].backordered_until")
    CkJsonObject::ckUpdateString(json,"inventories[3].sku","fall-candle")
    CkJsonObject::ckUpdateNull(json,"inventories[3].current_quantity")
    CkJsonObject::ckUpdateBool(json,"inventories[3].discontinued",0)
    CkJsonObject::ckUpdateNull(json,"inventories[3].backordered_until")

    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
    CkHttp::ckSetRequestHeader(http,"X-FAIRE-ACCESS-TOKEN","<access_token>")

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckEmitSb(json,sbRequestBody)

    resp.i = CkHttp::ckPTextSb(http,"PATCH","https://www.faire.com/api/v1/products/options/inventory-levels",sbRequestBody,"utf-8","application/json",0,0)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

    ; 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

    id.s
    product_id.s
    active.i
    deleted.i
    name.s
    sku.s
    available_quantity.i
    created_at.s
    updated_at.s
    retail_price_cents.i
    wholesale_price_cents.i
    backordered_until.s
    j.i
    count_j.i
    value.s

    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"options")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        id = CkJsonObject::ckStringOf(jResp,"options[i].id")
        product_id = CkJsonObject::ckStringOf(jResp,"options[i].product_id")
        active = CkJsonObject::ckBoolOf(jResp,"options[i].active")
        deleted = CkJsonObject::ckBoolOf(jResp,"options[i].deleted")
        name = CkJsonObject::ckStringOf(jResp,"options[i].name")
        sku = CkJsonObject::ckStringOf(jResp,"options[i].sku")
        available_quantity = CkJsonObject::ckIntOf(jResp,"options[i].available_quantity")
        created_at = CkJsonObject::ckStringOf(jResp,"options[i].created_at")
        updated_at = CkJsonObject::ckStringOf(jResp,"options[i].updated_at")
        retail_price_cents = CkJsonObject::ckIntOf(jResp,"options[i].retail_price_cents")
        wholesale_price_cents = CkJsonObject::ckIntOf(jResp,"options[i].wholesale_price_cents")
        backordered_until = CkJsonObject::ckStringOf(jResp,"options[i].backordered_until")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"options[i].variations")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            name = CkJsonObject::ckStringOf(jResp,"options[i].variations[j].name")
            value = CkJsonObject::ckStringOf(jResp,"options[i].variations[j].value")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(sbRequestBody)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

 

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