Implementation Guide

Build and test your webhook endpoint for receiving PartsSource events

This cookbook walks you through building an endpoint to receive, verify, and process webhook events from PartsSource. By the end, you'll have a working receiver ready for production.

circle-info

Webhook configuration (URL and subscribed events) is set up by the PartsSource implementation and integration team. This guide assumes your webhook has already been configured and you have your signing secret.

Your responsibilities as a webhook consumer:

  1. Accept the incoming POST request

  2. Verify the signature to confirm it came from PartsSource

  3. Acknowledge receipt by returning a 2xx response within 30 seconds

  4. Process the event data

Prerequisites: your webhook signing secret (provided during setup) and a publicly accessible HTTPS endpoint.


Step 1: Build Your Endpoint

Your endpoint must accept POST requests with Content-Type: application/json, return 200 OK (or any 2xx) within 30 seconds, and verify the signature before processing. Handle duplicate deliveries idempotently using the envelope fields.

Node.js (Express)

const express = require('express');
const app = express();

app.post('/webhooks/partssource', express.json(), (req, res) => {
  // 1. Verify signature (see Step 2)
  if (!verifySignature(req)) {
    return res.status(401).send('Invalid signature');
  }

  // 2. Process the event
  const event = req.body;
  console.log(`Received: ${event.event_type}`);

  switch (event.event_type) {
    case 'order.created':
      handleOrderCreated(event.payload);
      break;
    case 'order.shipment.shipped':
      handleShipment(event.payload);
      break;
    case 'order.line.backordered':
      handleBackorder(event.payload);
      break;
    default:
      console.log(`Unhandled event type: ${event.event_type}`);
  }

  // 3. Acknowledge receipt
  res.status(200).send('OK');
});

app.listen(3000);

C# (ASP.NET)

Python (Flask)


Step 2: Verify Signatures

Always verify the X-PS-Signature header to confirm the webhook came from PartsSource and wasn't modified in transit.

PartsSource constructs a signed payload as {timestamp}.{request_body}, computes HMAC-SHA256 using your webhook secret, and sends the result as sha256={hex_digest}. To verify:

  1. Extract the X-PS-Signature and X-PS-Timestamp headers

  2. Check that the timestamp is within 5 minutes of current time

  3. Construct the signed payload: {timestamp}.{raw_request_body}

  4. Compute HMAC-SHA256 with your webhook secret

  5. Compare signatures using constant-time comparison

Node.js

C#

Python

Secret Rotation

If your signing secret is rotated, there is a 24-hour grace period where deliveries include both X-PS-Signature (new secret) and X-PS-Signature-Previous (old secret). Accept either signature during this window:


Step 3: Production Best Practices

Process Asynchronously

Acknowledge the webhook immediately with 200 OK, then process the event in a background queue. This keeps your response time fast and avoids timeouts.

Deduplicate Events

Webhook delivery uses at-least-once semantics — the same event may be delivered more than once after a retry. Use the envelope fields to detect and skip duplicates:

Store the Raw Payload

Log the full request body before processing. This helps with debugging and allows you to replay events locally if needed.

Handle Unknown Event Types Gracefully

Your endpoint may receive event types you haven't implemented handlers for. Always acknowledge these with 200 OK — returning an error triggers unnecessary retries.


Testing Checklist

Before going live, verify the following:


Troubleshooting

Signature verification failing

  1. Use the raw request body (not a re-serialized version) when computing the signature

  2. Confirm you're using the correct secret (the one provided during setup, or the rotated one)

  3. Verify your HMAC is using SHA-256 and outputting lowercase hex

  4. Construct the signed payload as {timestamp}.{body} with a literal dot separator

  5. During secret rotation, check both X-PS-Signature and X-PS-Signature-Previous

Receiving duplicate events

This is expected behavior. Webhook delivery uses at-least-once semantics. Deduplicate using the envelope fields. For production, use a persistent store (database, Redis) rather than an in-memory set.

Not receiving webhooks

Contact your PartsSource integration team to verify:

  1. Your webhook is active

  2. Your subscribed events match what you expect

  3. Your endpoint is publicly accessible over HTTPS

They can also check delivery history and replay failed deliveries on your behalf.

Last updated