//native
/**
* Search Draft Orders
* Search draft orders with Shopify's search syntax (e.g. `status:open`, `customer_id:123`, `tag:quote updated_at:>2026-01-01`). Leave query empty to list them all. Returns one page; pass pageInfo.endCursor as after to get the next one.
*/
export async function main(
auth: RT.Shopify,
query: string | undefined,
sort_key:
| "UPDATED_AT"
| "NUMBER"
| "STATUS"
| "TOTAL_PRICE"
| "CUSTOMER_NAME"
| "ID"
| "RELEVANCE"
| undefined,
reverse: boolean | undefined,
first: number | undefined,
after: string | undefined
) {
const response = await fetch(
`https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
{
method: "POST",
headers: {
"X-Shopify-Access-Token": auth.token,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `query ($first: Int!, $after: String, $query: String, $sortKey: DraftOrderSortKeys, $reverse: Boolean) { draftOrders(first: $first, after: $after, query: $query, sortKey: $sortKey, reverse: $reverse) { nodes { id legacyResourceId name status email phone createdAt updatedAt completedAt invoiceUrl invoiceSentAt tags note2 ready reserveInventoryUntil subtotalPriceSet { shopMoney { amount currencyCode } } totalDiscountsSet { shopMoney { amount currencyCode } } totalShippingPriceSet { shopMoney { amount currencyCode } } totalTaxSet { shopMoney { amount currencyCode } } totalPriceSet { shopMoney { amount currencyCode } } customer { id displayName defaultEmailAddress { emailAddress } } order { id name } } pageInfo { hasNextPage endCursor } } }`,
variables: {
first: first || 50,
after: after || undefined,
query: query || undefined,
sortKey: sort_key || undefined,
reverse: reverse || undefined,
},
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data, errors } = await response.json()
if (errors) {
throw new Error(JSON.stringify(errors))
}
return data.draftOrders
}
Submitted by hugo989 3 hours ago