Appearance
@rule/client
@rule/client is the HTTP API client for the Rule.io marketing platform. It covers the full Rule.io API surface: subscriber management, audience segmentation, email and SMS campaigns and automations, templates, analytics, and more.
Most users should install
@rule/sdkinstead. It re-exports everything from this package and adds the RCML template builders and high-level helpers on top.
Installation
bash
npm install @rule/clientConnecting to Rule.io
typescript
import { RuleClient } from '@rule/client';
const client = new RuleClient({ apiKey: process.env['RULE_API_KEY']! });You can also pass the API key as a plain string: new RuleClient(apiKey).
What you can do
| Namespace | What it covers | Guide |
|---|---|---|
client.subscribers | Add, update, find, remove, block, and suppress subscribers | Managing Subscribers · Bulk Create |
client.tags | Create and manage audience tags | Tags |
client.campaigns | Create, target, and schedule campaigns | Email Campaigns · SMS Campaigns |
client.automations | Trigger-based email and SMS workflows | Email Automations · SMS Automations |
client.messages | Per-dispatcher message objects | Email Messages · SMS Messages |
client.templates | Email and SMS templates | Email Templates · SMS Templates |
client.dynamicSets | Connect messages to templates | Dynamic Sets |
client.brandStyles | Brand colors, fonts, and logos | Brand Styles |
client.customField | Custom field group schema | Custom Field Schema |
client.apiKeys | Create and rotate API keys | API Keys |
client.analytics | Campaign and automation statistics | Analytics |
client.exports | Bulk data exports (Enterprise) | Exports |
client.recipients | Recipient lists for targeting | Recipients |
parseWebhookEvent · markTagDirection | Typed event shapes for inbound Rule.io webhooks | Webhooks |
Error handling
Two error classes are exported from this package:
typescript
import { RuleApiError, RuleClientError } from '@rule/client';RuleApiError— the Rule.io API returned a non-2xx response. Provides.statusCode,.isAuthError(),.isValidationError(), and.validationErrors.RuleClientError— misconfiguration in your code (missing API key, invalid arguments).
Most get and find methods return null when the resource does not exist, so you rarely need to catch 404 errors explicitly. See Error Handling for the full picture.