Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Walmart - Update bulk inventorySee Update bulk inventory for more information about this call.
IncludeFile "CkJsonObject.pb" IncludeFile "CkHttp.pb" IncludeFile "CkXml.pb" IncludeFile "CkAuthUtil.pb" IncludeFile "CkHttpRequest.pb" IncludeFile "CkHttpResponse.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ; Sends the following POST request: ; POST https://marketplace.walmartapis.com/v2/feeds?feedType=inventory success.i url.s = "https://marketplace.walmartapis.com/v2/feeds?feedType=inventory" requestMethod.s = "POST" ; 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,url,wmConsumerId,wmPrivateKey,requestMethod) If CkAuthUtil::ckLastMethodSuccess(authUtil) <> 1 Debug CkAuthUtil::ckLastErrorText(authUtil) CkAuthUtil::ckDispose(authUtil) ProcedureReturn EndIf ; Build the HTTP POST request. req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpRequest::setCkHttpVerb(req, "POST") CkHttpRequest::setCkContentType(req, "multipart/form-data") CkHttpRequest::setCkPath(req, "/v2/feeds?feedType=inventory") CkHttpRequest::ckAddHeader(req,"Accept","application/xml") ; 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) CkHttpRequest::ckAddHeader(req,"WM_SVC.NAME","Walmart Marketplace") CkHttpRequest::ckAddHeader(req,"WM_QOS.CORRELATION_ID",CkJsonObject::ckStringOf(json,"correlation_id")) CkHttpRequest::ckAddHeader(req,"WM_SEC.TIMESTAMP",CkJsonObject::ckStringOf(json,"timestamp")) CkHttpRequest::ckAddHeader(req,"WM_SEC.AUTH_SIGNATURE",CkJsonObject::ckStringOf(json,"signature")) CkHttpRequest::ckAddHeader(req,"WM_CONSUMER.ID",wmConsumerId) ; Note: Make sure to replace "WALMART_CHANNEL_TYPE" with the actual value for your seller account... CkHttpRequest::ckAddHeader(req,"WM_CONSUMER.CHANNEL.TYPE","WALMART_CHANNEL_TYPE") ; The body of the POST will contain XML. In this example, we'll load the XML ; from a file. The XML contains inventory data that looks something like this: ; <InventoryFeed xmlns="http://walmart.com/"> ; <InventoryHeader> ; <version>1.4</version> ; </InventoryHeader> ; <inventory> ; <sku>1068155</sku> ; <quantity> ; <unit>EACH</unit> ; <amount>10</amount> ; </quantity> ; <fulfillmentLagTime>1</fulfillmentLagTime> ; </inventory> ; <inventory> ; <sku>10210321</sku> ; <quantity> ; <unit>EACH</unit> ; <amount>20</amount> ; </quantity> ; <fulfillmentLagTime>3</fulfillmentLagTime> ; </inventory> ; </InventoryFeed> success = CkHttpRequest::ckAddFileForUpload2(req,"inventory","qa_data/walmart/inventory.xml","application/xml") If success <> 1 Debug CkHttpRequest::ckLastErrorText(req) CkAuthUtil::ckDispose(authUtil) CkHttpRequest::ckDispose(req) CkJsonObject::ckDispose(json) ProcedureReturn EndIf http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf resp.i = CkHttp::ckSynchronousRequest(http,"marketplace.walmartapis.com",443,1,req) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkAuthUtil::ckDispose(authUtil) CkHttpRequest::ckDispose(req) 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,CkHttpResponse::ckBodyStr(resp)) ; A successful response should have a 200 response status If CkHttpResponse::ckStatusCode(resp) <> 200 Debug CkXml::ckGetXml(xml) Debug "Response Status Code: " + Str(CkHttpResponse::ckStatusCode(resp)) Debug "Failed." CkHttpResponse::ckDispose(resp) CkAuthUtil::ckDispose(authUtil) CkHttpRequest::ckDispose(req) CkJsonObject::ckDispose(json) CkHttp::ckDispose(http) CkXml::ckDispose(xml) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; Show the XML response.. Debug CkXml::ckGetXml(xml) Debug "--" Debug "Success!" CkAuthUtil::ckDispose(authUtil) CkHttpRequest::ckDispose(req) CkJsonObject::ckDispose(json) CkHttp::ckDispose(http) CkXml::ckDispose(xml) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.