---
name: klaviyo-enterprise-rbac
description: |-
  Configure Klaviyo enterprise access control with API key scopes and OAuth.
  Use when implementing per-key scoping, configuring OAuth app authorization,
  or setting up organization-level access controls for Klaviyo.
  Trigger with phrases like "klaviyo scopes", "klaviyo RBAC",
  "klaviyo enterprise", "klaviyo permissions", "klaviyo OAuth", "klaviyo access control".
allowed-tools: Read, Write
version: 1.7.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - klaviyo
  - email-marketing
  - cdp
compatibility: Designed for Claude Code
title: klaviyo-enterprise-rbac
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac/references/examples.md), [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac/references/implementation.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/klaviyo-enterprise-rbac`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/klaviyo-enterprise-rbac`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/klaviyo-enterprise-rbac --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/klaviyo-enterprise-rbac --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Klaviyo Enterprise RBAC

## Overview

Enterprise access control for Klaviyo: API key scoping with granular read/write permissions, OAuth app authorization flows, and application-level RBAC built on top of Klaviyo's scope system. Klaviyo has no built-in roles, so you compose least-privilege access from scoped keys plus an application permission layer.

## Prerequisites

- Klaviyo account with API key management access
- Understanding of OAuth 2.0 (for OAuth apps)
- Application requiring per-user or per-role Klaviyo access

## Klaviyo Access Control Model

Klaviyo uses **scoped API keys** and **OAuth** for access control. There are no built-in "roles" in Klaviyo's API -- you implement RBAC by creating multiple API keys with different scopes.

### API Key Scopes

| Scope | Read | Write | What It Controls |
|-------|------|-------|-----------------|
| `accounts` | Account info | N/A | Organization name, timezone |
| `campaigns` | List campaigns | Create/send campaigns | Email, SMS, push campaigns |
| `catalogs` | Browse items | CRUD catalog items | Product catalog management |
| `coupons` | List coupons | Create coupons | Coupon/discount codes |
| `data-privacy` | N/A | Delete profiles | GDPR/CCPA deletion requests |
| `events` | Query events | Track events | Server-side event tracking |
| `flows` | List flows | Create/update flows | Flow automation |
| `images` | List images | Upload images | Email template images |
| `lists` | List lists | CRUD lists/members | List management |
| `metrics` | Query metrics | N/A | Metric aggregations |
| `profiles` | Read profiles | Create/update profiles | Profile management |
| `segments` | Read segments | N/A | Segment queries |
| `tags` | Read tags | CRUD tags | Resource tagging |
| `templates` | Read templates | Create/update templates | Email templates |
| `webhooks` | List webhooks | CRUD webhooks | Webhook subscriptions |

## Instructions

The full, copy-ready code for every step lives in
[the implementation walkthrough](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac/references/implementation.md). At a high level
the workflow is five steps:

1. **Create scoped API keys** — one key per service/role in the Klaviyo
   dashboard (**Settings > API Keys**), each granted only the scopes it needs.
   A profile-sync service gets `profiles:*` + `lists:*`; a reporting dashboard
   gets `*:read` only; the admin key gets everything and is used sparingly.
2. **Model application-level RBAC** — map each app role (admin, marketer,
   developer, viewer, service) to a permission set and to its scoped key, so the
   app enforces intent and the key enforces the hard boundary.
3. **Add permission middleware** — reject requests whose role lacks the required
   permission before the handler runs (401 for no role, 403 for wrong role).
4. **Wire the OAuth app flow** — for third-party/marketplace integrations,
   request only the scopes the app uses, then exchange the code for tokens.
5. **Record an audit trail** — log every access with role/action/resource and
   alert the security team on destructive actions like profile deletion.

The essential skeleton — a least-privilege key plus the permission check — looks
like this:

```typescript
// One scoped key per service — reporting is read-only
const reportingSession = new ApiKeySession(process.env.KLAVIYO_KEY_REPORTING!);

// App-level guard: refuse before the handler runs
app.post('/api/klaviyo/campaigns/send',
  requireKlaviyoPermission('canSendCampaigns'),
  campaignSendHandler
);
```

See [the implementation walkthrough](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac/references/implementation.md) for the role
permission matrix, `getSessionForRole`, the middleware, the OAuth exchange, the
audit logger, and the full environment variable layout in
[the implementation walkthrough](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac/references/implementation.md).

## Output

Applying this skill produces:

- **Multiple scoped API keys** in Klaviyo, one per service/role, each holding
  only the scopes that service needs (defence in depth beyond app-level checks).
- **An RBAC module** (`src/klaviyo/rbac.ts`) exporting `checkPermission` and
  `getSessionForRole`, mapping the five app roles to permissions and keys.
- **Permission middleware** (`src/middleware/klaviyo-auth.ts`) that returns 401
  when no role is assigned and 403 when a role lacks the requested permission.
- **An OAuth flow** for marketplace apps requesting minimized scopes.
- **An audit log** (`src/klaviyo/audit.ts`) that records access and alerts on
  destructive actions.

A blocked request returns a structured 403, e.g.:

```json
{ "error": "Forbidden", "message": "Role 'marketer' does not have permission: canDeleteProfiles" }
```

## Examples

Grounded, end-to-end scenarios — least-privilege keys, route gating by
permission, resolving a session from a role, OAuth scope minimization, and
alerting on a destructive action — are collected in
[the examples reference](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac/references/examples.md).

Quick illustration — a marketer is allowed to send campaigns but blocked from
deleting profiles, purely from the role permission set:

```typescript
// canSendCampaigns: true  -> allowed
app.post('/api/klaviyo/campaigns/send', requireKlaviyoPermission('canSendCampaigns'), campaignSendHandler);

// canDeleteProfiles: false -> 403 Forbidden
app.delete('/api/klaviyo/profiles/:id', requireKlaviyoPermission('canDeleteProfiles'), profileDeleteHandler);
```

## Error Handling

| Error | Status | Cause | Solution |
|-------|--------|-------|----------|
| `permission_denied` | 403 | API key missing required scope | Create new key with correct scopes |
| OAuth code expired | 400 | User took too long to authorize | Retry authorization flow |
| Token refresh failed | 401 | Refresh token revoked | Re-authorize the app |
| Role not assigned | 401 | User missing `klaviyoRole` | Assign role in your user management |

## Resources

- [Full implementation walkthrough](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac/references/implementation.md) — all five steps, verbatim code
- [Worked examples](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-enterprise-rbac/references/examples.md) — least-privilege, route gating, OAuth minimization
- [Klaviyo API Scopes](https://developers.klaviyo.com/en/docs/authenticate_)
- [OAuth Setup Guide](https://developers.klaviyo.com/en/docs/set_up_oauth)
- [Update OAuth Scopes](https://developers.klaviyo.com/en/docs/update_your_oauth_scopes)
- For major migrations, see the `klaviyo-migration-deep-dive` skill.
