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 Web API Examples

Primary Categories

AWS Translate
Azure OAuth2
Azure Storage Accounts
CardConnect
Cloudfare
Facebook
GeoOp
Jira
Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans

PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Walmart
Xero
eBay
effectconnect

 

 

 

(PureBasic) Walmart - Get a FeedItem's Status

Demonstrates how to get a Walmart feedItem's status.

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/feeds/feeditems/{feedId}?includeDetails={includeDetails}&limit={limit}

    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/feeds/feeditems/{feedId}?includeDetails={includeDetails}&limit={limit}")
    numReplaced.i = CkStringBuilder::ckReplace(sbUrl,"{feedId}","AAAA7F0345E9403C91223F7139FFC341@AQsBAQA")
    numReplaced = CkStringBuilder::ckReplace(sbUrl,"{includeDetails}","true")
    numReplaced = CkStringBuilder::ckReplaceI(sbUrl,"{limit}",3)

    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 iterate over the ingestion statuses:
    numIngestionStatuses.i = CkXml::ckNumChildrenAt(xml,"ns2:elements|ns2:itemDetails")
    i.i = 0
    While i < numIngestionStatuses
        CkXml::setCkI(xml, i)

        Debug "sku: " + CkXml::ckGetChildContent(xml,"ns2:elements|ns2:itemDetails|ns2:itemIngestionStatus[i]|ns2:sku")
        Debug "status: " + CkXml::ckGetChildContent(xml,"ns2:elements|ns2:itemDetails|ns2:itemIngestionStatus[i]|ns2:ingestionStatus")
        Debug "--"

        i = i + 1
    Wend

    Debug "Success."

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

    ; <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    ; <ns2:ItemStatusDetail xmlns:ns2="http://walmart.com/">
    ;     <ns2:meta>
    ;         <ns2:feedId>AAAAF0345E9403C91223F7139FFC341@AQsBAQA</ns2:feedId>
    ;         <ns2:feedStatus>PROCESSED</ns2:feedStatus>
    ;         <ns2:ingestionErrors />
    ;         <ns2:itemsReceived>130088</ns2:itemsReceived>
    ;         <ns2:itemsSucceeded>113154</ns2:itemsSucceeded>
    ;         <ns2:itemsFailed>16934</ns2:itemsFailed>
    ;         <ns2:itemsProcessing>0</ns2:itemsProcessing>
    ;         <ns2:limit>3</ns2:limit>
    ;         <ns2:totalCount>3</ns2:totalCount>
    ;         <ns2:nextCursor>includeDetails=true&amp;limit=3&amp;skuOffset=ENC%28%2F8D%2FyDen1ByXGA7EsWkArA%3D%3D%29</ns2:nextCursor>
    ;     </ns2:meta>
    ;     <ns2:elements>
    ;         <ns2:itemDetails>
    ;             <ns2:itemIngestionStatus>
    ;                 <ns2:martId>0</ns2:martId>
    ;                 <ns2:sku>0000~0~00141</ns2:sku>
    ;                 <ns2:index>0</ns2:index>
    ;                 <ns2:ingestionStatus>DATA_ERROR</ns2:ingestionStatus>
    ;                 <ns2:ingestionErrors>
    ;                     <ns2:ingestionError>
    ;                         <ns2:type>DATA_ERROR</ns2:type>
    ;                         <ns2:code>PIVI_021</ns2:code>
    ;                         <ns2:description>No item found with the given SKU.</ns2:description>
    ;                     </ns2:ingestionError>
    ;                 </ns2:ingestionErrors>
    ;             </ns2:itemIngestionStatus>
    ;             <ns2:itemIngestionStatus>
    ;                 <ns2:martId>0</ns2:martId>
    ;                 <ns2:sku>0000~0~03472</ns2:sku>
    ;                 <ns2:index>1</ns2:index>
    ;                 <ns2:ingestionStatus>SUCCESS</ns2:ingestionStatus>
    ;                 <ns2:ingestionErrors />
    ;             </ns2:itemIngestionStatus>
    ;             <ns2:itemIngestionStatus>
    ;                 <ns2:martId>0</ns2:martId>
    ;                 <ns2:sku>0000~0~08540</ns2:sku>
    ;                 <ns2:index>2</ns2:index>
    ;                 <ns2:ingestionStatus>SUCCESS</ns2:ingestionStatus>
    ;                 <ns2:ingestionErrors />
    ;             </ns2:itemIngestionStatus>
    ;         </ns2:itemDetails>
    ;     </ns2:elements>
    ; </ns2:ItemStatusDetail>


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


    ProcedureReturn
EndProcedure

 

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