Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Order Filtering with REST

Solved

Order Filtering with REST

Kilmer
Tourist
4 1 0

Hi. I'm wondering if I can

 

  1. Filter by multiple parameters with the REST API
  2. Filter by fulfillment status with the REST API

I'm using the Shopify python module and making requests like this:

 

 

f = shopify.Order.find(created_at_min="2022-06-09",fulfilled_status="fulfilled")
# (https://mystore.myshopify.com/admin/api/2022-04/orders.json?created_at_min=2022-06-09&fulfilled_stat...)
u = shopify.Order.find(created_at_min="2022-06-09",fulfilled_status="null")

I've also tried status=fulfilled, removing the date: .find(fulfilled_status="fulfilled")

 

None of it seems to filter by fulfillment status. Do I need to do this with the GraphQL endpoint?

 

Thanks much.

 

–Mike

Accepted Solution (1)
Kilmer
Tourist
4 1 0

This is an accepted solution.

And the answer to the original question (doing it with just the REST API):

 

Which produces, via. the Python API:

 

.myshopify.com/admin/api/2022-04/orders.json?status=%3Cbuilt-in+function+all%3E&created_at_min=2022-05-22&fulfillment_status=shipped

 

Have a good one.

View solution in original post

Replies 3 (3)

Kilmer
Tourist
4 1 0

Update I am now working with the GraphQL library, but still struggling to filter by fulfillment status:

 

graphql_query = (
            """{
            orders(first: 100, query: "fulfillment_status:FULFILLED updated_at:>"""
                + since_date
                + """") {
            edges {
                node {
                    id
                    displayFulfillmentStatus
                    updatedAt
                }
            }
            }
        }
        """

 

References: Field Search, Orders.

 

Input would, of course, be very much appreciated.

Kilmer
Tourist
4 1 0

Here's a solution:

 

 

    def get_orders(self, days_ago: int) -> dict:
        """
        Get a list of shopify order resource objects.
        """
        start_at = datetime.date.today() - datetime.timedelta(days=days_ago)
        since = start_at.strftime("%Y-%m-%d")
        graphql_query = (
            """{
            orders(first: 100, query: "fulfillment_status:shipped updated_at:>"""
                + since
                + """") {
            edges {
                node {
                    id
                    displayFulfillmentStatus
                    updatedAt
                }
            }
            }
        }
        """
        )
        _response = shopify.GraphQL().execute(graphql_query)
        _remote_orders = json.loads(_response)["data"]["orders"]["edges"]
        return [item["node"] for item in _remote_orders]

 

 

Not sure why the API seems to ignore the filter parameter when I filter by a filter status that doesn't exist, though. (fulfillment_status:fulfilled). This post was key.

Kilmer
Tourist
4 1 0

This is an accepted solution.

And the answer to the original question (doing it with just the REST API):

 

Which produces, via. the Python API:

 

.myshopify.com/admin/api/2022-04/orders.json?status=%3Cbuilt-in+function+all%3E&created_at_min=2022-05-22&fulfillment_status=shipped

 

Have a good one.