(Swift 3,4,5...) 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.int(of: "count").intValue
// A sample JSON response body that is parsed by the above code:
// {
// "count": 1
// }
print("Example Completed.")
}
|