Sample code for 30+ languages & platforms
Go

Shopify Receive Count of All Products in a Collection

See more Shopify Examples

Get a count of all products of a given collection

Chilkat Go Downloads

Go
    success := false

    rest := chilkat.NewRest()

    rest.SetAuthBasic("SHOPIFY_PRIVATE_API_KEY","SHOPIFY_PRIVATE_API_KEY")

    success = rest.Connect("chilkat.myshopify.com",443,true,true)
    if success != true {
        fmt.Println(rest.LastErrorText())
        rest.DisposeRest()
        return
    }

    sbJson := chilkat.NewStringBuilder()
    success = rest.FullRequestNoBodySb("GET","/admin/products/count.json?collection_id=841564295 ",sbJson)
    if success != true {
        fmt.Println(rest.LastErrorText())
        rest.DisposeRest()
        sbJson.DisposeStringBuilder()
        return
    }

    if rest.ResponseStatusCode() != 200 {
        fmt.Println("Received error response code: ", rest.ResponseStatusCode())
        fmt.Println("Response body:")
        fmt.Println(*sbJson.GetAsString())
        rest.DisposeRest()
        sbJson.DisposeStringBuilder()
        return
    }

    json := chilkat.NewJsonObject()
    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")

    // A sample JSON response body that is parsed by the above code:

    // {
    //   "count": 1
    // }

    fmt.Println("Example Completed.")

    rest.DisposeRest()
    sbJson.DisposeStringBuilder()
    json.DisposeJsonObject()