> ## Documentation Index
> Fetch the complete documentation index at: https://docs.followr.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Verify webhook requests

> Check the X-Company-Secret header on every request.

Anyone who knows your webhook URL can send it a request. Check the secret before you trust one.

## What Followr sends

The company's secret, as is, in the `X-Company-Secret` header:

```http theme={null}
POST /webhooks/followr HTTP/1.1
Content-Type: application/json
X-Company-Secret: q8Vf2LxN0aZr7TbK4mWc9YhD1sJ6pE3u
```

* **Not a signature.** The body isn't signed and has no timestamp. Compare the header with your stored secret, and parse the JSON as usual.
* **32 letters and digits**, the same on every request, unique to the company.
* **Find it** in [**Company settings > Webhooks**](https://app.followr.ai/company-settings/webhooks), or in `webhook_secret` from `GET /companies/{id}`.

> [!WARNING]
>
> Anyone who sees one request can send fake ones that pass, and the secret can't be changed. Use `https://`, never log headers, and make your handler [idempotent](https://docs.followr.ai/webhooks/overview.md#ordering-and-duplicates): replays aren't blocked.

## Verify a request

**1. Read the header**

Reject the request if `X-Company-Secret` is missing or empty.

**2. Compare in constant time**

A plain `==` or `===` stops at the first different character, which leaks how much of a guess was right.

**3. Answer**

No match: `401`, and ignore the body. Match: `200`, then process the event.

The examples read the secret from the `FOLLOWR_WEBHOOK_SECRET` environment variable.

```javascript Node.js (Express) theme={null}
// npm install express
// FOLLOWR_WEBHOOK_SECRET=your_secret node server.js
const crypto = require("node:crypto");
const express = require("express");

const WEBHOOK_SECRET = process.env.FOLLOWR_WEBHOOK_SECRET;
if (!WEBHOOK_SECRET) {
  throw new Error("Set FOLLOWR_WEBHOOK_SECRET");
}

// Hash both values first: timingSafeEqual needs buffers of the same length,
// and comparing digests does not reveal the secret's length.
function secretMatches(received) {
  if (typeof received !== "string" || received === "") {
    return false;
  }
  const a = crypto.createHash("sha256").update(received).digest();
  const b = crypto.createHash("sha256").update(WEBHOOK_SECRET).digest();
  return crypto.timingSafeEqual(a, b);
}

function handlePostStatus(event) {
  console.log(`Post ${event.id} on ${event.social_network_type} is now ${event.status}`);
}

const app = express();

app.post("/webhooks/followr", express.json(), (req, res) => {
  if (!secretMatches(req.get("X-Company-Secret"))) {
    return res.sendStatus(401);
  }

  res.sendStatus(200);

  // Answer first, then work. In production, put the event on a queue here.
  setImmediate(() => handlePostStatus(req.body));
});

app.listen(3000, () => console.log("Listening on http://localhost:3000"));
```

```python Python (Flask) theme={null}
# pip install flask
# FOLLOWR_WEBHOOK_SECRET=your_secret flask --app server run --port 3000
import hmac
import os

from flask import Flask, abort, request

WEBHOOK_SECRET = os.environ["FOLLOWR_WEBHOOK_SECRET"]

app = Flask(__name__)


def secret_matches(received: str) -> bool:
    if not received:
        return False
    # compare_digest takes the same time wherever the values differ.
    return hmac.compare_digest(received.encode(), WEBHOOK_SECRET.encode())


@app.post("/webhooks/followr")
def followr_webhook():
    if not secret_matches(request.headers.get("X-Company-Secret", "")):
        abort(401)

    event = request.get_json(force=True)
    # In production, put the event on a queue here and return at once.
    print(f"Post {event['id']} on {event['social_network_type']} is now {event['status']}")
    return "", 200
```

```php PHP theme={null}
<?php
// FOLLOWR_WEBHOOK_SECRET=your_secret php -S localhost:3000 webhook.php

$expected = getenv('FOLLOWR_WEBHOOK_SECRET') ?: '';
$received = $_SERVER['HTTP_X_COMPANY_SECRET'] ?? '';

// hash_equals takes the same time wherever the values differ.
if ($expected === '' || $received === '' || !hash_equals($expected, $received)) {
    http_response_code(401);
    exit;
}

$event = json_decode(file_get_contents('php://input'), true, 512, JSON_THROW_ON_ERROR);

http_response_code(200);

// In production, put the event on a queue here and return at once.
error_log(sprintf(
    'Post %d on %s is now %s',
    $event['id'],
    $event['social_network_type'],
    $event['status']
));
```

## One URL for several companies

Compare the header with each company's secret in constant time. The match tells you the company; no match means `401`.

```python Python theme={null}
import hmac

# Load these from your secret store.
SECRETS_BY_COMPANY = {
    1287: "q8Vf2LxN0aZr7TbK4mWc9YhD1sJ6pE3u",
    1288: "Zp4Lm9Qx2Vb7Nc5Rt1Ws8Kd3Jf6Hg0Ya",
}


def company_for(received: str):
    match = None
    for company_id, secret in SECRETS_BY_COMPANY.items():
        if received and hmac.compare_digest(received.encode(), secret.encode()):
            match = company_id
    return match
```

## Test your endpoint

Replace `YOUR_WEBHOOK_SECRET` with your secret. Expect `200`, and `401` with any other value.

```bash theme={null}
curl --request POST http://localhost:3000/webhooks/followr \
  --header "Content-Type: application/json" \
  --header "X-Company-Secret: YOUR_WEBHOOK_SECRET" \
  --data '{"id":240551,"social_network_type":"instagram","title":null,"description":"Our winter blend is here. Come taste it this weekend.","status":"published","status_message":null,"media_fetch_failures":null,"external_id":"17912345678901234","link":null,"preferences":{"media_product_type":"FEED"},"created_at":"2026-12-10T16:20:05.000000Z","updated_at":"2026-12-15T09:30:42.000000Z","published_at":"2026-12-15T09:30:41.000000Z"}' \
  --write-out "%{http_code}\n"
```

## Troubleshooting

> [accordion] The header is empty
>
> The URL was set when the company was created, so there's no secret. Remove the URL (**Remove** in the app, or `"webhook_posts_url": null` in `PUT /companies/{id}`), set it again, then read `webhook_secret`.

> [accordion] The header never matches
>
> Check you stored this company's secret. Copy it again, with no spaces or line breaks around it.

> [accordion] The secret leaked
>
> [Contact support](https://docs.followr.ai/support.md). Until it's replaced, read the post with `GET /posts/{id}` before you act on a request.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.