---
title: Ruby
description: Notiflows Ruby SDK for server-side integration
---

The Ruby SDK (`notiflows`) allows you to trigger notiflows, manage users, and interact with the Notiflows Admin API from your Ruby backend.

## Installation

```bash
gem install notiflows
```

Or add to your Gemfile:

```ruby
gem "notiflows"
```

## Quick Start

```ruby
require "notiflows"

client = Notiflows::Client.new(
  api_key: "pk_your_api_key",
  secret: "sk_your_secret_key"
)

# Trigger a notiflow
client.notiflows.run("welcome-email", {
  data: { name: "Jane" },
  recipients: [{ external_id: "user_123" }]
})
```

## Configuration

```ruby
client = Notiflows::Client.new(
  api_key: "pk_your_api_key",
  secret: "sk_your_secret_key"
)
```

Both `api_key` and `secret` are required. Find them in your project's **Settings > API Keys**.

## Triggering Notiflows

```ruby
# Send to specific recipients
client.notiflows.run("order-shipped", {
  data: { order_id: "order_789" },
  recipients: [
    { external_id: "user_123" },
    { external_id: "user_456" }
  ]
})

# Send to all subscribers of a topic
client.notiflows.run("new-comment", {
  topic: "post_123",
  data: { commenter: "Jane" },
  actor: { external_id: "user_456" }
})
```

## Managing Users

```ruby
# Upsert user
client.users.upsert("user_123", { email: "jane@example.com", first_name: "Jane" })

# Get user
user = client.users.retrieve("user_123")

# List users
users = client.users.list(limit: 20)

# Delete user
client.users.delete("user_123")
```

## User Preferences

```ruby
# Get preferences
prefs = client.users.preferences.retrieve("user_123")

# Update preferences
client.users.preferences.update("user_123", {
  channel_types: { "email" => true, "sms" => false }
})
```

## Topic Subscriptions

```ruby
# Subscribe
client.users.subscriptions.subscribe("user_123", { topic_name: "product-updates" })

# List subscriptions
subs = client.users.subscriptions.list("user_123")

# Unsubscribe
client.users.subscriptions.unsubscribe("product-updates", { user_external_id: "user_123" })
```

## Topics

```ruby
# List topics
client.topics.list(limit: 10)

# Get topic
client.topics.retrieve("product-updates")

# Delete topic
client.topics.delete("product-updates")
```

## Notifications & Deliveries

```ruby
# List notifications
client.notifications.list(limit: 10)

# Get notification
client.notifications.retrieve("notification_id")

# List deliveries
client.deliveries.list(limit: 10)

# Get delivery
client.deliveries.retrieve("delivery_id")
```
