-
Notifications
You must be signed in to change notification settings - Fork 274
Description
Question
Is there a way by which we can list all the Shopify orders (including open, closed and canceled) using ListWithPagination function?
Roadblock
I tried the following code to extract the list of orders:
func listOrders(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
conn, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("shopify_order.listOrders", "connection_error", err)
return nil, err
}
// max limit defined by the api is 250
// We are setting status to 'any' to get all the orders(open, closed, canceled)
options := goshopify.OrderListOptions{
ListOptions: goshopify.ListOptions{},
Status: "any",
}
maxLimit := int64(250)
// set the limit if a lower limit is passed in query context
limit := d.QueryContext.Limit
if limit != nil {
if *limit < maxLimit {
options.ListOptions.Limit = int(*limit)
}
} else {
options.ListOptions.Limit = int(maxLimit)
}
for {
orders, paginator, err := conn.Order.ListWithPagination(options)
if err != nil {
plugin.Logger(ctx).Error("shopify_order.listOrders", "api_error", err)
return nil, err
}
for _, order := range orders {
d.StreamListItem(ctx, order)
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
if paginator.NextPageOptions == nil {
return nil, nil
}
options.ListOptions.PageInfo = paginator.NextPageOptions.PageInfo
}
}
However if the number of orders is more than 250, the API returns the following error -
status: status cannot be passed when page_info is present. See https://shopify.dev/api/usage/pagination-rest for more information.
This link suggests that we can only pass limit and page_info, but there is no scope to pass the status field.
Alternatives considered
If I don't pass the Status parameter to the OrderListOptions, the results are correctly paginated, however, the caveat is that I cannot access the closed or canceled orders.
Expectation
ListWithPagination function should include the option to pass the Status field so that we can retrieve all kinds of orders.
Additional Context
Issue reference - turbot/steampipe-plugin-shopify#25
Please let me know if additional details are needed. Any kind suggestion would be very helpful. Thanks!!