Spaces

Webhooks

Spaces sends each event to your URL the moment it happens, as a signed POST. Your AI agent hears about a new message, a failed send or a signed-out account without asking again and again.

Create one

POST https://api.spacesos.com/v1/messaging/webhooks
Authorization: Bearer spc_live_...

{ "url": "https://example.com/spaces", "events": ["message.received", "message.failed", "account.disconnected"] }

The answer holds the signing secret once: keep it. events defaults to message.received and account.status. Pass account_id for one account only. Up to 10 per workspace. An agent key can also have its own: POST /v1/events/webhooks (MCP create_event_webhook).

Events

EventWhen
message.receivedSomeone wrote to a connected account. Carries the text (up to 1,000 characters), the sender and chat_id.
conversation.startedThe first message in a chat Spaces has not seen: started_by them or account.
message.sentA send through Spaces went out.
message.failedA send through Spaces did not go out, or the platform did not confirm it. code, error_category, next_step, and maybe_sent when it may have gone out.
message.delivered, message.readThe platform reported the message delivered or read.
message.reaction, message.edited, message.deletedA reaction, an edit or a deletion in a chat.
comment.receivedA new comment on one of the account's posts.
post.published, post.failed, post.deletedA post made through Spaces went live, did not go out (with why), or is gone.
account.statusThe account's status changed.
account.disconnectedThe account stopped working: reason, reason_text and needs_reconnect.
account.reconnectedThe account works again.
account.restingThe platform asked Spaces to slow down: stop writing until resting_until.
approval.pendingA write is waiting for the owner's approval.
chat.handed_over, chat.handed_backA person on the team took a chat, or gave it back to the AI agent.
follower.new, invitation.received, invitation.acceptedA new follower, or a LinkedIn invitation.
link.clicked, ad.chat_startedSomeone opened a tracked link, or started a chat from an ad.

Every event is { id, type, created_at, data }. The id (evt_...) is the same on every retry, so keep the ids you have handled and skip a repeat. Text other people wrote is screened first, and is cut to 1,000 characters.

Verify every delivery

Each POST has these headers:

  • Spacesos-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>" with the secret>
  • Spacesos-Event-Id and Spacesos-Event-Type
  • Spacesos-Redelivery: 1 on a delivery you asked to send again

Compute the HMAC over the raw body, compare in constant time, and reject a t more than 5 minutes from your clock so an old delivery cannot be replayed.

Node.js

import crypto from 'node:crypto';

// rawBody: the request body exactly as received (a Buffer or string), before JSON parsing.
export function verifySpaces(rawBody, header, secret, toleranceSeconds = 300) {
  const parts = Object.fromEntries(String(header).split(',').map((p) => p.split('=')));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false; // too old: a replay
  const expected = crypto.createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
  const given = Buffer.from(parts.v1 ?? '', 'hex');
  return given.length === 32 && crypto.timingSafeEqual(given, Buffer.from(expected, 'hex'));
}

// Express: app.post('/spaces', express.raw({ type: 'application/json' }), (req, res) => { ... })
//   if (!verifySpaces(req.body, req.get('Spacesos-Signature'), process.env.SPACES_WEBHOOK_SECRET)) return res.sendStatus(400);
//   const event = JSON.parse(req.body);
//   if (alreadyHandled(event.id)) return res.sendStatus(200); // a retry of an event you have
//   res.sendStatus(200); then handle the event.

Python

import hashlib, hmac, time

def verify_spaces(raw_body: bytes, header: str, secret: str, tolerance_seconds: int = 300) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    t = int(parts.get("t", "0"))
    if not t or abs(time.time() - t) > tolerance_seconds:
        return False  # too old: a replay
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))

Retries and failures

Answer with a 2xx within 5 seconds, then do the work. Any other answer, or no answer, is tried again after 30 seconds, 2, 10 and 30 minutes, then 1, 2, 4, 8 and 8 hours: about a day in all. A 4xx other than 408 and 429 is not retried. A delivery that fails every try stays in the delivery log as failed. After 50 events in a row fail, the webhook turns off; create it again once your endpoint works.

Test events and the delivery log

  • POST /v1/messaging/webhooks/{id}/test with { "type": "message.failed" } sends one signed example now, marked test: true, and answers with the status your server gave.
  • GET /v1/messaging/webhooks/{id}/deliveries lists the past week: event, status (pending, delivered, failed), your status code and the number of attempts. It never holds a message body.
  • A key's own webhook has the same: POST /v1/events/webhooks/{id}/test and GET /v1/events/webhooks/{id}/deliveries, with the read permission.
  • POST /v1/messaging/webhooks/{id}/deliveries/{delivery_id}/redeliver sends one again now, with the same event id. A message event comes without its text: read the message through the API.

No public URL?

An AI agent that cannot take webhooks reads the same events with GET /v1/events?after=<cursor>&wait=50 (MCP wait_for_events). It returns the moment an event lands and never touches the platform, so it is safe to call in a loop. Events are kept 14 days.

Error answers: every code. Every route: the API reference.