← Dashboard
Section 09 of 14

Shopify API

What This Does

We use Shopify's GraphQL Admin API to fetch full order details — specifically the discount allocations and line item prices that the webhook payload doesn't include in enough detail. The GraphQL query fetches the order's currentSubtotalPriceSet (the post-discount total we compare against) and all line items with their discount allocations.

Why It Matters

The webhook payload tells us an order has an order-level discount, but it doesn't give us the precise allocation amounts per line item. We need the GraphQL API to get the exact discount breakdown for accurate ratio calculation.

How It Works

  1. 1.We find the most recent Shopify session (OAuth access token) for the shop domain.
  2. 2.We make a GraphQL request to Shopify's Admin API with the order ID.
  3. 3.The query returns: order name, currency, currentSubtotalPriceSet (post-all-discounts total), shipping address, and all line items.
  4. 4.Each line item includes its discount allocations — how much of each discount applies to this specific item.
  5. 5.We use the allocation data to sum up order-level discount amounts for the ratio calculation.

The Code

Key Decisions

What Could Go Wrong