//native
/**
* Get Order
* Get an order with its customer, addresses, totals, the first 50 line items, fulfillments, transactions and refunds. Orders older than 60 days need the read_all_orders scope.
*/
export async function main(auth: RT.Shopify, order_id: string) {
const id = order_id.startsWith("gid://")
? order_id
: `gid://shopify/Order/${order_id}`
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 ($id: ID!) { order(id: $id) { id legacyResourceId name email phone poNumber createdAt updatedAt processedAt cancelledAt cancelReason closed closedAt test tags note customAttributes { key value } displayFinancialStatus displayFulfillmentStatus currencyCode subtotalPriceSet { shopMoney { amount currencyCode } } totalDiscountsSet { shopMoney { amount currencyCode } } totalShippingPriceSet { shopMoney { amount currencyCode } } totalTaxSet { shopMoney { amount currencyCode } } totalPriceSet { shopMoney { amount currencyCode } } totalRefundedSet { shopMoney { amount currencyCode } } totalOutstandingSet { shopMoney { amount currencyCode } } customer { id displayName defaultEmailAddress { emailAddress } defaultPhoneNumber { phoneNumber } } shippingAddress { name firstName lastName company address1 address2 city provinceCode zip countryCodeV2 phone } billingAddress { name firstName lastName company address1 address2 city provinceCode zip countryCodeV2 phone } shippingLine { title code originalPriceSet { shopMoney { amount currencyCode } } } lineItems(first: 50) { nodes { id name sku quantity currentQuantity unfulfilledQuantity refundableQuantity originalUnitPriceSet { shopMoney { amount currencyCode } } discountedUnitPriceAfterAllDiscountsSet { shopMoney { amount currencyCode } } variant { id title } product { id title } } pageInfo { hasNextPage endCursor } } fulfillments(first: 20) { id name status displayStatus createdAt trackingInfo { company number url } } transactions(first: 20) { id kind status gateway test processedAt amountSet { shopMoney { amount currencyCode } } } refunds(first: 20) { id createdAt note totalRefundedSet { shopMoney { amount currencyCode } } } } }`,
variables: { id },
}),
}
)
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.order
}
Submitted by hugo989 3 hours ago