(Swift 2) Shopify Receive Count of All Products in a Collection
Get a count of all products of a given collection
func chilkatTest() {
let rest = CkoRest()
var success: Bool
rest.SetAuthBasic("SHOPIFY_PRIVATE_API_KEY", password: "SHOPIFY_PRIVATE_API_KEY")
success = rest.Connect("chilkat.myshopify.com", port: 443, tls: true, autoReconnect: true)
if success != true {
print("\(rest.LastErrorText)")
return
}
let sbJson = CkoStringBuilder()
success = rest.FullRequestNoBodySb("GET", uriPath: "/admin/products/count.json?collection_id=841564295 ", sb: sbJson)
if success != true {
print("\(rest.LastErrorText)")
return
}
if rest.ResponseStatusCode.intValue != 200 {
print("Received error response code: \(rest.ResponseStatusCode.intValue)")
print("Response body:")
print("\(sbJson.GetAsString())")
return
}
let json = CkoJsonObject()
json.LoadSb(sbJson)
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
var count: Int
count = json.IntOf("count").intValue
// A sample JSON response body that is parsed by the above code:
// {
// "count": 1
// }
print("Example Completed.")
}
|