> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dema.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Rule

> Let the Dema Agent manage subscribers and tags, read campaign performance, and send transactional email or SMS in Rule when you ask.

## Overview

Once Rule is connected, the Dema Agent can work with your [Rule](https://www.rule.io) email and SMS marketing data directly inside a conversation — list tags, look up a subscriber by email or phone, browse campaigns, and read campaign statistics. It can also create or update subscribers (with custom fields and tags), add tags to a subscriber to trigger automations, and send transactional email or SMS.

The agent only acts when you ask it to, and Dema asks you to confirm sensitive changes before they are applied.

***

## Prerequisites

* A Rule account with access to the **Developer** settings page (to create an API key).

***

## Connect Rule

<Steps>
  <Step title="Create an API key in Rule">
    1. In Rule, open the account dropdown menu and click **Settings**.
    2. Go to **Developer**.
    3. Click **New API key**. The new key appears shortly — copy it.

    <Note>
      A Rule API key is a sensitive credential, much like a password — it grants access to your account and data. Store it securely and do not share it.
    </Note>
  </Step>

  <Step title="Connect in Dema">
    In Dema, go to **Agents → Settings → Integrations**, find **Rule**, and click **Connect**. Enter:

    * **API key** — the key you copied from Rule.

    Click **Add**. Dema marks the integration as Active.
  </Step>
</Steps>

A single API key covers everything the agent does — reading tags, subscribers, and campaign statistics, pushing subscriber records and tags, and sending transactional messages. You do not need separate keys for read and write.

***

## Rotating the key

To rotate, create a new key under **Settings → Developer**, click **Reconnect** on the Rule integration card in Dema, enter the new key, then delete the old key in Rule.

***

## Troubleshooting

<AccordionGroup>
  <Accordion title="Dema cannot authenticate">
    Check that you copied the full API key from **Settings → Developer**. A failed key returns an authorization error — recreate the key in Rule and click **Reconnect** in Dema.
  </Accordion>

  <Accordion title="I cannot find the Developer page">
    The API key is created under the account dropdown menu → **Settings → Developer**. If you do not see it, ask an admin on your Rule account to create the key for you.
  </Accordion>

  <Accordion title="The agent's Rule requests are failing">
    Confirm the key has not been deleted in Rule. If it has, create a new key and click **Reconnect** in Dema.
  </Accordion>
</AccordionGroup>

If you are still stuck, contact [support](mailto:info@dema.ai) with the error message you see.

***

## Additional resources

* [Rule API key and documentation](https://help.rule.io/en/support/solutions/articles/103000274805-api-key-and-documentation)
* [Rule REST API reference](https://apidoc.rule.se/)
