Get Orders using Shopify API

 import uvicorn
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import requests
import os

app = FastAPI()

# Environment variable for the Shopify store URL

class Order(BaseModel):

@app.get("/orders", summary="Get Orders", description="Retrieves orders from a Shopify store.")
async def get_orders():
    orders_url = f"https://{SHOPIFY_STORE_URL}/admin/api/2024-01/orders.json"
    headers = {
        'Content-Type': 'application/json',
        'X-Shopify-Access-Token': os.environ['SHOPIFY_ADMIN_API_TOKEN']
    response = requests.get(orders_url, headers=headers)
    if response.status_code == 200:
        return response.json()

About this template

A python app for getting orders in a store using the Shopify API. The python FastAPI is used for making the API call. The app requires a SHOPIFY_ADMIN_API_TOKEN and "orders" scope permissions to authenticate requests. This app can be customized to get all orders by name, by order ID (order number), fulfilled orders only and so on.

Introduction to the Get Orders using Shopify API Template

Welcome to the "Get Orders using Shopify API" template. This template is designed to help you build an application that retrieves orders from a Shopify store using the Shopify API. The application is built with Python and FastAPI, and it's perfect for those who want to integrate Shopify order retrieval into their software without worrying about the complexities of API calls and server deployment.

Clicking Start with this Template

To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code manually.

Initial Setup: Adding Environment Secrets

Before you can test and use the application, you need to set up a couple of environment secrets within the Lazy Builder. These secrets are necessary for the app to authenticate requests to the Shopify API.

You will need to set up the following environment secrets:

  • SHOPIFY_STORE_URL: The URL of your Shopify store.
  • SHOPIFY_ADMIN_API_TOKEN: The API token provided by Shopify for admin access.

To obtain these values:

  1. Log in to your Shopify admin dashboard.
  2. Go to "Apps" and then "Manage private apps" to create or use an existing private app.
  3. Ensure that the private app has the "orders" scope permissions.
  4. Copy the API key and password (this will be your SHOPIFY_ADMIN_API_TOKEN).
  5. Set the SHOPIFY_STORE_URL to your store's URL (e.g.,

Once you have these values, enter them into the Environment Secrets tab within the Lazy Builder.

Test: Pressing the Test Button

After setting up the environment secrets, press the "Test" button to deploy the app. The Lazy platform will handle the deployment, and you won't need to install any libraries or set up your environment.

Using the App

Once the app is deployed, you will be provided with a dedicated server link to interact with the API. Additionally, since this app uses FastAPI, you will also receive a link to the API documentation, which will allow you to explore the available endpoints and their usage.

To retrieve orders from your Shopify store, you can use the provided server link to send a GET request to the "/orders" endpoint. Here's a sample request:

GET /orders
Host: [Your Server Link]

A sample response might look like this:

  "orders": [
      "id": 123456789,
      "email": "",
      "closed_at": null,
      "created_at": "2023-01-01T10:00:00-05:00",
      "updated_at": "2023-01-01T10:00:00-05:00",
      // More order details...
    // More orders...

Integrating the App

If you wish to integrate this app into an external service or frontend, you can use the server link provided by Lazy to make API calls from your external tool. Ensure that you handle the authentication properly by including the necessary headers with your requests.

For example, if you're integrating with a frontend application, you might make an AJAX call to the server link to retrieve orders and display them on your webpage.

Remember to replace [Your Server Link] with the actual link provided by Lazy when making requests.

By following these steps, you should now have a functional application that retrieves orders from your Shopify store using the Shopify API, all set up and ready to go on the Lazy platform.

Last published
June 14, 2024

More templates like this

PDF Data Extraction and Excel Transfer

An app for extracting name, phone number, and email data from PDF files and transferring it to Excel.


GPT-4 Exam Generator

This app uses GPT-4 to generate a PDF of a new exam based on an uploaded PDF of a past exam.


Job Search Website

A customisable one-page job search website with a search bar and a search button that displays UI cards of matching jobs. You need to have a (free) account on to get the API key required for this to work.

React JS
Get Orders using Shopify API