Publish

Publish to a named channel with publish permission. Use the API and Language controls to switch Socket vs REST and JavaScript vs React.

Publish a message

Publish over the WebSocket client after you are connected.

import { QPub } from "@qpub/sdk";

const socket = new QPub.Socket({
  apiKey: process.env.QPUB_API_KEY,
});

socket.connection.on("connected", async () => {
  const channel = socket.channels.get("notifications");
  await channel.publish(
    { title: "New order", orderId: "ord_1" },
    { event: "order.created", alias: "api" }
  );
});

Socket publish does not return the REST published payload.

Batch publish (REST)

Batch publish to multiple channels is a REST feature (publishBatch / POST /v1/channels/messages). Switch to REST above, or publish once per channel on the Socket.

curl

API_KEY="publicId:secret"
curl -X POST "https://rest.qpub.io/v1/channel/notifications/messages" \
  -H "Authorization: Basic $(echo -n "$API_KEY" | base64)" \
  -H "Content-Type: application/json" \
  -d '{"messages":[{"event":"ping","data":{"ok":true}}]}'

Notes

  • At least one message is required in the REST body.
  • Message size and rate limits depend on your plan.
  • Subscribers need a Socket subscription to receive messages in realtime.