GraphQL query to fetch all the sales orders from Shopify

GraphQL query to retrieve all sales orders with a status of “paid.”

Utilize afterCursor for pagination to fetch all orders, as each query instance can return a maximum of 250 orders.

query getOrders($afterCursor: String) {

                                orders(

                                        query: "created_at:>${time} financial_status:paid"

                                        first: 200

                                        after: $afterCursor

                                    ) {

                                        edges {

                                            node {

                                                id

                                                createdAt

                                                customer {

                                                id

                                                firstName

                                                lastName

                                                email

                                                phone

                                            }

                                            billingAddress {

                                                address1

                                                address2

                                                city

                                                province

                                                country

                                                zip

                                            }

                                            shippingAddress {

                                                address1

                                                address2

                                                city

                                                province

                                                country

                                                zip

                                                name

                                                phone

                                            }

                                            totalPrice

                                            totalTax

                                            totalShippingPrice

                                            totalDiscounts

                                            lineItems(first: 250) {

                                                edges {

                                                    node {

                                                        id

                                                        title

                                                        quantity

                                                        isGiftCard

                                                        originalUnitPrice

                                                        variant {

                                                            inventoryItem {

                                                                id

                                                                sku

                                                                tracked

                                                            }

                                                            price

                                                        }

                                                        originalTotal

                                                    }

                                                }

                                            }

                                        }

                                    }

                                    pageInfo {

                                        hasNextPage

                                        endCursor

                                    }

                                }

                            }

Leave a comment

Your email address will not be published. Required fields are marked *