skip to Main Content

I am trying to get all order events for a shop for my shopify app. What would be the best scalable way?

I have tried Events API, the documentation for Events API says to use GET /admin/events.json to retrieve a list of all events for a shop, but it doesn’t return all order events, only order confirmed event is returned.

The way I can see all events associated with an order is by using GET /admin/orders/#{order_id}/events.json, but this solution might not work for my use case. With this endpoint, i will need to get list of all orders first and then iterate over those order IDs to get events for those orders. It’s won’t be scalable for me at order ID level, it would perfect if i can get all order events though one endpoint at the events level.

Does anyone know the best way to solve this issue?

2

Answers


  1. There is a way. I would do this:

    • download all orders
    • iterate those orders, looking for events
    • persist the events with the order ID as your key.

    Now when ever your merchant customer wants to see the events associated with an order and it would be inconvenient of them to just navigate to the order, a call to your App with the Order ID can snappily report the events as you saved them.

    If you listen to order updates, you could scan for new events added.

    So your scaling problem is not really a problem since you need only grab old orders once. Moving forward just listening to orders/update will keep things updated without a whole lot of overhead.

    Login or Signup to reply.
  2. If you specifically are looking for Order timeline events, you can get this using the Shopify GraphQL Admin API. A query like this will return the first 100 events on a specific order.

    # simple query to get top 10 messages from order timeline
    query {
      order(id: "gid://shopify/Order/618806837270") {
        events(first: 100) {
          edges {
            node {
              __typename message
              createdAt
              id
            }
          }
        }
      }
    }
    

    This will return a result like

    [
      {
        "order": {
          "events": {
            "edges": [
              {
                "node": {
                  "__typename": "BasicEvent",
                  "message": "Order was placed on XXXXXXX.",
                  "createdAt": "2018-11-08T22:16:54Z",
                  "id": "gid://shopify/BasicEvent/9349083824150"
                }
              },
              {
                "node": {
                  "__typename": "BasicEvent",
                  "message": "Received new order <a href="https://XXXXXXX.myshopify.com/admin/orders/618806837270">#1183</a>.",
                  "createdAt": "2018-11-08T22:16:55Z",
                  "id": "gid://shopify/BasicEvent/9349083856918"
                }
              },
              {
                "node": {
                  "__typename": "BasicEvent",
                  "message": "XXXXXXX fulfilled 1 item from Shopify.",
                  "createdAt": "2019-02-04T17:26:00Z",
                  "id": "gid://shopify/BasicEvent/14072023547926"
                }
              },
              {
                "node": {
                  "__typename": "BasicEvent",
                  "message": "This order was archived.",
                  "createdAt": "2019-02-04T17:26:00Z",
                  "id": "gid://shopify/BasicEvent/14072023580694"
                }
              },
              {
                "node": {
                  "__typename": "CommentEvent",
                  "message": "this is a comment",
                  "createdAt": "2019-02-04T17:26:15Z",
                  "id": "gid://shopify/CommentEvent/14072023875606"
                }
              }
            ]
          }
        }
      },
      {
        "cost": {
          "requestedQueryCost": 103,
          "actualQueryCost": 8,
          "throttleStatus": {
            "maximumAvailable": 1000,
            "currentlyAvailable": 992,
            "restoreRate": 50
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search