How to set up webhooks

How to set up webhooks

A webhook sends consignment events to your own system as they happen, so it can react without checking MachShip for changes.

Before you start

  • You need the Company Automations permission at Create/Delete.
  • You need an endpoint in your system that accepts HTTPS requests on port 443.

How to set up a webhook

  1. Go to Admin > Rules > Automations and click Create Automation.
  2. In Details, enter a Name, for example "Send events to our system", and choose the Company.
  3. In Trigger, choose When something happens and the event, for example Consignment ยท Created. Optionally, add Filters.
  4. In Do this, choose Fire a webhook.
  5. Choose the Method: POST or PUT.
  6. Enter the Endpoint URL. It must start with https and use port 443.
  7. Optionally, enter a Signing secret of at least 32 characters, so your system can check that each delivery came from MachShip. Leave it empty to send deliveries unsigned.

The Fire a webhook action with the method, endpoint URL and signing secret

  1. Optionally, under Custom headers, click Add header to send a header with every delivery, for example an API key your endpoint expects. You cannot use Content-Type, Idempotency-Key, Accept-Encoding, X-MachShip headers or connection headers.
  2. Click Save.

Custom headers with one header added

Result

Each time the event happens to a matching consignment, MachShip sends a request to your endpoint. Check each delivery in View logs.

What your endpoint receives

  • A JSON body with four fields: id (the consignment ID), companyId, carrierConsignmentId and eventData. To get more detail, call the MachShip API with the ID.
  • The headers X-MachShip-Event, X-MachShip-Timestamp and Idempotency-Key, plus your custom headers.
  • With a signing secret, an X-MachShip-Signature header: sha256= followed by the HMAC-SHA256 of the X-MachShip-Timestamp, X-MachShip-Event and Idempotency-Key values and the raw body, joined by new lines. Recompute it with your secret, compare the two, and reject deliveries with an old timestamp.

Retries

  • A 2xx response is a success.
  • A 5xx response or no response within 10 seconds is retried.
  • A 3xx or 4xx response is a failure and is not retried. Redirects are not followed.

Use the Idempotency-Key header to ignore a delivery your system has already processed.

Change a webhook later

Saved URLs, secrets and header values are hidden for security. Click Replace to enter a new one. If you change the Endpoint URL, enter the signing secret and header values again.

A saved webhook, with the endpoint URL, secret and header value hidden

Related guides