# Shopify new order notifications on your phone

> Get a push notification with the customer, total and item count every time a new order is placed in your store, with a button to open the order.

- Company: Shopify (https://www.justpush.io/recipes/shopify)
- Event: `orders/create` (Order creation)
- Tags: E-commerce, Orders
- Install: https://studio.justpush.io/recipes/shopify/order-created
- Web page: https://www.justpush.io/recipes/shopify/order-created

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. In your Shopify admin, go to Settings > Notifications > Webhooks.
3. Click Create webhook and pick the Order creation event.
4. Paste your webhook URL (shown in Studio after install) as the URL, choose JSON and save.
5. Copy the signing secret shown under the webhook list into JustPush.

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// Shopify → orders/create
// Fires when a new order is placed in a Shopify store.
// Docs: https://shopify.dev/docs/api/admin-rest/latest/resources/webhook
//
// Paste this into a JustPush Studio integration and point your Shopify
// "Order creation" webhook at the integration's endpoint URL.

function handleRequest(request) {
    const order = request.body

    // Ignore anything that isn't a well-formed order payload.
    if (!order || !order.id) {
        console.log("Not a Shopify order payload — skipping")
        return null
    }

    const currency = order.currency || "USD"
    const total = order.total_price ?? "0.00"
    const customer = order.customer
        ? `${order.customer.first_name ?? ""} ${order.customer.last_name ?? ""}`.trim()
        : "Guest"

    const itemCount = Array.isArray(order.line_items)
        ? order.line_items.reduce((sum, item) => sum + (item.quantity ?? 1), 0)
        : 0

    return {
        title: `🛒 New order ${order.name ?? `#${order.order_number}`}`,
        message: `${customer} spent ${total} ${currency} on ${itemCount} item(s)`,
        topic: "Shopify Orders",
        priority: 1, // High — a sale is worth surfacing promptly
        sound: "cashregister",
        buttons: order.order_status_url
            ? [{ cta: "View order", url: order.order_status_url }]
            : [],
    }
}
```

## Shopify orders/create webhook payload (sample)

```json
{
  "id": 820982911946154500,
  "name": "#1001",
  "currency": "EUR",
  "customer": {
    "email": "jane@example.com",
    "last_name": "Doe",
    "first_name": "Jane"
  },
  "line_items": [
    {
      "price": "12.00",
      "title": "Enamel Pin",
      "quantity": 2
    },
    {
      "price": "25.00",
      "title": "Sticker Pack",
      "quantity": 1
    }
  ],
  "total_price": "49.00",
  "order_number": 1001,
  "order_status_url": "https://your-store.myshopify.com/orders/abc123"
}
```

## Signature check

Shopify signs every webhook with an HMAC-SHA256 hash of the request body, sent in the X-Shopify-Hmac-Sha256 header and made with your store's signing secret. JustPush checks it before the code runs.

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into Shopify and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
