Shopify API Order: How To Get All Orders From Shopify

shopify-order-api

While it enjoys its position as one of the most popular CMS in the E-commerce world, Shopify is one of those platforms that often comes around with some quite confusing queries. Many of these queries come regarding the integrations such as ERP connectors, descriptive order analytics, and much more.

One such query that most Shopify maintenance service providers receive is related to the Shopify order limit of 250 rows. The problem here is the fact that The Shopify API actually allows a maximum of 250 orders per request.

The solution to this problem is quite simple. All you need to do is to create a private app in Shopify and tweak Shopify API order to surpass the 250 orders limit.

How? We’re going to discuss it in this read.

Let’s begin.

Related: Shopify Website Prices: How Much Does It Cost To Build A Shopify Website?

shopify-store

Creating A Private App API in Shopify

The first step to creating a Shopify API order is to create a private app within Shopify. This would provide you with an API URL.

Here’s how to do it.

Step 1: Access your Shopify admin panel and navigate to the Apps menu.

Step 2: In the Apps menu, navigate and click on the Manage Private Apps option.

Step 3: Click on the Create New Private App option.

Once you’ve successfully created an app, you’ll be able to get the URL which you can use to create a Shopify API order.

Here’s how it looks like.

https://%7Bapikey%7D:%7Bpassword%7D@%7Bhostname%7D/admin/api/%7Bversion%7D/%7Bresource%7D.json

Get All Orders

Once you’ve got the URL, there are some minor changes that you need to make in the variables of this URL.

  • Limit=250: This is the maximum number of orders we can get.
  • fulfillment_status=unfulfilled: We will get all unfulfilled orders so we will use the status unfulfilled. You can remove it and get also the fulfilled orders.
  • since_id=: This means that we want all orders since the order Id we will provide. We will use it to surpass the limit of 250 orders.

The trick here is after every API call to get the oldest order ID and use it for our next call inside the since_id variable. Then, when the API will return less than our limit (250) we stop the loop and return the orders Dataframe.

Refer to this line of code below for better understand.

import pandas as pd

import numpy as np

import re

import requests

def get_all_orders():

    last=0

    orders=pd.DataFrame()

    while True:

        url = f”https://{apikey}:{password}@{hostname}/admin/api/{version}/{resource}.json?limit=250&fulfillment_status=unfulfilled&since_id={last}”

        response = requests.request(“GET”, url)

        df=pd.DataFrame(response.json()[‘orders’])

        orders=pd.concat([orders,df])

        last=df[‘id’].iloc[-1]

        if len(df)<250:

            break

    return(orders)

df=get_all_orders()

df.head()

Finishing

Using this technique mentioned above, you can quickly create Shopify API orders and get all orders from Shopify without limitations.

If you’ve found this read useful, have a look at our other Shopify related posts such as ‘How To Pause/ Close Your Shopify Seller Account