Home / Blog / Amazon Price Change Webhook: Build Your Own Signed Alert, Not a SaaS Integration

Amazon Price Change Webhook: Build Your Own Signed Alert, Not a SaaS Integration

Build your own Amazon price change webhook: poll the live offer listing, compare the Buy Box price against a stored baseline, and POST a signed JSON event to any endpoint you control when it moves past a threshold. Covers HMAC-SHA256 signing with a timestamp so the receiver can reject a replayed or tampered request, and why an undelivered webhook must never advance the state.

November 22, 2026
7 min read
SellerMagnet Team
Share & Bookmark
Terminal window showing a signed Amazon price change webhook POST and its verified receipt

To build your own Amazon price change webhook, poll /amazon-product-offers for each ASIN, compare the Buy Box's landed price with a stored baseline, and POST a JSON event to any URL you control once the price moves by a threshold percentage. The script below signs every POST with HMAC-SHA256 over a timestamp and the body, so your receiver can reject a tampered or replayed request, and it never marks a price as notified unless the receiver actually answered 2xx.

Key Takeaways

  • The SellerMagnet API itself has no push mechanism for live data endpoints: every webhook here is sent by your own script after it polls, not by the API.
  • DataPipeline (/schedueler) is a separate no-code dashboard feature that can deliver scheduled results to a webhook URL; it is configured in the dashboard, not called from a script, so it is a different tool from the one this post builds.
  • Sign the timestamp plus the body (not the body alone) with HMAC-SHA256, so a captured request cannot be replayed forever with the same valid signature.
  • A webhook is marked delivered only on a 2xx response; an undelivered webhook must leave the stored baseline untouched, or a receiver outage silently swallows a real price change.
  • Retry a 429 or 5xx (the receiver may be temporarily overloaded); never retry a non-429 4xx, which means the receiver understood and rejected the request on purpose.

Does the SellerMagnet API support webhooks?

Not for the live data endpoints. /amazon-product-offers, /amazon-product-lookup and the rest are plain request/response: you call them, you get JSON back, nothing calls you. The one feature that delivers data to a webhook URL on its own is DataPipeline, a no-code dashboard scheduler that runs up to 10,000 URLs per batch on a cron schedule and can deliver the results to a webhook, email or a file destination. It is configured in the dashboard, not driven from your own code, so it solves a different problem than a script you can read, test and change. This post builds the code-driven version: a script that polls the data endpoints itself and sends its own signed webhook when something you care about actually changes.

Every reading the script can produce and what it does.
ReadingWebhookState
First sighting of an ASINno webhookbaseline price stored
Price within THRESHOLD_PCT of the baselineno webhooknothing changes
Price moves by THRESHOLD_PCT or more, either direction1 webhooksigned JSON POST, state advances
Receiver answers a 2xxdeliveredstate advances, won't resend
Receiver times out, errors, or answers 429/5xxretried up to 4x, then undeliveredstate does NOT advance
Receiver answers a non-429 4xx (payload rejected)undelivered, not retriedstate does NOT advance

How do I build the Amazon price change webhook?

read_price() reads the landed Buy Box total price from one offers call, returning None when no offer is featured rather than a misleading 0.0. main() compares it with last_notified_price in webhook_price_state.json: a first sighting stores the price as a silent baseline, a change under THRESHOLD_PCT is ignored, and a change at or above it builds a price.changed event and hands it to send_webhook(). get_with_retry comes from retry.py and ApiError/new_session from sellermagnet.py, both from the Python quickstart. Malformed ASINs are filtered before any call, since the offers endpoint bills a typo like any other request.

webhook_price_alert.py - poll offers, compare to a baseline, send one signed webhook per change

import hashlib
import hmac
import json
import os
import re
import time

import requests

from retry import get_with_retry
from sellermagnet import ApiError, new_session

MARKETPLACE_ID = "ATVPDKIKX0DER"                  # amazon.com
ASINS = ["B0CL61F39H", "B0EXAMPLE2", "B0EXAMPLE3"]
THRESHOLD_PCT = 1.0                               # fire on a change of at least 1% in either direction
STATE_FILE = "webhook_price_state.json"
ASIN_RE = re.compile(r"\A[A-Z0-9]{10}\Z")          # offers calls are billed even for a typo, so filter first

WEBHOOK_URL = os.environ["PRICE_WEBHOOK_URL"]      # YOUR endpoint; this is not a SellerMagnet feature
WEBHOOK_SECRET = os.environ["PRICE_WEBHOOK_SECRET"].encode()
MAX_CLOCK_SKEW = 300                               # seconds a receiver should still accept (replay window)


def read_price(session, asin: str) -> float | None:
    """Landed Buy Box total price, or None when nothing is featured (never 0.0)."""
    data = get_with_retry(session, "amazon-product-offers", asin=asin, marketplaceId=MARKETPLACE_ID)
    box = data.get("buyBox") or {}
    price = box.get("totalPrice")
    return price if isinstance(price, (int, float)) else None


def load_state() -> dict:
    try:
        with open(STATE_FILE) as f:
            return json.load(f)
    except FileNotFoundError:
        return {}


def save_state(state: dict) -> None:
    with open(STATE_FILE, "w") as f:
        json.dump(state, f)


def sign(body: bytes, timestamp: int) -> str:
    """HMAC-SHA256 over 'timestamp.body', the same construction Stripe/GitHub use so a signature
    cannot be replayed with a different timestamp and a captured body cannot be replayed after
    MAX_CLOCK_SKEW seconds (the receiver checks the timestamp itself, see verify_webhook.py)."""
    signed_payload = str(timestamp).encode() + b"." + body
    return hmac.new(WEBHOOK_SECRET, signed_payload, hashlib.sha256).hexdigest()


def send_webhook(event: dict, attempts: int = 4) -> bool:
    """POST a signed event. Delivered only means a 2xx was returned for THIS attempt; the caller
    marks the price as notified only when this returns True, so a down receiver gets the same
    event again on the next run instead of a silent drop."""
    body = json.dumps(event, separators=(",", ":"), sort_keys=True).encode()
    timestamp = int(time.time())
    headers = {
        "Content-Type": "application/json",
        "X-SM-Timestamp": str(timestamp),
        "X-SM-Signature": "sha256=" + sign(body, timestamp),
    }
    for attempt in range(1, attempts + 1):
        try:
            resp = requests.post(WEBHOOK_URL, data=body, headers=headers, timeout=10)
        except requests.RequestException:
            if attempt == attempts:
                return False
            time.sleep(min(2 ** attempt, 30))
            continue
        if 200 <= resp.status_code < 300:
            return True
        if resp.status_code in (429, 500, 502, 503, 504) and attempt < attempts:
            time.sleep(min(2 ** attempt, 30))
            continue
        return False                      # a 4xx other than 429 means the payload itself was rejected
    return False


def main() -> None:
    session = new_session()
    state = load_state()
    sent = 0
    for asin in ASINS:
        if not ASIN_RE.match(asin):
            print(f"SKIP {asin}: not a well-formed ASIN, not billed")
            continue
        try:
            price = read_price(session, asin)
        except ApiError as err:
            if err.status in (401, 403):
                print(f"STOP: {err.status} on {asin}, run ended early (free, not billed)")
                break
            print(f"SKIP {asin}: {err.status} {err}")      # 404 billed-not-retried, 502/503 billed-and-capped
            continue
        if price is None:
            print(f"SKIP {asin}: no featured offer right now")
            continue
        prior = state.get(asin, {}).get("last_notified_price")
        if prior is None:
            state[asin] = {"last_notified_price": price}       # first sighting: store, never alert on it
            print(f"BASELINE {asin}: {price:.2f}")
            continue
        pct = abs(price - prior) / prior * 100
        if pct < THRESHOLD_PCT:
            print(f"NOCHANGE {asin}: {price:.2f}, {pct:.2f}% < {THRESHOLD_PCT}% threshold")
            continue
        event = {"event": "price.changed", "asin": asin, "marketplaceId": MARKETPLACE_ID,
                  "oldPrice": prior, "newPrice": price, "pctChange": round(pct, 2)}
        delivered = send_webhook(event)
        if delivered:
            state[asin] = {"last_notified_price": price}
            sent += 1
            print(f"SENT {asin}: {prior:.2f} -> {price:.2f} ({pct:.1f}%)")
        else:
            print(f"UNDELIVERED {asin}: {price:.2f}, will retry next run (state not advanced)")
    save_state(state)
    print(f"{len(ASINS)} checked, {sent} webhook(s) delivered")


if __name__ == "__main__":
    main()

Three runs over the same 3 ASINs (illustrative ASINs and prices)

--- run 1, first check (illustrative ASINs) ---
BASELINE B0CL61F39H: 19.99
BASELINE B0EXAMPLE2: 44.50
BASELINE B0EXAMPLE3: 9.99
3 checked, 0 webhook(s) delivered
--- run 2, no changes ---
NOCHANGE B0CL61F39H: 19.99, 0.00% < 1.0% threshold
NOCHANGE B0EXAMPLE2: 44.50, 0.00% < 1.0% threshold
NOCHANGE B0EXAMPLE3: 9.99, 0.00% < 1.0% threshold
3 checked, 0 webhook(s) delivered
--- run 3, one confirmed change ---
SENT B0CL61F39H: 19.99 -> 17.49 (12.5%)
NOCHANGE B0EXAMPLE2: 44.60, 0.22% < 1.0% threshold
NOCHANGE B0EXAMPLE3: 9.99, 0.00% < 1.0% threshold
3 checked, 1 webhook(s) delivered

How does the HMAC signature actually protect the receiver?

sign() builds str(timestamp) + "." + body and runs HMAC-SHA256 over it with a secret only you and your receiver know, the same timestamp-plus-body construction Stripe and GitHub use for their own outgoing webhooks. The receiver recomputes the same HMAC from the body it actually received and the X-SM-Timestamp header, then compares it to X-SM-Signature with hmac.compare_digest, a constant-time comparison that does not leak how many leading bytes matched through response timing. Mixing the timestamp into the signed bytes, not just adding it as an unsigned header, stops an attacker from pairing a captured valid signature with a different timestamp.

verify_webhook.py - what the receiver runs before trusting the body

import hashlib
import hmac
import os
import time

WEBHOOK_SECRET = os.environ["PRICE_WEBHOOK_SECRET"].encode()
MAX_CLOCK_SKEW = 300


def verify(body: bytes, timestamp_header: str, signature_header: str, now: int | None = None) -> bool:
    now = int(time.time()) if now is None else now
    try:
        timestamp = int(timestamp_header)
    except (TypeError, ValueError):
        return False
    if abs(now - timestamp) > MAX_CLOCK_SKEW:
        return False                      # too old (or clock-skewed): reject, do not process
    expected = "sha256=" + hmac.new(WEBHOOK_SECRET, str(timestamp).encode() + b"." + body,
                                     hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature_header or "")
Blueprint flow: offers check per ASIN, baseline compare, then one signed webhook POST
Only a confirmed 2xx advances the stored price; everything else is retried next run.

Why must an undelivered webhook leave the baseline untouched?

Because the alternative loses real price changes silently. If the script advanced last_notified_price as soon as it built the event, a receiver that is down for one run would still cause the next comparison to run against the NEW price, find no further change, and never alert on the drop that failed to deliver. Leaving the stored price at the old value means the same event, with the same oldPrice, is rebuilt and resent on the next run until a 2xx actually lands. A 429 or 5xx is retried with backoff inside the same run because it usually means the receiver is briefly unavailable; a non-429 4xx is not retried, because the receiver understood the request and rejected it on purpose, and a retry would only repeat the same rejection.

Why each outcome is or is not retried.
OutcomeRetried this runState advances
2xxN/A, deliveredyes
429 or 5xxyes, up to 4 attempts with backoffonly if a later attempt succeeds
Non-429 4xxnono
Connection error / timeoutyes, up to 4 attempts with backoffonly if a later attempt succeeds
Blueprint table of the four checks a receiver runs before trusting a signed webhook
Any one of these failing means: reject, do not process the body.

What should the receiver do with a verified event?

Answer 2xx as soon as the signature and timestamp check out, before doing anything slow: the sender's retry budget is only 4 attempts with capped backoff, and a receiver that takes longer than the sender's 10-second timeout to answer looks identical to one that is down. Queue the actual work (updating a dashboard, sending an internal notification, writing to a database) after responding, not before. A price.changed event carries asin, marketplaceId, oldPrice, newPrice and pctChange; it never carries your API key or any credential, since the receiver only needs the shared webhook secret to trust the message.

How many credits does this cost?

One /amazon-product-offers call per tracked ASIN per check, the same as the Buy Box alert family: a 404 is billed once and not retried, 502/503 are billed on every attempt up to the cap, a 500 is refunded, and the free gate errors (400, 401, 403, 429) cost nothing. The Buy Box monitoring interval guide compares check intervals and their credit cost in detail; this script adds no extra API calls of its own, only the outgoing POST to your receiver, which is never billed by SellerMagnet since it never touches the API.

Frequently Asked Questions

Does the SellerMagnet API push price changes to me on its own?

No. Every endpoint is a plain request/response GET; nothing calls your server unless you poll and send the webhook yourself, exactly as this script does. DataPipeline is the one feature that delivers results to a webhook URL, but it is a no-code dashboard scheduler, not something a script calls, so it is not part of this build.

Why sign the webhook instead of just POSTing the JSON?

Without a signature, anyone who learns or guesses your receiver's URL can POST a fake price drop. HMAC-SHA256 over the timestamp and body lets the receiver prove the request came from someone who holds the shared secret, and reject anything else.

Why include a timestamp in the signed data instead of signing the body alone?

Signing the body alone lets a captured request be replayed forever with the exact same valid signature. Mixing the timestamp into the signed bytes and rejecting anything older than MAX_CLOCK_SKEW gives a captured request a short, bounded shelf life.

Why does an undelivered webhook not update the stored price?

The state file only advances on a confirmed 2xx. If it advanced anyway, a receiver outage would silently absorb a real price change: the next run would compare against the new price, see no difference, and never alert on the drop that was already missed once.

Why retry a 500 or 429 but not a 400?

A 429 or 5xx can mean the receiver was briefly overloaded or restarting, so a second attempt with backoff can genuinely succeed. A non-429 4xx means the receiver understood the request and rejected it on purpose (bad signature, wrong path); retrying sends the exact same request for the exact same rejection.

How do I pick THRESHOLD_PCT?

Start around 1 to 2% for a Buy Box price watch. Below that, ordinary cent-level rounding noise on some marketplaces can fire the webhook every check; well above it, you miss changes that matter for thin margins. There is no single correct value, only a trade-off against noise.

Bottom line: the API never pushes to you, so build the push yourself: poll /amazon-product-offers, compare against a stored baseline, and sign every outgoing POST with a timestamp-bound HMAC so the receiver can tell a genuine, fresh event from a replayed or tampered one. For a specific delivery channel instead of a generic endpoint you run yourself, see the Buy Box lost Slack alert or the price drop Discord alert; a free account includes 150 credits to try it.

Ready to Extract Amazon Data at Scale?

Start building with SellerMagnet API today. Real-time product data, competitive pricing, and review analytics at your fingertips.

150 free API credits • No credit card required • Cancel anytime