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

PureBasic Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
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)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(PureBasic) Walmart - Get Inventory for an Item

Demonstrates how to get inventory for an item and parse the result.

Note: This example requires Chilkat v9.5.0.67 or greater.

Chilkat PureBasic Module Download

Chilkat PureBasic Module

IncludeFile "CkXml.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkAuthUtil.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

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

    ;  Sends the following GET request:
    ;  GET https://marketplace.walmartapis.com/v2/inventory?sku={SKU}

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

    success.i = CkStringBuilder::ckAppend(sbUrl,"https://marketplace.walmartapis.com/v2/inventory?sku={SKU}")
    numReplaced.i = CkStringBuilder::ckReplace(sbUrl,"{SKU}","HOPP~904~51041")

    requestMethod.s = "GET"

    ;  First we need to generate a signature for our request.
    ;  The signature needs to be re-generated for each new Walmart HTTP request.
    authUtil.i = CkAuthUtil::ckCreate()
    If authUtil.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    wmConsumerId.s = "WALMART_CONSUMER_ID"
    wmPrivateKey.s = "WALMART_PRIVATE_KEY"
    jsonStr.s = CkAuthUtil::ckWalmartSignature(authUtil,CkStringBuilder::ckGetAsString(sbUrl),wmConsumerId,wmPrivateKey,requestMethod)
    If CkAuthUtil::ckLastMethodSuccess(authUtil) <> 1
        Debug CkAuthUtil::ckLastErrorText(authUtil)
        CkStringBuilder::ckDispose(sbUrl)
        CkAuthUtil::ckDispose(authUtil)
        ProcedureReturn
    EndIf

    ;  The JSON returned by WalmartSignature contains the values to be used in the following
    ;  header fields: WM_SEC.AUTH_SIGNATURE, WM_SEC.TIMESTAMP, and WM_QOS.CORRELATION_ID
    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoad(json,jsonStr)

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

    CkHttp::ckSetRequestHeader(http,"WM_SVC.NAME","Walmart Marketplace")
    CkHttp::ckSetRequestHeader(http,"WM_QOS.CORRELATION_ID",CkJsonObject::ckStringOf(json,"correlation_id"))
    CkHttp::ckSetRequestHeader(http,"WM_SEC.TIMESTAMP",CkJsonObject::ckStringOf(json,"timestamp"))
    CkHttp::ckSetRequestHeader(http,"WM_SEC.AUTH_SIGNATURE",CkJsonObject::ckStringOf(json,"signature"))
    CkHttp::ckSetRequestHeader(http,"WM_CONSUMER.ID",wmConsumerId)
    CkHttp::setCkAccept(http, "application/xml")

    ;  Note: Do not explicitly set the "Host" header.  Chilkat will set it automatically.

    xmlStr.s = CkHttp::ckQuickGetStr(http,CkStringBuilder::ckGetAsString(sbUrl))
    If CkHttp::ckLastMethodSuccess(http) <> 1
        Debug CkHttp::ckLastErrorText(http)
        CkStringBuilder::ckDispose(sbUrl)
        CkAuthUtil::ckDispose(authUtil)
        CkJsonObject::ckDispose(json)
        CkHttp::ckDispose(http)
        ProcedureReturn
    EndIf

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

    CkXml::ckLoadXml(xml,xmlStr)

    ;  A successful response should have a 200 response status
    If CkHttp::ckLastStatus(http) <> 200
        Debug CkXml::ckGetXml(xml)
        Debug "Response Status Code: " + Str(CkHttp::ckLastStatus(http))
        Debug "Failed."
        CkStringBuilder::ckDispose(sbUrl)
        CkAuthUtil::ckDispose(authUtil)
        CkJsonObject::ckDispose(json)
        CkHttp::ckDispose(http)
        CkXml::ckDispose(xml)
        ProcedureReturn
    EndIf

    ;  A sample XML response is shown below..
    Debug CkXml::ckGetXml(xml)
    Debug "--"

    ;  To get the quantity:
    quantity.i = CkXml::ckGetChildIntValue(xml,"quantity|amount")
    Debug "quantity = " + Str(quantity)

    ;  ---------------------------------------
    ;  Sample XML response
    ;  ---------------------------------------

    ;  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    ;  <inventory xmlns="http://walmart.com/">
    ;      <sku>HOPP~904~51041</sku>
    ;      <quantity>
    ;          <unit>EACH</unit>
    ;          <amount>234</amount>
    ;      </quantity>
    ;      <fulfillmentLagTime>5</fulfillmentLagTime>
    ;  </inventory>


    CkStringBuilder::ckDispose(sbUrl)
    CkAuthUtil::ckDispose(authUtil)
    CkJsonObject::ckDispose(json)
    CkHttp::ckDispose(http)
    CkXml::ckDispose(xml)


    ProcedureReturn
EndProcedure

 

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