//native
/**
* List Assigned Fulfillment Orders
* For fulfillment service apps: list the fulfillment orders assigned to the app's locations, optionally filtered by request status (e.g. FULFILLMENT_REQUESTED to pick up new work, CANCELLATION_REQUESTED to see cancellations). Returns one page; pass pageInfo.endCursor as after for the next. Needs the read_assigned_fulfillment_orders scope.
*/
export async function main(
auth: RT.Shopify,
assignment_status:
| "FULFILLMENT_REQUESTED"
| "FULFILLMENT_ACCEPTED"
| "CANCELLATION_REQUESTED"
| "FULFILLMENT_UNSUBMITTED"
| undefined,
location_ids: string[] | undefined,
sort_key: "UPDATED_AT" | "ID" | 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, $assignmentStatus: FulfillmentOrderAssignmentStatus, $locationIds: [ID!], $sortKey: FulfillmentOrderSortKeys, $reverse: Boolean) { assignedFulfillmentOrders(first: $first, after: $after, assignmentStatus: $assignmentStatus, locationIds: $locationIds, sortKey: $sortKey, reverse: $reverse) { nodes { id status requestStatus orderId orderName createdAt updatedAt fulfillAt fulfillBy assignedLocation { name location { id } } fulfillmentHolds { id reason reasonNotes handle } supportedActions { action } lineItems(first: 10) { nodes { id sku productTitle variantTitle totalQuantity remainingQuantity lineItem { id } } } } pageInfo { hasNextPage endCursor } } }`,
variables: {
first: first || 50,
after: after || undefined,
assignmentStatus: assignment_status || undefined,
locationIds: location_ids?.length
? location_ids.map((id) =>
id.startsWith("gid://") ? id : `gid://shopify/Location/${id}`
)
: 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.assignedFulfillmentOrders
}
Submitted by hugo989 3 hours ago