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

Objective-C 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
Jira
Lightspeed
MYOB
Magento
Mailgun

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
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
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

 

 

 

(Objective-C) Walmart - Get List of Orders

Demonstrates how to get a list of all orders.

Chilkat Objective-C Library Downloads

MAC OS X (Cocoa) Libs

iOS Libs

#import <CkoStringBuilder.h>
#import <CkoDateTime.h>
#import <NSString.h>
#import <CkoAuthUtil.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoXml.h>

// ---------------------------------------------------------------------------------------------------------
// Note: This example is deprecated.  The Walmart API no longer uses the Signature method of authenticating.
// Walmart now uses OAuth2.  
// ---------------------------------------------------------------------------------------------------------

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

// Demonstrates how to get a list of Walmart orders and parse the XML result.

// ---
// Note: The Walmart documentation indicates that the createdStartDate/createdEndDate query parameters are optional,
// however, this may not actually be the case.  It may be that at least one is required for getting a list of orders.
// ---

// The general format to get orders is as follows:
// GET https://marketplace.walmartapis.com/v3/orders?sku={sku}&customerOrderId={customerOrderId}&purchaseOrderId={purchaseOrderId}&status={status}&createdStartDate={createdStartDate}&createdEndDate={createdEndDate}&fromExpectedShipDate={fromExpectedShipDate}&toExpectedShipDate={toExpectedShipDate}&limit={limit} 

// Let's build a request to get all the orders in the last 7 days.
CkoStringBuilder *sbUrl = [[CkoStringBuilder alloc] init];
BOOL success = [sbUrl Append: @"https://marketplace.walmartapis.com/v3/orders?createdStartDate={createdStartDate}&limit={limit}"];
// We'll just get 2 results so we can demonstrate iterating over the XML..
int numReplaced = [[sbUrl ReplaceI: @"{limit}" replacement: [NSNumber numberWithInt: 2]] intValue];

// Get the current system date/time and add -7 days to get 1 week ago.
CkoDateTime *dtStartDate = [[CkoDateTime alloc] init];
[dtStartDate SetFromCurrentSystemTime];
[dtStartDate AddDays: [NSNumber numberWithInt: -7]];
NSLog(@"%@%@",@"One week ago (GMT): ",[dtStartDate GetAsTimestamp: NO]);

numReplaced = [[sbUrl Replace: @"{createdStartDate}" replacement: [dtStartDate GetAsTimestamp: NO]] intValue];

NSString *requestMethod = @"GET";

// First we need to generate a signature for our request.
// The signature needs to be re-generated for each new Walmart HTTP request.
CkoAuthUtil *authUtil = [[CkoAuthUtil alloc] init];

NSString *wmConsumerId = @"WALMART_CONSUMER_ID";
NSString *wmPrivateKey = @"WALMART_PRIVATE_KEY";
NSString *jsonStr = [authUtil WalmartSignature: [sbUrl GetAsString] consumerId: wmConsumerId privateKey: wmPrivateKey requestMethod: requestMethod];
if (authUtil.LastMethodSuccess != YES) {
    NSLog(@"%@",authUtil.LastErrorText);
    return;
}

// 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
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json Load: jsonStr];

CkoHttp *http = [[CkoHttp alloc] init];
[http SetRequestHeader: @"WM_SVC.NAME" value: @"Walmart Marketplace"];
[http SetRequestHeader: @"WM_QOS.CORRELATION_ID" value: [json StringOf: @"correlation_id"]];
[http SetRequestHeader: @"WM_SEC.TIMESTAMP" value: [json StringOf: @"timestamp"]];
[http SetRequestHeader: @"WM_SEC.AUTH_SIGNATURE" value: [json StringOf: @"signature"]];
[http SetRequestHeader: @"WM_CONSUMER.ID" value: wmConsumerId];
// Note: check to see what keyword you should use for your situation.
// The keyword "WALMART_CHANNEL_TYPE" is one option.  Another is "SWAGGER_CHANNEL_TYPE".
[http SetRequestHeader: @"WM_CONSUMER.CHANNEL.TYPE" value: @"WALMART_CHANNEL_TYPE"];

http.Accept = @"application/xml";

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

NSString *xmlStr = [http QuickGetStr: [sbUrl GetAsString]];
if (http.LastMethodSuccess != YES) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoXml *xml = [[CkoXml alloc] init];
[xml LoadXml: xmlStr];

// A successful response should have a 200 response status
if ([http.LastStatus intValue] != 200) {
    NSLog(@"%@",[xml GetXml]);
    NSLog(@"%@%d",@"Response Status Code: ",[http.LastStatus intValue]);
    NSLog(@"%@",@"Failed.");
    return;
}

// A sample XML response is shown below..

// Let's grab some information, and iterate over the XML..
NSLog(@"%@%d",@"Total number of orders in last 7 days: ",[[xml GetChildIntValue: @"ns3:meta|ns3:totalCount"] intValue]);

// The outermost loop loops over the orders.  
// The next inner loop loops over the order lines.
// The innermost loop loops over the order line statuses.
int i = 0;
int numOrders = [[xml NumChildrenAt: @"ns3:elements"] intValue];
while (i < numOrders) {
    xml.I = [NSNumber numberWithInt: i];
    NSLog(@"%@%d%@",@"---- order ",i + 1,@" ----");

    CkoXml *order = [xml GetChildWithTag: @"ns3:elements|ns3:order[i]"];
    NSLog(@"%@%@",@"purchaseOrderId: ",[order GetChildContent: @"ns3:purchaseOrderId"]);
    NSLog(@"%@%@",@"name: ",[order GetChildContent: @"ns3:shippingInfo|ns3:postalAddress|ns3:name"]);

    int j = 0;
    int numOrderLines = [[order NumChildrenAt: @"ns3:orderLines"] intValue];
    while (j < numOrderLines) {
        order.J = [NSNumber numberWithInt: j];
        CkoXml *orderLine = [order GetChildWithTag: @"ns3:orderLines|ns3:orderLine[j]"];
        NSLog(@"%@%@",@"  productName: ",[orderLine GetChildContent: @"ns3:item|ns3:productName"]);

        int k = 0;
        int numOrderLineStatuses = [[orderLine NumChildrenAt: @"ns3:orderLineStatuses"] intValue];
        while (k < numOrderLineStatuses) {
            orderLine.K = [NSNumber numberWithInt: k];
            NSLog(@"%@%@",@"    order line status: ",[orderLine GetChildContent: @"ns3:orderLineStatuses|ns3:orderLineStatus[k]|ns3:status"]);
            NSLog(@"%@%@",@"    order line carrier: ",[orderLine GetChildContent: @"ns3:orderLineStatuses|ns3:orderLineStatus[k]|ns3:trackingInfo|ns3:carrierName|ns3:carrier"]);
            k = k + 1;
        }

        j = j + 1;
    }

    i = i + 1;
}

NSLog(@"%@",@"Success.");

// ---------------------------------------
// Sample XML response
// (The confidential information has been redacted or modified with fake data.
// ---------------------------------------

// <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
// <ns3:list xmlns:ns2="http://walmart.com/mp/orders" xmlns:ns3="http://walmart.com/mp/v3/orders" xmlns:ns4="http://walmart.com/">
//     <ns3:meta>
//         <ns3:totalCount>239</ns3:totalCount>
//         <ns3:limit>2</ns3:limit>
//         <ns3:nextCursor>?limit=2&amp;hasMoreElements=true&amp;soIndex=239&amp;poIndex=1578652999055&amp;partnerId=10000999999&amp;sellerId=9999&amp;createdStartDate=2017-04-21T19:08:55Z&amp;createdEndDate=2017-04-28T19:08:58.464Z</ns3:nextCursor>
//     </ns3:meta>
//     <ns3:elements>
//         <ns3:order>
//             <ns3:purchaseOrderId>1111641944111</ns3:purchaseOrderId>
//             <ns3:customerOrderId>1111777852111</ns3:customerOrderId>
//             <ns3:customerEmailId>somebody@somewhere.com</ns3:customerEmailId>
//             <ns3:orderDate>2017-04-21T01:25:52.000Z</ns3:orderDate>
//             <ns3:shippingInfo>
//                 <ns3:phone>3175555555</ns3:phone>
//                 <ns3:estimatedDeliveryDate>2017-05-10T06:00:00.000Z</ns3:estimatedDeliveryDate>
//                 <ns3:estimatedShipDate>2017-04-29T06:00:00.000Z</ns3:estimatedShipDate>
//                 <ns3:methodCode>Value</ns3:methodCode>
//                 <ns3:postalAddress>
//                     <ns3:name>barry redacted</ns3:name>
//                     <ns3:address1>9999 redacted dr</ns3:address1>
//                     <ns3:city>Indianapolis</ns3:city>
//                     <ns3:state>IN</ns3:state>
//                     <ns3:postalCode>46227</ns3:postalCode>
//                     <ns3:country>USA</ns3:country>
//                     <ns3:addressType>RESIDENTIAL</ns3:addressType>
//                 </ns3:postalAddress>
//             </ns3:shippingInfo>
//             <ns3:orderLines>
//                 <ns3:orderLine>
//                     <ns3:lineNumber>1</ns3:lineNumber>
//                     <ns3:item>
//                         <ns3:productName>DPX DPx HEST 2.0 Mil-Spec Fixed Blade G10 Multi-Colored</ns3:productName>
//                         <ns3:sku>DPXG~DPHSX008~00317</ns3:sku>
//                     </ns3:item>
//                     <ns3:charges>
//                         <ns3:charge>
//                             <ns3:chargeType>PRODUCT</ns3:chargeType>
//                             <ns3:chargeName>ItemPrice</ns3:chargeName>
//                             <ns3:chargeAmount>
//                                 <ns3:currency>USD</ns3:currency>
//                                 <ns3:amount>125.00</ns3:amount>
//                             </ns3:chargeAmount>
//                         </ns3:charge>
//                     </ns3:charges>
//                     <ns3:orderLineQuantity>
//                         <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement>
//                         <ns3:amount>1</ns3:amount>
//                     </ns3:orderLineQuantity>
//                     <ns3:statusDate>2017-04-28T18:09:26.000Z</ns3:statusDate>
//                     <ns3:orderLineStatuses>
//                         <ns3:orderLineStatus>
//                             <ns3:status>Shipped</ns3:status>
//                             <ns3:statusQuantity>
//                                 <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement>
//                                 <ns3:amount>1</ns3:amount>
//                             </ns3:statusQuantity>
//                             <ns3:trackingInfo>
//                                 <ns3:shipDateTime>2017-04-24T20:57:52.000Z</ns3:shipDateTime>
//                                 <ns3:carrierName>
//                                     <ns3:carrier>USPS</ns3:carrier>
//                                 </ns3:carrierName>
//                                 <ns3:methodCode>Value</ns3:methodCode>
//                                 <ns3:trackingNumber>redacted</ns3:trackingNumber>
//                                 <ns3:trackingURL>http://walmart.narvar.com/walmart/tracking/usps?redacted</ns3:trackingURL>
//                             </ns3:trackingInfo>
//                         </ns3:orderLineStatus>
//                     </ns3:orderLineStatuses>
//                 </ns3:orderLine>
//             </ns3:orderLines>
//         </ns3:order>
//         <ns3:order>
//             <ns3:purchaseOrderId>1111652066111</ns3:purchaseOrderId>
//             <ns3:customerOrderId>1111778837111</ns3:customerOrderId>
//             <ns3:customerEmailId>somebody2@somewhere.com</ns3:customerEmailId>
//             <ns3:orderDate>2017-04-22T13:37:12.000Z</ns3:orderDate>
//             <ns3:shippingInfo>
//                 <ns3:phone>8435555555</ns3:phone>
//                 <ns3:estimatedDeliveryDate>2017-05-11T06:00:00.000Z</ns3:estimatedDeliveryDate>
//                 <ns3:estimatedShipDate>2017-05-02T06:00:00.000Z</ns3:estimatedShipDate>
//                 <ns3:methodCode>Value</ns3:methodCode>
//                 <ns3:postalAddress>
//                     <ns3:name>Doug Redacted</ns3:name>
//                     <ns3:address1>1111 redacted dr</ns3:address1>
//                     <ns3:city>Columbia</ns3:city>
//                     <ns3:state>SC</ns3:state>
//                     <ns3:postalCode>29527</ns3:postalCode>
//                     <ns3:country>USA</ns3:country>
//                     <ns3:addressType>RESIDENTIAL</ns3:addressType>
//                 </ns3:postalAddress>
//             </ns3:shippingInfo>
//             <ns3:orderLines>
//                 <ns3:orderLine>
//                     <ns3:lineNumber>1</ns3:lineNumber>
//                     <ns3:item>
//                         <ns3:productName>Rayovac Specialty Battery 123A 2PK, RL123A-2D</ns3:productName>
//                         <ns3:sku>RAYO~RL123A-2A~46270</ns3:sku>
//                     </ns3:item>
//                     <ns3:charges>
//                         <ns3:charge>
//                             <ns3:chargeType>PRODUCT</ns3:chargeType>
//                             <ns3:chargeName>ItemPrice</ns3:chargeName>
//                             <ns3:chargeAmount>
//                                 <ns3:currency>USD</ns3:currency>
//                                 <ns3:amount>12.92</ns3:amount>
//                             </ns3:chargeAmount>
//                         </ns3:charge>
//                     </ns3:charges>
//                     <ns3:orderLineQuantity>
//                         <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement>
//                         <ns3:amount>1</ns3:amount>
//                     </ns3:orderLineQuantity>
//                     <ns3:statusDate>2017-04-28T17:18:51.000Z</ns3:statusDate>
//                     <ns3:orderLineStatuses>
//                         <ns3:orderLineStatus>
//                             <ns3:status>Shipped</ns3:status>
//                             <ns3:statusQuantity>
//                                 <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement>
//                                 <ns3:amount>1</ns3:amount>
//                             </ns3:statusQuantity>
//                             <ns3:trackingInfo>
//                                 <ns3:shipDateTime>2017-04-28T16:50:53.000Z</ns3:shipDateTime>
//                                 <ns3:carrierName>
//                                     <ns3:carrier>USPS</ns3:carrier>
//                                 </ns3:carrierName>
//                                 <ns3:methodCode>Value</ns3:methodCode>
//                                 <ns3:trackingNumber>redacted</ns3:trackingNumber>
//                                 <ns3:trackingURL>http://walmart.narvar.com/walmart/tracking/usps?redacted</ns3:trackingURL>
//                             </ns3:trackingInfo>
//                         </ns3:orderLineStatus>
//                     </ns3:orderLineStatuses>
//                 </ns3:orderLine>
//                 <ns3:orderLine>
//                     <ns3:lineNumber>2</ns3:lineNumber>
//                     <ns3:item>
//                         <ns3:productName>Rayovac Specialty Battery 123A 2PK, RL123A-2D</ns3:productName>
//                         <ns3:sku>RAYO~RL123A-2A~46270</ns3:sku>
//                     </ns3:item>
//                     <ns3:charges>
//                         <ns3:charge>
//                             <ns3:chargeType>PRODUCT</ns3:chargeType>
//                             <ns3:chargeName>ItemPrice</ns3:chargeName>
//                             <ns3:chargeAmount>
//                                 <ns3:currency>USD</ns3:currency>
//                                 <ns3:amount>12.92</ns3:amount>
//                             </ns3:chargeAmount>
//                         </ns3:charge>
//                     </ns3:charges>
//                     <ns3:orderLineQuantity>
//                         <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement>
//                         <ns3:amount>1</ns3:amount>
//                     </ns3:orderLineQuantity>
//                     <ns3:statusDate>2017-04-28T17:18:51.000Z</ns3:statusDate>
//                     <ns3:orderLineStatuses>
//                         <ns3:orderLineStatus>
//                             <ns3:status>Shipped</ns3:status>
//                             <ns3:statusQuantity>
//                                 <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement>
//                                 <ns3:amount>1</ns3:amount>
//                             </ns3:statusQuantity>
//                             <ns3:trackingInfo>
//                                 <ns3:shipDateTime>2017-04-28T16:50:53.000Z</ns3:shipDateTime>
//                                 <ns3:carrierName>
//                                     <ns3:carrier>USPS</ns3:carrier>
//                                 </ns3:carrierName>
//                                 <ns3:methodCode>Value</ns3:methodCode>
//                                 <ns3:trackingNumber>redacted</ns3:trackingNumber>
//                                 <ns3:trackingURL>http://walmart.narvar.com/walmart/tracking/usps?redacted</ns3:trackingURL>
//                             </ns3:trackingInfo>
//                         </ns3:orderLineStatus>
//                     </ns3:orderLineStatuses>
//                 </ns3:orderLine>
//             </ns3:orderLines>
//         </ns3:order>
//     </ns3:elements>
// </ns3:list>
 

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