Most "AI dropshipping agent" pitches skip the boring part: before any model gets involved, you need a webhook receiver that can prove an order notification actually came from your store and not from someone guessing your endpoint URL. That verification step is the whole foundation — get it wrong and you're processing forged orders; get it right and everything downstream (drafting supplier emails, updating customers) is safe to automate.
How the pieces fit together
1. Register the webhook: Subscribe your app to the orders/create topic from your store's admin so Shopify pushes a payload to your endpoint the moment an order comes in.
2. Verify the signature first: Every webhook request carries an X-Shopify-Hmac-SHA256 header. Recompute the HMAC over the raw request body using your app's secret and compare it with a constant-time check before trusting anything in the payload.
3. Hand off to the model, then to a human where it matters: Once verified, pass the order details to an LLM to draft the supplier purchase order and the customer notification — but route anything above a value threshold, or anything the model flags as unusual, to a person before it goes out.
# Shopify order webhook receiver with HMAC-SHA256 verification
import base64, hashlib, hmac, os
from fastapi import FastAPI, Header, HTTPException, Request
app = FastAPI()
SHOPIFY_APP_SECRET = os.environ["SHOPIFY_APP_SECRET"].encode()
@app.post("/webhooks/orders-create")
async def handle_order_created(request: Request, x_shopify_hmac_sha256: str = Header(None)):
raw_body = await request.body() # must read raw bytes before any body parsing
digest = hmac.new(SHOPIFY_APP_SECRET, raw_body, hashlib.sha256).digest()
computed_hmac = base64.b64encode(digest).decode()
if not hmac.compare_digest(computed_hmac, x_shopify_hmac_sha256 or ""):
raise HTTPException(status_code=401, detail="Invalid webhook signature")
# Only past this point do we trust the payload enough to act on it
return {"status": "accepted"}
| Setup | What breaks first | Fix |
|---|---|---|
| No signature check | Anyone who finds your endpoint URL can submit fake "orders" | Verify HMAC on every request before processing it |
| Body parsed before hashing | Legitimate webhooks fail verification (hash mismatch) | Read and hash the raw request bytes first |
Once orders are flowing through a verified endpoint, the AI layer is genuinely the easy part — a single prompt can turn an order payload into a clear supplier email or a friendly shipping update. The engineering work that actually protects your store is the boring authentication step above it.
Practical Challenge
Modify the script above so a failed signature check gets logged to a file with the offending IP and timestamp, instead of just returning a 401 — in production you want to be able to tell a misconfigured secret apart from a real spoofing attempt.
Concept Check
Sources & Further Reading
- Shopify Dev — Verify webhook deliveries — the official HMAC verification steps this article's code follows.
- Shopify Dev — Deliver webhooks through HTTPS — how to subscribe an endpoint to order events.
- OpenAI — Chat Completions guide — the API used to draft supplier/customer messages from order data.
AI