# Gateway Timeout for Historical Orders Query

**URL:** <https://community.shiphero.com/t/gateway-timeout-for-historical-orders-query/2811>\
**Category:** GraphQL API\
**Created:** [February 6, 2024, 10:28pm UTC](https://community.shiphero.com/t/gateway-timeout-for-historical-orders-query/2811 "2024-02-06T22:28:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rypaul12](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rypaul12](https://community.shiphero.com/u/rypaul12)\
**Post date:** [February 6, 2024, 10:28pm UTC](https://community.shiphero.com/t/gateway-timeout-for-historical-orders-query/2811/1 "2024-02-06T22:28:30Z")

</div>

Hello,

For historical orders queries we are consistently getting **504 Gateway Timeouts**.  
We are paginating through all orders over the past 5 years, and have been able to get 10,000+ orders before this issue started sporadically popping up.

We have already tried reducing the number of orders requested at a time.

Currently, the start of our query that keeps timing out is:

```auto
query {
  orders(updated_from: "2019-02-06T04:12:26") {
    data(first: 25, after: "YXJyYXljb25uZWN0aW9uOjE3MTQ5") {

```

Can you please suggest why this request is sporadically timing out?

Thanks,  
Ryan

---

<div class="post-metadata">

**Author:** ![tomasfd](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@tomasfd](https://community.shiphero.com/u/tomasfd)\
**Post date:** [February 7, 2024, 2:30pm UTC](https://community.shiphero.com/t/gateway-timeout-for-historical-orders-query/2811/2 "2024-02-07T14:30:49Z")

</div>

Hi @rypaul12!

Can you share a request ID so I can dig deeper?

However, with what you shared, I can tell you even if you are pulling the first 25, you are still going through the whole dataset of all order updates from that date. So even when it is not timing out, which is 180 secs in our API, every call might take as long as ~179 seconds.

I would suggest you further constrain the call by using an updated\_to. You can try grabbing an entire month using both arguments, paginating through it, and jumping to the following one when you are done.

Have a nice day!  
TomasFD

---

<div class="post-metadata">

**Author:** ![rypaul12](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rypaul12](https://community.shiphero.com/u/rypaul12)\
**Post date:** [February 7, 2024, 11:13pm UTC](https://community.shiphero.com/t/gateway-timeout-for-historical-orders-query/2811/3 "2024-02-07T23:13:23Z")

</div>

Thanks Tomas! Adding the **updated\_to** helped a lot and I’m no longer running into any issues.  
Out of curiosity are there any other optimizations I could make (perhaps something with the _sort_)?

---

<div class="post-metadata">

**Author:** ![tomasfd](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@tomasfd](https://community.shiphero.com/u/tomasfd)\
**Post date:** [February 9, 2024, 2:27pm UTC](https://community.shiphero.com/t/gateway-timeout-for-historical-orders-query/2811/4 "2024-02-09T14:27:47Z")

</div>

Hey @rypaul12!

Glad to hear that!

The thing about containing between dates is that it lets you pick a predefined amount of dates that you can control and once you are done jump onto the next period. The rest of the filters you can use, will require you to know all the values that filter can have, and run them all for each date period.

These are your available filters:

```auto
  $shop_name: String,
  $partner_order_id: String,
  $order_number: String,
  $warehouse_id: String,
  $allocated_warehouse_id: String,
  $fulfillment_status: String,
  $sku: String,
  $email: String,
  $updated_from: ISODateTime,
  $updated_to: ISODateTime,
  $order_date_from: ISODateTime,
  $order_date_to: ISODateTime,
  $customer_account_id: String,
  $operator_hold: Boolean,
  $address_hold: Boolean,
  $payment_hold: Boolean,
  $fraud_hold: Boolean,
  $ready_to_ship: Boolean,
  $profile: String,
  $tag: String,

```

Adding any of those will add more work to you data retrieval I think.

Have a nice day!  
TomasFD
