Messaging

Register a browser Web Push subscription

Register a browser `PushSubscription` (the `endpoint` plus the `p256dh` / `auth` keys returned by `pushManager.subscribe()`) so it becomes eligible to receive native Web Push. The send endpoint (`/messaging/push`) only delivers to subscriptions registered to the project, so a caller cannot push to arbitrary or other-tenant endpoints. Registration is idempotent - re-registering the same endpoint updates the existing row (keys rotate, `lastSeenAt` bumps) instead of creating a duplicate. Each project has a cap on the number of registered subscriptions; when the cap is reached, the least-recently-seen subscriptions are evicted to make room. Optionally associate the subscription with a `userId` (your end-user id, for targeted sends) and a `deviceId`. Accepts: OrgBearerAuth (for admin users), ProjectBearerAuth (JWT for authenticated users), or ApiKeyAuth (X-API-Key for programmatic access).

AuthJWT or API Key
GroupMessaging
Rate limitSee Rate Limits
POST/api/messaging/projects/{projectId}/messaging/web-push/subscriptions

SDK setup

Create a client and set credentials (JWT and/or API key) before calling the API. Match the authentication type shown above.

import { Configuration, MessagingApi } from 'mudbase-sdk';

const configuration = new Configuration({
  basePath: 'https://cloud.mudbase.dev',
  apiKey: 'sk_live_mudbase_doc_Xk9mP2qR7vN4wL8jH3tY6uE',
  accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfbW9yZ2FuX2RlIiwiZW1haWwiOiJtb3JnYW4uY2hlbkBub3J0aHdpbmQuZGV2IiwiZXhwIjoxODI1MTI5NjAwfQ.doc_preview_sig',
});
// This endpoint accepts either credential - apiKey or accessToken alone is enough.

const messaging = new MessagingApi(configuration);
import { Configuration, MessagingApi } from 'mudbase-sdk';

const configuration = new Configuration({
  basePath: 'https://cloud.mudbase.dev',
  apiKey: 'sk_live_mudbase_doc_Xk9mP2qR7vN4wL8jH3tY6uE',
  accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfbW9yZ2FuX2RlIiwiZW1haWwiOiJtb3JnYW4uY2hlbkBub3J0aHdpbmQuZGV2IiwiZXhwIjoxODI1MTI5NjAwfQ.doc_preview_sig',
});
// This endpoint accepts either credential - apiKey or accessToken alone is enough.

const messaging = new MessagingApi(configuration);

Example request

Call this endpoint using the client from SDK setup. Use View HTTP for a raw cURL example.

const { data: result } = await messaging.registerWebPushSubscription(
  "proj_p6fDsoIpoNwu",
  {
    subscription: "158.80.243.175",
    userId: "usr_w12eIrDSgAbdrB",
    deviceId: "mNlSAIOUV9OrQrhb"
  }
);
const { data: result } = await messaging.registerWebPushSubscription(
  "proj_p6fDsoIpoNwu",
  {
    subscription: "158.80.243.175",
    userId: "usr_w12eIrDSgAbdrB",
    deviceId: "mNlSAIOUV9OrQrhb"
  }
);

Playground

live

Test this endpoint with your own credentials. Your requests will be sent to the live API.

Get your API key from the console
Use the auth endpoints to obtain a JWT.

No Request Yet

Send a request to see the full inspector

Authentication

Requires JWT Requires API Key JWT or API Key
Note
This endpoint accepts either JWT Bearer token or API Key. Use Authorization: Bearer YOUR_TOKEN for user context, or X-API-Key: YOUR_KEY for server-to-server. View authentication guide →Include your JWT in the Authorization: Bearer YOUR_TOKEN header (user-facing apps, RBAC). View authentication guide →Include your API key in the X-API-Key: YOUR_KEY header (server-to-server, SDKs). View authentication guide →

Path Parameters

NameTypeRequiredDescription
projectIdstringYes-

Request Body

json
{
  "subscription": {
    "endpoint": "pixel back up",
    "keys": {
      "p256dh": "hard drive index",
      "auth": "card override"
    }
  },
  "userId": "usr_l6ZF362tQSr4nE",
  "deviceId": "6zGHB7sSCIsru797"
}
{
  "subscription": {
    "endpoint": "pixel back up",
    "keys": {
      "p256dh": "hard drive index",
      "auth": "card override"
    }
  },
  "userId": "usr_l6ZF362tQSr4nE",
  "deviceId": "6zGHB7sSCIsru797"
}

Responses

201Web Push subscription registered
json
{
  "success": true,
  "data": {
    "endpoint": "https://push-service.example.com/subscribe/abc123",
    "userId": "user_123",
    "lastSeenAt": "2024-01-15T10:00:00.000Z"
  }
}
{
  "success": true,
  "data": {
    "endpoint": "https://push-service.example.com/subscribe/abc123",
    "userId": "user_123",
    "lastSeenAt": "2024-01-15T10:00:00.000Z"
  }
}
400-
403-
429Subscription registration rate limit exceeded
json
{
  "success": true,
  "error": "program back up"
}
{
  "success": true,
  "error": "program back up"
}

Errors

CodeMeaning
400-
403-
429Subscription registration rate limit exceeded
Edit this page on GitHub
Chat with us