Welcome to the Jose Madrid Salsa developer docs — explore features, APIs, and deployment guides.
Jose Madrid SalsaJMS Docs

Shopify

Shopify Admin API integration for order syncing and fulfillment management

Shopify Integration

SDK

GitHubShopify/shopify-api-js

957381

The platform syncs orders to Shopify for fulfillment management. When a customer completes checkout on the Next.js storefront, the order is pushed to Shopify via the Admin REST API. Shopify then handles fulfillment, inventory tracking, and shipping label generation.

Architecture

Next.js Storefront -> Order Created -> syncOrderToShopify()
  -> ShopifyAdminClient.createOrder() -> Shopify Admin API
  -> Order record updated with Shopify IDs

The Shopify integration consists of three modules:

FilePurpose
lib/shopify/client.tsShopifyAdminClient class and order transformation
lib/shopify/sync.tsOrder sync orchestration
lib/shopify/webhook.tsWebhook signature verification and status mapping

Environment Variables

VariableDescriptionRequired
SHOPIFY_STORE_DOMAINShopify store domain (e.g., my-store.myshopify.com)Yes
SHOPIFY_ADMIN_API_TOKENShopify Admin API access tokenYes
SHOPIFY_API_VERSIONAPI version (defaults to 2024-10)No
SHOPIFY_WEBHOOK_SECRETWebhook HMAC signing secretYes

Setup

Create a Shopify Custom App

In the Shopify admin, go to Settings > Apps and sales channels > Develop apps. Create a custom app with the following scopes:

  • write_orders
  • read_orders
  • write_fulfillments
  • read_fulfillments

Install and get the access token

Install the app in your store and copy the Admin API access token.

Configure environment variables

SHOPIFY_STORE_DOMAIN=josemadridsalsa.myshopify.com
SHOPIFY_ADMIN_API_TOKEN=shpat_...
SHOPIFY_API_VERSION=2024-10
SHOPIFY_WEBHOOK_SECRET=your_webhook_secret

Register webhooks

Create webhooks in the Shopify admin pointing to https://your-domain.com/api/webhooks/shopify for these topics:

  • orders/create
  • orders/updated
  • orders/paid
  • orders/cancelled
  • fulfillments/create
  • fulfillments/update

Order Transformation

The transformOrderForShopify() function converts a Prisma order (with items, addresses, and user) into Shopify's order format:

Field Mapping

Prisma FieldShopify Field
items[].productNameline_items[].title
items[].unitPriceline_items[].price (formatted to 2 decimals)
items[].quantityline_items[].quantity
shippingAddressshipping_address
billingAddressbilling_address
paymentStatusfinancial_status (mapped via PAYMENT_STATUS_MAP)
shippingCostshipping_lines[].price
taxtotal_tax
discountAmounttotal_discounts

Payment Status Mapping

Prisma StatusShopify Status
PENDING / PROCESSINGpending
SUCCEEDED / PAIDpaid
FAILED / CANCELEDvoided
REFUNDEDrefunded
PARTIALLY_REFUNDEDpartially_refunded

Metadata

Each Shopify order includes:

  • Tags: Jose Madrid Salsa, Next.js Storefront
  • Note attributes: orderNumber and orderId (used for webhook matching)
  • inventory_behaviour: 'decrement_obeying_policy'
  • Receipt and fulfillment emails are disabled (send_receipt: false)

ShopifyAdminClient

A singleton client accessed via getShopifyClient(). Methods:

createOrder(order)

Creates a Shopify order from a Prisma order. Returns { success, order?, error? }.

cancelOrder(shopifyOrderId, reason?)

Cancels a Shopify order with optional restock and reason.

getOrder(shopifyOrderId)

Retrieves a Shopify order by ID, including fulfillment and tracking data.

Order Sync

File: lib/shopify/sync.ts

syncOrderToShopify(orderId)

  1. Checks if Shopify is configured (skips silently if not)
  2. Fetches the full order with items, addresses, and user
  3. Calls ShopifyAdminClient.createOrder()
  4. On success: updates the order with shopifyOrderId, shopifyOrderName, shopifySyncedAt, and appends sync info to adminNotes
  5. On failure: stores the error in shopifySyncError

queueShopifySync(orderId)

Fire-and-forget wrapper that calls syncOrderToShopify() without awaiting. Used in checkout flows where Shopify sync should not block the response.

Shopify sync is optional. If SHOPIFY_STORE_DOMAIN and SHOPIFY_ADMIN_API_TOKEN are not set, syncOrderToShopify() returns immediately without error.

Key Files

FilePurpose
lib/shopify/client.tsShopifyAdminClient and order transformation
lib/shopify/sync.tsOrder sync orchestration
lib/shopify/webhook.tsWebhook verification and status mapping
app/api/webhooks/shopify/route.tsWebhook HTTP endpoint

How is this guide?

On this page