Skip to main content

Consumers API

Consumers represent end users in the Fanfare platform. Use these endpoints to create, manage, and query consumer records.

Create Consumer

Create a new consumer. POST /api/v1/consumers

Authentication

  • Secret key required

Request Body

interface CreateConsumerRequest {
  email?: string;
  phone?: string; // E.164 format recommended
  fullName?: string;
  metadata?: Record<string, unknown>;
  externalId?: string;
}

Response

interface Consumer {
  id: string;
  email: string | null;
  phone: string | null;
  fullName: string | null;
  metadata: Record<string, unknown> | null;
  externalId: string | null;
  totalOrders: number;
  totalOrderValue: number;
  lastOrderAt: string | null;
  createdAt: string;
  updatedAt: string;
}

Example

curl -X POST https://admin.fanfare.io/api/v1/consumers \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "fullName": "John Doe",
    "metadata": {
      "source": "import",
      "tier": "vip"
    }
  }'
Response:
{
  "id": "cons_01HXYZ123456789",
  "email": "[email protected]",
  "phone": null,
  "fullName": "John Doe",
  "metadata": {
    "source": "import",
    "tier": "vip"
  },
  "externalId": null,
  "totalOrders": 0,
  "totalOrderValue": 0,
  "lastOrderAt": null,
  "createdAt": "2024-11-01T10:00:00Z",
  "updatedAt": "2024-11-01T10:00:00Z"
}

Error Responses

StatusErrorDescription
400Validation failedInvalid request data
400Email already existsDuplicate email
401Authentication requiredMissing authentication

List Consumers

List consumers with pagination, search, and filtering. GET /api/v1/consumers

Authentication

  • Secret key required

Query Parameters

ParameterTypeDefaultDescription
firstnumber20Number of items per page (max 100)
afterstring-Cursor for forward pagination
beforestring-Cursor for backward pagination
lastnumber-Items for backward pagination
searchstring-Search by email, phone, or name (min 2 chars)
sortBystringcreatedAtField to sort by
sortDirstringdescSort direction (asc or desc)
createdAfterstring-Filter by creation date
createdBeforestring-Filter by creation date
audienceIdstring-Filter by audience membership
includestring-Relations to include (audiences)

Response

interface ConsumersListResponse {
  data: Consumer[];
  pageInfo: {
    startCursor: string | null;
    endCursor: string | null;
  };
}

Example

curl -X GET "https://admin.fanfare.io/api/v1/consumers?first=20&search=john&sortBy=createdAt&sortDir=desc" \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxx"
Response:
{
  "data": [
    {
      "id": "cons_01HXYZ123456789",
      "email": "[email protected]",
      "fullName": "John Doe",
      "createdAt": "2024-11-01T10:00:00Z"
    },
    {
      "id": "cons_01HXYZ123456790",
      "email": "[email protected]",
      "fullName": "John Smith",
      "createdAt": "2024-10-15T08:00:00Z"
    }
  ],
  "pageInfo": {
    "startCursor": "eyJpZCI6ImNvbnNfMDFIWFlaIn0=",
    "endCursor": "eyJpZCI6ImNvbnNfMDFIWFlaMn0="
  }
}

Get Consumer

Get a single consumer by ID. GET /api/v1/consumers/:id

Authentication

  • Secret key required

Path Parameters

ParameterTypeDescription
idstringThe consumer ID

Query Parameters

ParameterTypeDescription
includestringRelations to include (audiences, orders)

Example

curl -X GET "https://admin.fanfare.io/api/v1/consumers/cons_01HXYZ123456789?include=audiences" \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxx"

Error Responses

StatusErrorDescription
404Consumer not foundConsumer ID does not exist

Update Consumer

Update an existing consumer. PUT /api/v1/consumers/:id

Authentication

  • Secret key required

Path Parameters

ParameterTypeDescription
idstringThe consumer ID

Request Body

interface UpdateConsumerRequest {
  email?: string | null;
  phone?: string | null;
  fullName?: string | null;
  metadata?: Record<string, unknown> | null;
  externalId?: string | null;
}

Example

curl -X PUT https://admin.fanfare.io/api/v1/consumers/cons_01HXYZ123456789 \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "fullName": "John A. Doe",
    "metadata": {
      "tier": "platinum"
    }
  }'

Error Responses

StatusErrorDescription
400Validation failedInvalid request data
404Consumer not foundConsumer ID does not exist

Delete Consumer

Delete a consumer. DELETE /api/v1/consumers/:id

Authentication

  • Secret key required

Path Parameters

ParameterTypeDescription
idstringThe consumer ID

Example

curl -X DELETE https://admin.fanfare.io/api/v1/consumers/cons_01HXYZ123456789 \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxx"

Response

Returns the deleted consumer.

Batch Create Consumers

Create multiple consumers in a single request. POST /api/v1/consumers/batch

Authentication

  • Secret key required

Request Body

type BatchCreateConsumersRequest = CreateConsumerRequest[];
Maximum batch size: 500 consumers

Example

curl -X POST https://admin.fanfare.io/api/v1/consumers/batch \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '[
    {"email": "[email protected]", "fullName": "User One"},
    {"email": "[email protected]", "fullName": "User Two"},
    {"email": "[email protected]", "fullName": "User Three"}
  ]'
Response:
[
  {
    "id": "cons_01HXYZ123456789",
    "email": "[email protected]",
    "fullName": "User One"
  },
  {
    "id": "cons_01HXYZ123456790",
    "email": "[email protected]",
    "fullName": "User Two"
  },
  {
    "id": "cons_01HXYZ123456791",
    "email": "[email protected]",
    "fullName": "User Three"
  }
]

Error Responses

StatusErrorDescription
400Max batch size is 500Too many consumers in batch

Batch Update Consumers

Update multiple consumers in a single request. PUT /api/v1/consumers/batch

Authentication

  • Secret key required

Request Body

interface BatchUpdateConsumerItem extends UpdateConsumerRequest {
  id: string;
}

type BatchUpdateConsumersRequest = BatchUpdateConsumerItem[];

Example

curl -X PUT https://admin.fanfare.io/api/v1/consumers/batch \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '[
    {"id": "cons_01HXYZ123456789", "metadata": {"tier": "gold"}},
    {"id": "cons_01HXYZ123456790", "metadata": {"tier": "silver"}}
  ]'

Search Consumers

Search consumers with additional search options. GET /api/v1/consumers/search

Authentication

  • Secret key required

Query Parameters

ParameterTypeDescription
qstringSearch query (min 2 chars)
emailstringExact email match
phonestringExact phone match
externalIdstringExact external ID match
firstnumberPage size

Example

curl -X GET "https://admin.fanfare.io/api/v1/consumers/[email protected]" \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxx"

Sortable Fields

FieldDescription
createdAtConsumer creation date (default)
emailEmail address (alphabetical)
fullNameFull name (alphabetical)
lastOrderAtMost recent order date
totalOrderValueLifetime order value
totalOrdersTotal order count

SDK Usage

import { FanfareAdmin } from "@fanfare/admin-sdk";

const admin = new FanfareAdmin({
  secretKey: process.env.FANFARE_SECRET_KEY,
});

// Create consumer
const consumer = await admin.consumers.create({
  email: "[email protected]",
  fullName: "John Doe",
});

// List consumers with pagination
const { data: consumers, pageInfo } = await admin.consumers.list({
  first: 20,
  search: "john",
  sortBy: "createdAt",
  sortDir: "desc",
});

// Get next page
if (pageInfo.endCursor) {
  const nextPage = await admin.consumers.list({
    first: 20,
    after: pageInfo.endCursor,
  });
}

// Update consumer
await admin.consumers.update(consumer.id, {
  metadata: { tier: "vip" },
});

// Batch create
await admin.consumers.batchCreate([{ email: "[email protected]" }, { email: "[email protected]" }]);

// Delete consumer
await admin.consumers.delete(consumer.id);