Skip to main content
Use the Sendrealm JavaScript SDK from trusted server-side or edge environments to call the Sendrealm API. This SDK uses a Sendrealm API key. Do not use it to register browsers or mobile devices for push. Use the Android, iOS, React Native, or React Web Push SDK for device registration.
Do not expose a Sendrealm API key in browser JavaScript or mobile app code. API keys are server-side secrets.

Runtime Support

The SDK uses native fetch and has no runtime dependencies.
  • Node.js 18 or newer.
  • Cloudflare Workers.
  • Deno.
  • Bun.
  • Vercel Edge Runtime.
  • Other runtimes with fetch, Headers, Request, and Response.

Install

Create An API Key

Create an API key in the Sendrealm dashboard and store it in your secret manager or environment variables.
See API Keys for dashboard setup.

Create A Client

If SENDREALM_API_KEY is set, the client can read it automatically:

Client Options

Use client options for custom timeouts, retries, headers, or fetch behavior:
Important options:
  • apiKey: required unless SENDREALM_API_KEY is set.
  • projectId: optional project selector; defaults to SENDREALM_PROJECT_ID, then to the API key’s default project.
  • timeout: request timeout in milliseconds.
  • maxRetries: number of automatic retries for retryable failures.
  • fetch: custom fetch implementation.
  • defaultHeaders: headers sent with every request.
  • defaultQuery: query parameters sent with every request.
apiKey may also be an async function if your service rotates credentials.

Send Email

Before sending production email, make sure the sending domain is verified in Sendrealm.

Send Push

Send push notifications to registered devices:
Push sending requires device setup first:
  • Android devices use the Android or React Native SDK.
  • iOS devices use the iOS or React Native SDK.
  • Web browsers use the React Web Push SDK.
  • Firebase, APNs, or Web Push provider settings must be configured in Sendrealm.

Test And Diagnose Push

Use API-key resources from trusted backend code to inspect setup and prove one device end to end:
Raw APNs, FCM, and Web Push credentials are not returned by app or device resources. Push campaign SDK methods create and edit drafts, preview reachable devices, and test a draft on one device; they do not schedule or launch it.

Ingest Events

Each event should include one identity, such as contact_id, external_id, or email. Use an idempotency_key when your system might retry the same event. For correlated journeys such as checkout recovery, pass the business identifier on every related event:
Avoid putting sensitive personal data in event data unless your team intentionally wants that data in Sendrealm.

Work With Contacts

List contacts with cursor pagination:
Create a contact:
Update a contact:
Look up or upsert a contact by email:
Use backend-owned contact fields for authoritative customer data such as billing plan, account status, compliance flags, and verified profile data.

Dashboard Resources

Use API-key-scoped resources to inspect the current project, choose a verified domain, and create campaign drafts:
Campaign APIs create and update drafts only. Review readiness and schedule or send the campaign from the SendRealm dashboard.

Automations

Validate drafts before publishing, inspect runs, and use no-send test runs for waits and timeout paths:

Pagination

Some list endpoints return cursor pages. Consume every item with for await:
Or inspect pages manually:

Errors

Non-2xx responses throw typed errors:
Common error categories:
  • Authentication errors: check the API key.
  • Permission errors: check key scope and project access.
  • Validation errors: check required fields and request shape.
  • Rate limits: retry after the server-provided delay when available.
  • Connection errors: check network and runtime fetch behavior.

Edge Runtime Examples

Cloudflare Workers:
Deno:
Bun:

Production Checklist

  • API key is stored in a secret manager or environment variable.
  • API key is never sent to browser or mobile code.
  • Sending domains are verified for email.
  • Device SDKs are installed before backend push sends target app users.
  • Event names are stable.
  • Event submissions use idempotency_key where retries are possible.
  • Errors are logged with status, code, and message.
  • Rate limit responses are handled.