Tutorials
How to Prevent Missing Orders with Shopify GraphQL Timestamp Filters
Shopify API 2027-01 changes how timestamp filters handle second boundaries. Learn why fractional seconds matter and how to build reliable order synchronization windows with GraphQL and TypeScript.
An application synchronizes Shopify orders every five minutes. Each request retrieves orders created since the previous synchronization, stores them in a local database, and saves the timestamp for the next execution.
The process appears straightforward until an order is created near the boundary between two synchronization windows.
Perhaps it appears in both responses. Or, more problematically, it never appears in either.
The difficulty is that Shopify’s GraphQL Admin API returns timestamps with second-level precision, although some resources internally store timestamps with fractional seconds.
On December 4, 2026, Shopify announced a change to timestamp filtering in API version 2027-01. The update standardizes how comparison operators interpret timestamps without fractional seconds.
For applications that periodically synchronize orders, products, or other resources, this is a reason to revisit how their synchronization windows are constructed.
The difference between stored and returned timestamps
Suppose three orders are created at the following times:
| Order | Hypothetical stored timestamp | Returned createdAt |
|---|---|---|
| A | 12:04:59.800 | 12:04:59 |
| B | 12:05:00.250 | 12:05:00 |
| C | 12:05:00.750 | 12:05:00 |
Orders B and C have different underlying timestamps, but the application receives the same createdAt value for both.
That becomes relevant when the returned timestamp is used as the boundary of another query.
Consider this filter:
created_at:>'2026-12-03T12:05:00Z'
Should it include orders B and C?
If the comparison uses the exact beginning of the second, both orders qualify. Their internal timestamps are greater than 12:05:00.000.
However, if the timestamp represents the entire second, neither qualifies.
Both interpretations are understandable. The problem arises when an API uses different interpretations depending on the resource being queried.
Before version 2027-01, Shopify’s timestamp filters exhibited such inconsistencies.
What changes in Shopify API 2027-01?
With the new behavior, a timestamp written without fractional seconds represents its corresponding second.
For a timestamp T equal to 12:05:00Z, the four operators behave as follows:
| Filter | Matching records |
|---|---|
< T |
Earlier than 12:05:00 |
<= T |
Earlier than 12:05:01 |
> T |
From 12:05:01 onward |
>= T |
From 12:05:00 onward |
This table applies to whole-second filter values.
The distinction becomes particularly visible with inclusive upper bounds and exclusive lower bounds.
For example:
created_at:<='2026-12-03T12:05:00Z'
includes orders created throughout the second beginning at 12:05:00.
But:
created_at:>'2026-12-03T12:05:00Z'
excludes that entire second.
Shopify had already adjusted exclusive lower-bound comparisons in API version 2026-10. The December 4 announcement extends consistent whole-second semantics across all four comparison operators.
1. Construct adjacent synchronization windows
Suppose an application retrieves orders in five-minute intervals.
The first window starts at 12:00 and ends at 12:05. The next starts at 12:05 and ends at 12:10.
A reliable way to express these intervals in API 2027-01 is to include the lower boundary and exclude the upper one.
query OrdersInWindow {
orders(
first: 50
sortKey: CREATED_AT
query: "created_at:>='2026-12-03T12:00:00Z' created_at:<'2026-12-03T12:05:00Z'"
) {
nodes {
id
createdAt
}
}
}
The following request uses:
created_at:>='2026-12-03T12:05:00Z'
created_at:<'2026-12-03T12:10:00Z'
An order created during the second 12:05:00 belongs to the second window.
There is no overlap between these filters, and no second is left uncovered.
A different combination can introduce a gap:
Window 1: created_at:<'2026-12-03T12:05:00Z'
Window 2: created_at:>'2026-12-03T12:05:00Z'
The first window excludes the boundary second, and the second window excludes it as well.
Every order created during that second falls outside both windows.
The opposite combination, an inclusive upper bound followed by an inclusive lower bound, can cause the boundary second to appear in both responses.
2. Be careful with JavaScript’s toISOString()
JavaScript introduces a less obvious detail.
Consider:
const boundary = new Date("2026-12-03T12:05:00Z");
console.log(boundary.toISOString());
The output is:
2026-12-03T12:05:00.000Z
Nothing has changed about the represented instant. JavaScript simply includes milliseconds in its ISO representation.
Shopify, however, distinguishes between timestamps with and without explicitly specified fractional seconds.
Consider these two filters:
created_at:>'2026-12-03T12:05:00Z'
created_at:>'2026-12-03T12:05:00.000Z'
In API 2027-01, the first excludes the entire second. The second performs an exact timestamp comparison.
An order internally created at 12:05:00.250 matches the second filter but not the first.
This difference can be difficult to notice during debugging because both timestamps become the same value when parsed into JavaScript Date objects.
For the half-open interval using >= and <, exact boundaries at .000Z produce the same mathematical interval under the new rules. The distinction becomes important when using > or <=.
Nevertheless, choosing a consistent representation makes the application’s intended filtering behavior clearer.
3. Generate whole-second filters in TypeScript
Instead of constructing filters separately throughout the application, create a small utility responsible for formatting synchronization windows.
export function wholeSecond(date: Date): string {
if (
!Number.isFinite(date.getTime()) ||
date.getUTCMilliseconds() !== 0
) {
throw new Error(
"Expected a valid whole-second boundary"
);
}
return date.toISOString().replace(/\.000Z$/, "Z");
}
export function orderWindow(
start: Date,
end: Date
): string {
const lower = wholeSecond(start);
const upper = wholeSecond(end);
if (start.getTime() >= end.getTime()) {
throw new Error("Invalid time window");
}
return (
`created_at:>='${lower}' ` +
`created_at:<'${upper}'`
);
}
The function deliberately rejects dates containing non-zero milliseconds.
Why not simply remove the fractional part?
Because silently converting 12:05:00.750 into 12:05:00 changes the requested boundary. Depending on the surrounding synchronization logic, that may retrieve records that were not intended to be included.
If your application needs whole-second windows, rounding should be an explicit decision.
For example, the current time can be rounded down before constructing a synchronization window:
const end = new Date(
Math.floor(Date.now() / 1000) * 1000
);
The formatter then ensures that every boundary follows the selected convention.
4. Test adjacent windows
The filter-building utility can be tested independently of Shopify.
Using Vitest:
import { describe, expect, it } from "vitest";
import { orderWindow } from "./order-window";
describe("orderWindow", () => {
const a = new Date("2026-12-03T12:00:00Z");
const b = new Date("2026-12-03T12:05:00Z");
const c = new Date("2026-12-03T12:10:00Z");
it("creates adjacent whole-second windows", () => {
expect(orderWindow(a, b)).toBe(
"created_at:>='2026-12-03T12:00:00Z' " +
"created_at:<'2026-12-03T12:05:00Z'"
);
expect(orderWindow(b, c)).toBe(
"created_at:>='2026-12-03T12:05:00Z' " +
"created_at:<'2026-12-03T12:10:00Z'"
);
});
it("rejects reversed and empty windows", () => {
expect(() => orderWindow(b, a)).toThrow();
expect(() => orderWindow(a, a)).toThrow();
});
it("rejects fractional-second boundaries", () => {
const end = new Date(
"2026-12-03T12:05:00.500Z"
);
expect(() => orderWindow(a, end)).toThrow();
});
it("rejects invalid dates", () => {
expect(() =>
orderWindow(a, new Date("invalid"))
).toThrow();
});
});
These tests verify the application’s formatting and validation logic.
They do not verify Shopify’s filtering implementation.
That requires integration tests against the actual API version, using orders whose creation times allow the boundary behavior to be examined.
5. Do not confuse a time window with a page of results
There is another way to lose orders that has little to do with timestamps.
The earlier GraphQL query requests only 50 records:
first: 50
What happens if 83 orders are created within those five minutes?
The first response contains only part of the window.
If the application immediately advances its synchronization timestamp, the remaining records may never be retrieved.
Request pagination information and pass the cursor into subsequent requests.
query OrdersInWindow(
$filter: String!
$cursor: String
) {
orders(
first: 50
after: $cursor
sortKey: CREATED_AT
query: $filter
) {
nodes {
id
createdAt
}
pageInfo {
hasNextPage
endCursor
}
}
}
The filter remains unchanged throughout pagination. Only the cursor advances.
A TypeScript implementation might look like this:
type Order = {
id: string;
createdAt: string;
};
type OrdersPage = {
nodes: Order[];
pageInfo: {
hasNextPage: boolean;
endCursor: string | null;
};
};
type FetchOrdersPage = (
filter: string,
cursor: string | null
) => Promise<OrdersPage>;
export async function* readOrders(
start: Date,
end: Date,
fetchPage: FetchOrdersPage
): AsyncGenerator<Order> {
const filter = orderWindow(start, end);
let cursor: string | null = null;
while (true) {
const page = await fetchPage(filter, cursor);
for (const order of page.nodes) {
yield order;
}
if (!page.pageInfo.hasNextPage) {
return;
}
const next = page.pageInfo.endCursor;
if (!next || next === cursor) {
throw new Error("Invalid pagination cursor");
}
cursor = next;
}
}
The fetchPage function represents your existing authenticated Shopify GraphQL client.
It should reject failed requests and GraphQL errors instead of returning an empty page when something goes wrong.
The asynchronous generator allows the application to process orders incrementally rather than accumulating the entire synchronization window in memory.
More importantly, it keeps pagination separate from the synchronization checkpoint.
6. Save the checkpoint only after processing all pages
Imagine that the first two pages are retrieved successfully, but the third request fails because the application reaches an API rate limit.
If the synchronization timestamp has already advanced, restarting the job may skip the unprocessed orders.
The checkpoint should instead be updated after the complete window has been processed.
flowchart TD
A["Read saved checkpoint"] --> B["Choose fixed window end"]
B --> C["Fetch orders page"]
C --> D["Upsert orders by ID"]
D --> E{"More pages?"}
E -->|Yes| C
E -->|No| F["Save window end as checkpoint"]
Using the generator from the previous example:
for await (const order of readOrders(
start,
end,
fetchPage
)) {
await upsertOrder(order);
}
await saveCheckpoint(end);
Here, upsertOrder() and saveCheckpoint() represent the application’s database operations.
If fetching or processing a page throws an error, execution never reaches saveCheckpoint().
The next synchronization attempt can retry from the previous saved boundary.
But retrying creates another consideration: some orders may already exist in the database.
Use the Shopify order ID as a unique identifier within the store’s synchronization context. An upsert can update an existing record instead of inserting another copy.
The combination of stable checkpoints and idempotent writes makes retrying considerably safer.
7. Does this guarantee that no orders will ever be missed?
Correct timestamp filters eliminate one particular source of missing or duplicated records.
They do not turn a sequence of API requests into a database snapshot.
A record might become visible after the application has already finished scanning its time window. Pagination can also be affected by changes to the underlying collection.
For applications where missing an order has significant consequences, additional safeguards can include delayed upper boundaries, overlapping reconciliation windows, webhook processing, and periodic consistency checks.
Intentional overlap is not necessarily a problem when database writes are idempotent.
There is also a separate access restriction: Shopify normally exposes only the most recent 60 days of orders unless the application has the additional permissions required to retrieve older records.
Finally, created_at only identifies newly created orders. It does not retrieve every subsequent modification to those orders.
An application synchronizing order updates needs a separate strategy, potentially using updated_at and appropriate reconciliation logic.
Test before switching API versions
As of December 4, 2026, Shopify API 2027-01 is a release candidate.
Its stable release is scheduled for January 1, 2027.
During development testing, use the explicitly versioned endpoint:
https://YOUR_STORE.myshopify.com/admin/api/2027-01/graphql.json
Compare its behavior with your application’s existing API version.
Test filters containing Z, .000Z, and non-zero fractional values. Pay particular attention to records created during boundary seconds.
Also verify that pagination completes before the synchronization checkpoint advances.
The December 4 change resolves an inconsistency in timestamp comparison semantics. For most applications, adopting inclusive lower bounds and exclusive upper bounds is a relatively small adjustment.
The harder part is recognizing that the timestamp returned by an API may not contain the full precision of the value stored behind it.
Two orders can expose identical creation times without having been created at the same instant.
An integration that remembers only the last timestamp, ignores pagination, or assumes that every comparison operator behaves identically across API versions can lose information without producing a single error.