Audience API (Beta)

Complete Audience API documentation including public user-facing endpoints and private backend-to-backend APIs for bulk operations and data exports.

The Audience API is a dual-interface system providing comprehensive loyalty and gamification features through two distinct APIs:

  • Public API: User-facing endpoints for self-service profile management (JWT authenticated)

  • Private API: Backend-to-backend endpoints for bulk operations and admin tasks (API key authenticated)

Architecture

Public API (User-Facing)

  • JWT token authentication

  • User-scoped operations (users can only access their own data)

  • Rate limit: 100 requests/minute per user

  • Endpoints: Profile, Transactions, Challenges, Notifications, Product Redemption

Private API (Backend-to-Backend)

  • API key + secret authentication

  • Organization-scoped operations (full access to org data)

  • Rate limit: 10,000 requests/minute per API key

  • Endpoints: Bulk operations, User search, Data exports

Base URL

https://api.monterosa.cloud/v1/api/audience

All requests require the X-Monterosa-Org-ID header with your organization ID.


Public API Endpoints

User Profile

GET /profile

Get the authenticated user's complete profile including loyalty metrics and active challenges.

Authentication: JWT Bearer token (required)

Response:

PATCH /profile

Update the authenticated user's profile. Users can update displayName, preferences, and custom fields only.

Authentication: JWT Bearer token (required)

Request Body:

Response:


Transactions

GET /transactions

List the authenticated user's transaction history with optional filters and pagination.

Authentication: JWT Bearer token (required)

Query Parameters:

  • limit (optional): Records per page (default: 50, max: 100)

  • type (optional): Filter by credit or debit

  • currency (optional): Filter by points, xp, or coins

  • lastEvaluatedKey (optional): Pagination token from previous response

Example: /transactions?type=credit&currency=points&limit=20

Response:


Challenges

GET /challenges

List the authenticated user's challenges with optional status filter.

Authentication: JWT Bearer token (required)

Query Parameters:

  • status (optional): Filter by in_progress, completed, or failed

  • limit (optional): Records per page (default: 20)

Response:


Notifications

GET /notifications

List the authenticated user's notifications with optional unread filter.

Authentication: JWT Bearer token (required)

Query Parameters:

  • unread (optional): If true, show only unread notifications

  • limit (optional): Records per page (default: 50, max: 50)

  • lastEvaluatedKey (optional): Pagination token

Response:

POST /notifications/{notificationId}/read

Mark a specific notification as read.

Authentication: JWT Bearer token (required)

Response:


Products

GET /products

List products available for redemption (only shows in-stock items).

Authentication: JWT Bearer token (required)

Response:

POST /products/{productId}/redeem

Redeem a product using loyalty currency (points, XP, or coins).

Authentication: JWT Bearer token (required)

Request Body:

Response (201 Created):


Private API Endpoints

Private endpoints require API key authentication via X-API-Key and X-API-Secret headers.

User Actions

POST /internal/actions

Report a single user action for processing by the loyalty rules engine.

Authentication: API Key (required)

Permissions: actions:write

Request Body:

Response (202 Accepted):

POST /internal/actions/bulk

Submit multiple user actions in bulk (max 1,000 actions per request).

Authentication: API Key (required)

Permissions: actions:write

Request Body:

Response (202 Accepted):


User Profiles

GET /internal/profiles

Retrieve multiple user profiles in batch (max 100 users per request).

Authentication: API Key (required)

Permissions: users:read

Query Parameters:

  • user_ids (required): Comma-separated list of user IDs

Example: /internal/profiles?user_ids=alice,bob,charlie

Response:

POST /internal/profiles/update-batch

Update multiple user profiles in bulk (max 1,000 updates per request).

Authentication: API Key (required)

Permissions: users:write

Request Body:

Response:


Rewards

POST /internal/rewards/bulk

Distribute rewards to multiple users (max 1,000 rewards per request).

Authentication: API Key (required)

Permissions: rewards:write

Request Body:

Response:


User Search & Export

POST /internal/users/search

Search users with advanced filtering and pagination.

Authentication: API Key (required)

Permissions: users:read

Request Body:

Response:

POST /internal/users/export

Create an encrypted export job for users matching search criteria. Exports are encrypted with AES-256-GCM and auto-expire after 24 hours.

Authentication: API Key (required)

Permissions: users:export

Request Body:

Response (202 Accepted):

GET /internal/exports/{exportId}

Get export job status and download information.

Authentication: API Key (required)

Permissions: users:read

Response:

Export Status Values:

  • processing - Export is being generated

  • completed - Export is ready for download

  • failed - Export generation failed

  • expired - Export has passed its 24-hour TTL


Authentication

Public API - JWT Tokens

Public endpoints require a JWT Bearer token:

JWT tokens should include:

  • sub: User ID

  • orgId: Organization ID

  • scope: Permissions array (e.g., ["audience:read", "audience:write"])

Private API - API Keys

Private endpoints require API key and secret:


Rate Limits

API Type
Requests/Minute
Requests/Hour
Burst

Public

100

1,000

20

Private

10,000

100,000

200

Batch Operation Limits

Operation
Maximum Items

User IDs per batch get

100

Profile updates per batch

1,000

Actions per bulk submit

1,000

Rewards per bulk distribute

1,000

Users per export

1,000,000


Error Responses

All endpoints return errors in this format:

Common HTTP Status Codes:

  • 400 - Bad Request (invalid parameters)

  • 401 - Unauthorized (missing or invalid auth)

  • 403 - Forbidden (insufficient permissions)

  • 404 - Not Found

  • 429 - Too Many Requests (rate limit exceeded)

  • 500 - Internal Server Error


Export Feature Details

Encryption

Exports are encrypted using AES-256-GCM with:

  • Auto-generated 32-character password

  • Random salt and initialization vector

  • Authentication tag for integrity verification

File Format

Encrypted files use the format: {salt}:{iv}:{authTag}:{encryptedData}

Expiration

  • Exports expire 24 hours after creation (configurable)

  • DynamoDB TTL automatically deletes expired job records

  • S3 lifecycle policy deletes files after 2 days

Processing

  1. Export job created with status processing

  2. Scheduled Lambda (every 5 minutes) processes pending exports

  3. Users queried and data formatted (CSV or JSON)

  4. Content encrypted if requested

  5. File uploaded to S3

  6. Email sent with download URL and password

  7. Job status updated to completed

Decryption

See the Data Export Guide for decryption instructions.


SDK Support

The Monterosa SDK provides wrapper functions for all Audience API endpoints with automatic:

  • Token refresh and management

  • Error handling and retry logic

  • Request rate limiting

  • Response caching

Recommended: Use the SDK for production applications instead of calling the API directly.


Additional Resources


Last updated