Skip to content

Instantly share code, notes, and snippets.

@gordcurrie
Last active September 26, 2020 18:47
Show Gist options
  • Select an option

  • Save gordcurrie/f82c7d6131392f47be401bd79e814afa to your computer and use it in GitHub Desktop.

Select an option

Save gordcurrie/f82c7d6131392f47be401bd79e814afa to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
goshopify "github.com/bold-commerce/go-shopify/v3"
)
func main() {
client := goshopify.NewClient(goshopify.App{}, "SHOP_NAME", "API_TOKEN", goshopify.WithVersion("2020-07"))
_, page, err := client.Product.ListWithPagination(nil)
if err != nil {
fmt.Printf("Error: %s", err.Error())
}
// fmt.Printf("%+v", c)
fmt.Printf("%+v", page)
_, page, err = client.Product.ListWithPagination(page.NextPageOptions)
if err != nil {
fmt.Printf("Error: %s", err.Error())
}
// fmt.Printf("%+v", c)
fmt.Printf("%+v", page)
}
@gordcurrie
Copy link
Author

gordcurrie commented Sep 26, 2020

Calling the ListWithPagination function will return a slice of entities, product entities in this case, as well as a pointer to a Pagination struct, and an error. The NextPageOptions field from the Pagination struct can be passed to the next call to ListWithPagination to fetch the next page. The PreviousPageOptions field could be passed return the previous page.

go-shopify leverages the Link header to populate the Pagination struct, and passes those options via request params.

See:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment