Skip to content

@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/sdk instead. It re-exports everything from this package and adds the RCML template builders and high-level helpers on top.

Installation

bash
npm install @rule/client

Connecting 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).

RuleClient

What you can do

NamespaceWhat it coversGuide
client.subscribersAdd, update, find, remove, block, and suppress subscribersManaging Subscribers · Bulk Create
client.tagsCreate and manage audience tagsTags
client.campaignsCreate, target, and schedule campaignsEmail Campaigns · SMS Campaigns
client.automationsTrigger-based email and SMS workflowsEmail Automations · SMS Automations
client.messagesPer-dispatcher message objectsEmail Messages · SMS Messages
client.templatesEmail and SMS templatesEmail Templates · SMS Templates
client.dynamicSetsConnect messages to templatesDynamic Sets
client.brandStylesBrand colors, fonts, and logosBrand Styles
client.customFieldCustom field group schemaCustom Field Schema
client.apiKeysCreate and rotate API keysAPI Keys
client.analyticsCampaign and automation statisticsAnalytics
client.exportsBulk data exports (Enterprise)Exports
client.recipientsRecipient lists for targetingRecipients
parseWebhookEvent · markTagDirectionTyped event shapes for inbound Rule.io webhooksWebhooks

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.

RuleApiError · RuleClientError