Lua
Lua
Shopify Receive Count of All Products in a Collection
See more Shopify Examples
Get a count of all products of a given collectionChilkat Lua Downloads
local chilkat = require("chilkat")
local rest = chilkat.Rest.new()
rest:set_auth_basic("SHOPIFY_PRIVATE_API_KEY", "SHOPIFY_PRIVATE_API_KEY")
local success = rest:connect("chilkat.myshopify.com", 443, true, true)
if not success then
print(rest.last_error_text)
return
end
local sbJson = chilkat.StringBuilder.new()
success = rest:full_request_no_body_sb("GET", "/admin/products/count.json?collection_id=841564295 ", sbJson)
if not success then
print(rest.last_error_text)
return
end
if rest.response_status_code ~= 200 then
print("Received error response code: " .. rest.response_status_code)
print("Response body:")
print(sbJson:get_as_string())
return
end
local json = chilkat.JsonObject.new()
json:load_sb(sbJson)
-- The following code parses the JSON response.
-- A sample JSON response is shown below the sample code.
local count = json:int_of("count")
-- A sample JSON response body that is parsed by the above code:
-- {
-- "count": 1
-- }
print("Example Completed.")