Webhook

Webhook

Sublaunch invia una richiesta HTTPS al tuo server nel momento in cui un membro si iscrive, annulla o se ne va, un pagamento va a buon fine, un lead lascia la sua email, viene pubblicato un post o un commento, o si iscrive un affiliato. È firmata, così sai che arriva da noi.

Configura un endpoint

Aggiungi un endpoint nella pagina API del Sublaunch nell'app, oppure con Crea un endpoint webhook. Dagli un URL HTTPS pubblico e i tipi di evento che vuoi, poi conserva il secret che restituisce per verificare le firme.

  • Solo HTTPS, sulla porta 443 o 8443, nessuna credenziale nell'URL e nessun indirizzo privato, di loopback o link local.
  • Fino a 10 endpoint per Sublaunch.
  • filters.tier_ids limita gli eventi di membri e pagamenti che riceve un endpoint ai membri di alcuni livelli. Un evento senza livello, come un lead o un post, passa sempre.
  • Invia un evento di test per verificare il tuo server prima che arrivino gli eventi reali.

I webhook sono inclusi nei piani Business e Premium. Se il proprietario del Sublaunch passa a un piano inferiore, i suoi endpoint restano ma non inviano nulla finché il proprietario non torna a Business o Premium.

POST/v1/webhook_endpoints
curl -X POST https://api.sublaunch.com/v1/webhook_endpoints \
  -H "Authorization: Bearer $SUBLAUNCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/webhooks/sublaunch",
    "events": ["member.joined", "payment.succeeded"],
    "description": "CRM sync",
    "filters": {
      "tier_ids": ["tier1"]
    }
  }'

Tipi di evento

Ogni evento ha la stessa struttura. Il suo data dipende dal suo type.

TipoInviato quando
member.joinedUn'iscrizione diventa attiva, per un nuovo membro a pagamento o gratuito. Arriva una sola volta per ogni iscrizione.
member.leftUn'iscrizione attiva termina e il suo status diventa canceled. Arriva una sola volta per ogni iscrizione.
subscription.canceledUn membro chiede di annullare. La sua iscrizione resta attiva fino a cancel_at.
payment.succeededIl pagamento di un membro va a buon fine. Arriva una sola volta per ogni pagamento.
lead.createdUn lead magnet gratuito o un modulo del Sublaunch raccoglie una nuova email.
post.publishedViene pubblicato un post nella Community del Sublaunch, dal creator o da un membro.
comment.createdQualcuno commenta un post della Community, o risponde a un commento.
affiliate.joinedQualcuno entra nel programma di affiliazione del Sublaunch.

L'oggetto evento

  • idstring
    Identificatore univoco dell'evento, evt_ e 24 caratteri. Presente anche nell'header Sublaunch-Event-Id.
  • objectstring
    Sempre event.
  • typestring
    Il tipo di evento.
    member.joinedmember.leftsubscription.canceledpayment.succeededlead.createdpost.publishedcomment.createdaffiliate.joined
  • created_atstring
    Quando è avvenuto l'evento, ISO 8601.
  • sublaunch_idstring
    Il Sublaunch in cui è avvenuto.
  • dataobject
    Il contenuto dell'evento, a partire dal suo object. Un evento di test contiene test impostato su true.

member.joined

Un'iscrizione diventa attiva, per un nuovo membro a pagamento o gratuito. Arriva una sola volta per ogni iscrizione.

Dati

member.joined
{
  "id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
  "object": "event",
  "type": "member.joined",
  "created_at": "2026-11-17T09:30:00.000Z",
  "sublaunch_id": "q7RkX2LmPv",
  "data": {
    "object": {
      "id": "Ms8kL2QpXz",
      "object": "member",
      "email": "sam@example.com",
      "name": "Sam Carter",
      "first_name": "Sam",
      "last_name": "Carter",
      "user_id": "Us4kP9xQ2M",
      "status": "active",
      "type": "recurring",
      "tier": {
        "id": "tier1",
        "name": "Inner Circle"
      },
      "price": {
        "id": "pR8sK2xLmQ",
        "amount": 29,
        "currency": "usd",
        "interval": "month"
      },
      "payments_count": 3,
      "joined_at": "2026-09-02T18:41:07.000Z",
      "cancel_at": null,
      "canceled_at": null,
      "affiliate_id": null
    }
  }
}

member.left

Un'iscrizione attiva termina e il suo status diventa canceled. Arriva una sola volta per ogni iscrizione.

Dati

  • objectobject
    Il membro, con canceled_at.
member.left
{
  "id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
  "object": "event",
  "type": "member.left",
  "created_at": "2026-11-17T09:30:00.000Z",
  "sublaunch_id": "q7RkX2LmPv",
  "data": {
    "object": {
      "id": "Ms8kL2QpXz",
      "object": "member",
      "email": "sam@example.com",
      "name": "Sam Carter",
      "first_name": "Sam",
      "last_name": "Carter",
      "user_id": "Us4kP9xQ2M",
      "status": "canceled",
      "type": "recurring",
      "tier": {
        "id": "tier1",
        "name": "Inner Circle"
      },
      "price": {
        "id": "pR8sK2xLmQ",
        "amount": 29,
        "currency": "usd",
        "interval": "month"
      },
      "payments_count": 3,
      "joined_at": "2026-09-02T18:41:07.000Z",
      "cancel_at": null,
      "canceled_at": "2026-11-17T09:30:00.000Z",
      "affiliate_id": null
    }
  }
}

subscription.canceled

Un membro chiede di annullare. La sua iscrizione resta attiva fino a cancel_at.

Dati

  • objectobject
    Il membro, con cancel_at.
  • reasonstring o null
    Perché ha annullato, se l'ha indicato.
subscription.canceled
{
  "id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
  "object": "event",
  "type": "subscription.canceled",
  "created_at": "2026-11-17T09:30:00.000Z",
  "sublaunch_id": "q7RkX2LmPv",
  "data": {
    "object": {
      "id": "Ms8kL2QpXz",
      "object": "member",
      "email": "sam@example.com",
      "name": "Sam Carter",
      "first_name": "Sam",
      "last_name": "Carter",
      "user_id": "Us4kP9xQ2M",
      "status": "active",
      "type": "recurring",
      "tier": {
        "id": "tier1",
        "name": "Inner Circle"
      },
      "price": {
        "id": "pR8sK2xLmQ",
        "amount": 29,
        "currency": "usd",
        "interval": "month"
      },
      "payments_count": 3,
      "joined_at": "2026-09-02T18:41:07.000Z",
      "cancel_at": "2026-12-02T18:41:07.000Z",
      "canceled_at": null,
      "affiliate_id": null
    },
    "reason": "Too expensive"
  }
}

payment.succeeded

Il pagamento di un membro va a buon fine. Arriva una sola volta per ogni pagamento.

Dati

  • objectobject
    Il pagamento, con la tua quota in amount_creator.
payment.succeeded
{
  "id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
  "object": "event",
  "type": "payment.succeeded",
  "created_at": "2026-11-17T09:30:00.000Z",
  "sublaunch_id": "q7RkX2LmPv",
  "data": {
    "object": {
      "id": "In7pQ2xKLm",
      "object": "payment",
      "amount": 29,
      "currency": "usd",
      "amount_creator": 26.1,
      "status": "paid",
      "type": "subscription",
      "member_id": "Ms8kL2QpXz",
      "email": "sam@example.com",
      "tier_id": "tier1",
      "affiliate_id": null,
      "paid_at": "2026-11-02T18:41:09.000Z"
    }
  }
}

lead.created

Un lead magnet gratuito o un modulo del Sublaunch raccoglie una nuova email.

Dati

  • objectobject
    Il lead.
lead.created
{
  "id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
  "object": "event",
  "type": "lead.created",
  "created_at": "2026-11-17T09:30:00.000Z",
  "sublaunch_id": "q7RkX2LmPv",
  "data": {
    "object": {
      "id": "Ld3xQ8mKpR",
      "object": "lead",
      "email": "alex@example.com",
      "first_name": "Alex",
      "last_name": null,
      "phone": null,
      "source": "lead_magnet",
      "lead_magnet_id": "lm2K9x",
      "fields": [
        {
          "name": "Experience",
          "value": "Two years"
        }
      ],
      "created_at": "2026-11-16T08:11:05.000Z"
    }
  }
}

post.published

Viene pubblicato un post nella Community del Sublaunch, dal creator o da un membro.

Dati

post.published
{
  "id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
  "object": "event",
  "type": "post.published",
  "created_at": "2026-11-17T09:30:00.000Z",
  "sublaunch_id": "q7RkX2LmPv",
  "data": {
    "object": {
      "id": "Pt9xK3mQ2L",
      "object": "post",
      "title": "Weekly outlook",
      "text": "Three levels I watch this week on the S&P.\n\nCharts below, questions welcome.",
      "category_id": "x7Lp2QaZ",
      "access": "members",
      "price": null,
      "pinned": true,
      "comments_off": false,
      "author_id": null,
      "by_creator": true,
      "media": [
        {
          "kind": "image",
          "url": "https://example.com/weekly-chart.png"
        }
      ],
      "attachments": [],
      "poll": null,
      "likes": 48,
      "comments_count": 12,
      "status": "published",
      "url": "https://sublaunch.com/alphadesk/community/weekly-outlook",
      "published_at": "2026-11-15T17:02:40.000Z",
      "updated_at": "2026-11-16T08:11:05.000Z"
    }
  }
}

comment.created

Qualcuno commenta un post della Community, o risponde a un commento.

Dati

comment.created
{
  "id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
  "object": "event",
  "type": "comment.created",
  "created_at": "2026-11-17T09:30:00.000Z",
  "sublaunch_id": "q7RkX2LmPv",
  "data": {
    "object": {
      "id": "Cm2kX8pQ7R",
      "object": "comment",
      "post_id": "Pt9xK3mQ2L",
      "parent_id": null,
      "text": "Thanks, the 4 hour chart helps a lot.",
      "author_id": "Us4kP9xQ2M",
      "likes": 3,
      "status": "published",
      "created_at": "2026-11-15T18:20:13.000Z"
    }
  }
}

affiliate.joined

Qualcuno entra nel programma di affiliazione del Sublaunch.

Dati

affiliate.joined
{
  "id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
  "object": "event",
  "type": "affiliate.joined",
  "created_at": "2026-11-17T09:30:00.000Z",
  "sublaunch_id": "q7RkX2LmPv",
  "data": {
    "object": {
      "id": "Af6tR2kQxM",
      "object": "affiliate",
      "user_id": "Us7mQ2kX9P",
      "code": "482913",
      "commission_rate": 30,
      "status": "active",
      "members_active": 0,
      "members_total": 0,
      "joined_at": "2026-11-17T09:30:00.000Z"
    }
  }
}

Consegna

Sublaunch invia ogni evento come POST JSON e attende la tua risposta per 10 secondi. Qualsiasi 2xx conta come consegnato. Un redirect, qualsiasi altro stato, un timeout o un errore di connessione contano come fallimento, e l'evento viene inviato di nuovo.

HeaderValore
Sublaunch-SignatureIl timestamp e la firma, t=1763371800,v1=5f2b...
Sublaunch-Event-IdL'id dell'evento, per saltare gli eventi che hai già gestito.
Sublaunch-Event-TypeIl type dell'evento.
User-AgentSublaunch-Webhooks/1.0
Richiesta
POST /webhooks/sublaunch HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: Sublaunch-Webhooks/1.0
Sublaunch-Event-Id: evt_8kQ2vXr4LmT9wPz1Hc6YbN3d
Sublaunch-Event-Type: member.joined
Sublaunch-Signature: t=1763371800,v1=58ca5e964b92d617c979d3f067cdc2035a1a1a9d3f848d7d927c2db09b8e9baa

Verifica le firme

Chiunque può inviare una richiesta al tuo URL. Verifica che ognuna arrivi da Sublaunch prima di fidarti.

  1. Leggi il body grezzo come byte, prima di qualsiasi parsing JSON. Fare il parsing e riscriverlo cambia i byte.
  2. Dividi l'header Sublaunch-Signature sulle virgole. t è un timestamp Unix in secondi, v1 è la firma.
  3. Calcola l'HMAC SHA256 di t, un punto e il body grezzo, usando come chiave l'intero segreto dell'endpoint, whsec_ compreso, e scrivilo in esadecimale.
  4. Confrontalo con ogni v1 in tempo costante.
  5. Rifiuta un t che si discosta di più di 5 minuti dal tuo orologio, così nessuno può riprodurre una vecchia richiesta. Ogni nuovo tentativo è firmato con un t nuovo.

Rispondi 400 quando la verifica fallisce. Conserva il segreto in una variabile d'ambiente come SUBLAUNCH_WEBHOOK_SECRET.

const crypto = require("crypto");
const express = require("express");

// rawBody: the request body exactly as received, before any JSON parsing.
function verifySublaunchSignature(rawBody, header, secret, toleranceSeconds = 300) {
  if (typeof header !== "string") return false;
  let timestamp = null;
  const signatures = [];
  for (const part of header.split(",")) {
    const [key, value] = part.split("=", 2).map((s) => (s || "").trim());
    if (key === "t") timestamp = value;
    if (key === "v1" && value) signatures.push(value);
  }
  if (!/^\d+$/.test(timestamp || "") || signatures.length === 0) return false;
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > toleranceSeconds) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.`).update(rawBody).digest();
  return signatures.some((signature) => {
    const given = Buffer.from(signature, "hex");
    return given.length === expected.length && crypto.timingSafeEqual(given, expected);
  });
}

const app = express();

// The body must stay raw on this route.
app.post("/webhooks/sublaunch", express.raw({ type: "application/json" }), (req, res) => {
  const ok = verifySublaunchSignature(
    req.body,
    req.get("Sublaunch-Signature"),
    process.env.SUBLAUNCH_WEBHOOK_SECRET,
  );
  if (!ok) return res.status(400).send("Invalid signature");

  const event = JSON.parse(req.body.toString("utf8"));
  // Already handled? Skip it, retries send the same event.id again.
  if (event.type === "member.joined") {
    // event.data.object is the new member
  } else if (event.type === "payment.succeeded") {
    // event.data.object is the payment
  } else if (event.type === "subscription.canceled") {
    // event.data.object is the member, event.data.reason why they canceled
  }
  res.sendStatus(200);
});

app.listen(3000);

Nuovi tentativi

Quando una consegna fallisce, Sublaunch riprova 7 volte, ogni volta dopo un'attesa più lunga. Dopo l'8º tentativo, circa 45 ore dopo il primo, la consegna viene segnata come fallita.

TentativoInviato
1Subito
21 minuto dopo il fallimento precedente
35 minuti dopo il fallimento precedente
430 minuti dopo il fallimento precedente
52 ore dopo il fallimento precedente
66 ore dopo il fallimento precedente
712 ore dopo il fallimento precedente
824 ore dopo il fallimento precedente

Un endpoint che fallisce per 3 giorni di fila, con almeno 8 tentativi falliti, viene disattivato. Il suo status diventa disabled, il suo disabled_reason diventa failing e le consegne ancora in attesa finiscono come fallite. Sistema il tuo server, poi riattivalo nell'app o con Aggiorna un endpoint webhook. Il conteggio riparte dalla prima consegna che il tuo server accetta. Gli eventi di test vengono inviati una sola volta e non vengono mai conteggiati.

Elenca le consegne mostra il codice di stato e l'errore di ogni tentativo, così vedi cosa ha risposto il tuo server.

Buone pratiche

  • Rispondi 2xx entro 10 secondi, poi esegui il lavoro in una coda.
  • Ogni evento viene consegnato almeno una volta. Usa l'id dell'evento, presente anche in Sublaunch-Event-Id, per saltare un evento che hai già gestito.
  • Gli eventi possono arrivare in ordine sparso. Confronta created_at, oppure recupera di nuovo il membro per avere il suo stato più recente.
  • Verifica ogni firma e rifiuta i timestamp vecchi.
  • Quando rinnovi il segreto, viene sostituito all'istante. Fai subito il deploy di quello nuovo, le consegne che falliscono nel frattempo vengono ritentate e firmate con il nuovo.
  • Eventi e consegne vengono conservati 30 giorni.