Swift
Swift
HTTPS MWS List Orders (Amazon Marketplace Web Service)
See more HTTP Misc Examples
Send an HTTPS MWS ListOrders request to return a list of orders created or updated during a time frame.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// Make sure to connect to the correct Amazon MWS Endpoing, otherwise
// you'll get an HTTP 401 response code.
//
// The possible servers are:
//
// North America (NA) https://mws.amazonservices.com
// Europe (EU) https://mws-eu.amazonservices.com
// India (IN) https://mws.amazonservices.in
// China (CN) https://mws.amazonservices.com.cn
// Japan (JP) https://mws.amazonservices.jp
//
// Build the HTTP request.
let req = CkoHttpRequest()!
// Add query params
req.addParam(name: "Action", value: "ListOrders")
req.addParam(name: "CreatedAfter", value: "2016-12-31T23:00:00Z")
req.addParam(name: "MarketplaceId.Id.1", value: "MWS_MARKETPLACE_ID")
req.addParam(name: "SellerId", value: "MWS_SELLER_ID")
req.addParam(name: "AWSAccessKeyId", value: "MWS_ACCESS_KEY_ID")
req.addParam(name: "SignatureVersion", value: "2")
req.addParam(name: "SignatureMethod", value: "HmacSHA256")
req.addParam(name: "Version", value: "2013-09-01")
// Set the HTTP verb and path.
req.path = "/Orders/2013-09-01"
req.httpVerb = "POST"
// Add the MWS Signature after the verb, path, and all params have been set.
req.addMwsSignature(domain: "mws.amazonservices.com", mwsSecretKey: "MWS_SECRET_ACCESS_KEY_ID")
req.contentType = "application/x-www-form-urlencoded"
let resp = CkoHttpResponse()!
success = http.httpReq(url: "https://mws.amazonservices.com/Orders/2013-09-01", request: req, response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
if resp.statusCode.intValue != 200 {
print("Non-success status code: \(resp.statusCode.intValue)")
print("\(resp.bodyStr!)")
return
}
// Examine the XML returned in the response body.
print("\(resp.bodyStr!)")
print("----")
print("Success.")
}