Docs

Webhooks

Recustomer → Merchant (notification)

Recustomer sends POST notifications to the endpoint the merchant provides when a return is created or updated, or when a shipping status is updated.

In the admin Webhook settings, register each endpoint as a pair of an event (return created, return updated, shipping status updated) and a callback URL. Recustomer sends only the events you registered. The body does not contain the event type, so register a separate URL for each event to tell them apart.

How notifications are sent

  • The body is UTF-8 JSON (Content-Type: application/json), and the User-Agent is Recustomer-Webhook/1.0
  • Destinations must be HTTPS (TLS 1.2 or later) on port 443. Recustomer does not send to destinations that cannot be reached from the internet, such as internal networks
  • Returning a 2xx status means success. The content of the response body is not checked, so the body can be empty. 3xx, 4xx, 5xx, timeouts, and name resolution or connection errors are treated as failures. Even with 2xx, the attempt is treated as a failure if the body cannot be received in full, for example if the connection drops partway or the body is shorter than Content-Length
  • If the response headers do not arrive within 10 seconds of starting the connection, the attempt is aborted and treated as a failure. The time spent connecting and on the TLS handshake counts toward these 10 seconds. The attempt is also aborted if receiving the response body stalls for 10 seconds
  • Return 2xx as soon as your endpoint receives a notification. For work that takes time, save the notification to a queue or database, return 2xx, and do the work afterwards
  • The order of delivery is not guaranteed. The same event may arrive more than once, so record each X-Recustomer-Event-Id you have processed, for example in a database, and skip notifications whose ID is already recorded

Retries after a failure

When a delivery fails, Recustomer automatically sends the same notification again. The wait before each retry starts at 2 minutes and doubles with each retry (exponential backoff). If all 8 attempts, including the first, fail, Recustomer stops delivering the event. Currently, there is no mechanism to resend a stopped event later. An event that your endpoint failed to receive in all 8 attempts does not arrive, so check stopped events in "Webhook 配信ログ" (Webhook delivery log).

  1. 1stWhen the event occurs
  2. Wait 2 min2ndAbout 2 min later
  3. Wait 4 min3rdAbout 6 min later
  4. Wait 8 min4thAbout 14 min later
  5. Wait 16 min5thAbout 30 min later
  6. Wait 32 min6thAbout 1 h 2 min later
  7. Wait 64 min7thAbout 2 h 6 min later
  8. Wait 128 min8thAbout 4 h 14 min later
  9. Delivery stoppedIf the 8th attempt also fails
  • Once your endpoint returns 2xx at any attempt, no further retries are made
  • The times are estimates counted from the first attempt. Each wait starts after the previous attempt fails, and the time each attempt takes (up to about 10 seconds) and the time until the retry starts are added, so actual times can be later than shown
  • Even if your endpoint is temporarily down, you can receive the notification with a retry after it recovers. Currently, the last retry is made about 4 hours 14 minutes or more after the first attempt
  • Retries keep the same body and X-Recustomer-Event-Id. The signature is created again with the time of each attempt
  • You can check delivery results in "Webhook 配信ログ" (Webhook delivery log) under "Analytics β" in the admin's left menu. For each event, it shows the delivery time, the number of attempts, the HTTP status, any error, and the body that was sent

Redirects (3xx)

Recustomer does not follow redirects. A 3xx response is treated as a failure and retried like any other failure. If your endpoint returns 3xx every time, all 8 attempts fail and delivery of the event stops.

Register the final URL that does not redirect as the callback URL. If "Webhook 配信ログ" (Webhook delivery log) shows a 3xx HTTP status, check the Location header of the response with curl -i -X POST <callback URL>, and register that redirect target instead. URLs like these tend to return redirects:

  • The host differs from your endpoint's actual URL, such as with or without www, or a different domain
  • The path differs from your endpoint's actual URL by a trailing /
  • Your endpoint requires authentication and redirects to a login page
  • A Google Apps Script web app that returns its result with ContentService. Apps Script returns the result from a different URL through a 302, so even when your script has finished processing, Recustomer treats the attempt as a failure and sends the same notification again. Use an endpoint that returns 2xx directly

Recustomer does not follow redirects for these reasons:

  • A 3xx response does not show that your endpoint received the notification. Only a 2xx response does
  • Following a 301, 302, or 303 can turn the POST into a GET and drop the body. If the login page at the redirect target returns 200, the notification looks successful even though it never arrived
  • The body contains buyers' personal information. Recustomer sends the body and signature only to the registered URL

Verifying signatures

Recustomer signs the body of each notification and sends the signature in the X-Recustomer-Signature-256-V2 header, and the signing time (Unix seconds) in the X-Recustomer-Signature-256-V2-Timestamp-Epoch header. Verify the signature in your endpoint before parsing the body as JSON.

  1. In the webhook settings of the admin screen, open "Show secret" for the registered webhook to get its signing secret
  2. Concatenate the X-Recustomer-Signature-256-V2-Timestamp-Epoch value, ., and the received body as raw bytes (before parsing it as JSON), in this order, and compute its HMAC-SHA256 with the signing secret as the key. Encode the result as lowercase hexadecimal, without a prefix
  3. Compare the value from step 2 with the X-Recustomer-Signature-256-V2 header using a constant-time comparison. If they don't match, or if the signing time differs from the current time by more than 5 minutes, don't process the notification

Each webhook (a pair of event and URL) has its own signing secret, and you can recreate it with "シークレットを再発行" (Regenerate secret). Currently, retries of events that occurred before the secret was regenerated are signed with the old secret. Retries can continue for 4 hours 14 minutes or longer after the first attempt, so keep accepting the old secret for about 5 hours after regenerating it. If you stop accepting the old secret right away, notifications retried in the meantime are rejected by your endpoint, and delivery of those events stops.

The signing secret is a 64-character hexadecimal string. Treat it like a password: don't write it in source code or commit it to a repository, and keep it in environment variables or a secrets management service. If it may have leaked, recreate it with "シークレットを再発行" (Regenerate secret).

In frameworks that apply CSRF checks to POST requests, such as Rails and Django, exclude your endpoint's route from the CSRF check. Webhook notifications carry no CSRF token and are verified by their signature instead.

"Endpoint implementation" on each webhook page has code for these steps.

© Recustomer, Inc.