Get Started With Cosmo

This guide walks you through how to integrate your application with the Cosmo API. It’s designed for developers who want a clear, straightforward understanding of how to authenticate, work with partner programs, and issue points using Cosmo’s core endpoints.

Cosmo follows a simple flow: sign up, authenticate, retrieve your partnerships, and start issuing points. Sandbox mode lets you build and test safely before you connect to real partner programs in production.

By following the steps in this guide, you’ll learn how to:

  • Set up your organization and obtain API credentials
  • Authenticate and make authorized requests
  • Load the programs available to your business
  • Validate destination users
  • Preview and issue point transactions
  • Retrieve transactions and handle errors correctly
The goal is to help you get your integration running smoothly with as little friction as possible.

Account Setup

Cosmo supports two onboarding paths depending on your organization’s needs and operational workflow.

Managed Setup

For enterprises that require guided onboarding, Cosmo can manage the account creation and configuration process on your behalf. This includes:

  • Provisioning your organization in Cosmo
  • Assigning API credentials
  • Enabling program partnerships
  • Completing KYB and compliance checks
Your credentials and access details will be shared once configuration is complete.

Self-Service Setup

If you prefer to set up your account directly, follow the onboarding flow in the Cosmo Portal. Steps:

  • Sign up using your business email.
  • Enter your organization’s legal name.
  • Complete the automated KYB process.
  • Once approved, your organization and API credentials are created automatically.
After completion, you can immediately begin using Sandbox mode for development and testing

Sign Up

To begin using Cosmo, your team must create an organization and complete identity verification.

Sign Up Flow

  • Provide your organization’s legal details
  • Verify your email
  • Log into the Cosmo Portal
  • Submit your KYB information
  • Await automated approval (typically minutes)

Your API credentials (client_id and client_secret) will be visible once your KYB has been approved.

Sandbox Integration

Sandbox mode allows you to build and test your integration without affecting live partner programs. All transactions created in Sandbox are isolated and do not interact with production systems.

Sandbox Authentication

Sandbox uses the same authentication flow as production but with separate client credentials. Use your sandbox client_id and sandbox client_secret to obtain an access token.

Environment Behavior

  • All transactions are simulated
  • Error responses can be triggered deterministically using specific user IDs
  • Program configurations in Sandbox mirror the structure of Production
  • No real points are issued and no partner systems are contacted
Sandbox is designed to match production logic as closely as possible so your integration will behave identically when you switch environments.

User Flow

This section describes the complete flow your system will follow to issue points through Cosmo. Each step maps directly to a specific API endpoint, with links to the exact documentation for reference.

1. Authenticate

Your backend begins by authenticating with Cosmo using your client credentials. This returns a short-lived access token that must be included in all subsequent requests.

Endpoint:

POST /auth/token


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Authentication/operation/AuthController_token

What happens:

  • Your backend sends client_id and client_secret
  • Cosmo returns a JWT access token
  • All future requests must include Authorization: Bearer <token>
If the token expires, re-authenticate and retry.

2. Retrieve Partnerships

After authentication, your backend should fetch the partner programs available to your organization. This tells you which programs you can issue points to, and provides key metadata including programId and required account fields.

Endpoint:

GET /programs


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Programs/operation/ProgramsController_findAll

What this is used for:

  • Populating available partner programs in your UI
  • Obtaining the programId needed for issuing points
  • Reading program requirements (e.g., necessary destinationUserId fields)
Your system should cache this list but refresh periodically.

3. Issue points

This step performs the core business action: issuing loyalty points to a user for a selected partner program. The flow involves validation, optional previewing, and finally executing the transaction.

Validate User (Recommended)

Checks if the destination user is valid for the selected program.

Endpoint:

POST /programs/<programId>/validate-member


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Programs/operation/ProgramsController_validateMember

Use this before issuing points to reduce failed transactions.

Preview Transaction (Optional)

Returns how many points would be issued for a given value without creating a transaction.

Endpoint:

POST /transactions/preview


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Transactions/paths/~1transactions~1preview/post

Useful for showing “You will receive X points” in your UI.

Issue Transaction (Required)

Creates the actual transaction and issues points to the user.

Endpoint:

POST /transactions


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Transactions/operation/TransactionsController_create

Response includes:

  • transaction id
  • total points issued
  • referenceNumber
  • timestamp
Your backend should store these values for reconciliation.

Simulating Errors

Sandbox mode supports deterministic error simulation using predefined destinationUserId values.

This allows you to test:

  • Your backend error handling
  • Frontend error messaging
  • Retry and reconciliation flows
No dedicated endpoint — triggered through the normal Issue Points flow using sandbox IDs.

Possible Error Responses

Cosmo may return errors when a request violates authentication, validation, or program rules.

Common errors include:

  • Expired or invalid token
  • Missing required fields
  • Exceeding allowed transaction value limit
  • Exceeding allowed transaction points limit
  • Invalid program id
  • No partnership with the specified program
All errors follow a structured response format, enabling consistent handling in your system.

Key API endpoints

Cosmo provides a broad range of API endpoints beyond the essentials, enabling customized experiences throughout your user flow.

Validate User

Use this endpoint before issuing points to confirm that the destination user is valid for the selected loyalty program. This step prevents failed transactions and is recommended for all production-grade flows.

Endpoint:

POST /programs/<programId>/validate-member


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Programs/paths/~1programs~1%7BprogramId%7D~1validate-member/post

When to use:

  • Before issuing points
  • Before running an issue-points preview
  • To pre-check a user during onboarding flows

Request:

destinationUserId

destinationUserEmail


Response:

isValid = true or false

If false, do not proceed with issuing points. Use the Program Fields endpoint to understand which fields are required for the destination account.

Issue Points Preview (Dry Run)

This endpoint lets you check how many points will be issued for a given fiat value before committing a transaction. It is ideal for showing users “You will receive X points” in your UI.

Endpoint:

POST /transactions/preview


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Transactions/paths/~1transactions~1preview/post

When to use:

  • Showing point estimates in the UI
  • Pre-validating transaction value
  • Applying business rules before final submission

Request:

programId

value (fiat amount)

Response:

totalPoints (calculated for that program)

This call performs no transaction. You must still call the actual Issue Points endpoint to complete the operation.

Issue Points (Fiat Value)

This is the core transaction endpoint. Points are issued to the specified user, the transaction is recorded, and a unique transaction ID is returned.

Endpoint:

POST /transactions


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Transactions/paths/~1transactions/post

When to use:

  • To issue points based on a fiat amount
  • Standard use case for most integrations

Request:

programId

value

currency

destinationAccount

referenceNumber

description

Response:

id

totalPoints

referenceNumber

date

Store these values for reconciliation.

Issue Points (Exact Number of Points)

Instead of sending a fiat value, you can issue an exact number of points. This is useful when your system calculates the conversion or when you need deterministic issuance.

Endpoint:

POST /transactions (same endpoint)


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Transactions/paths/~1transactions/post

When to use:

  • Your application determines the exact points
  • You want fixed-point issuance rather than value-based issuance
  • Promotions, bonuses, partner-specific campaigns

Request:

programId

value

currency (POINTS)

destinationAccount

referenceNumber

description

Response:

Same format as value-based issuance.

If you’re unsure whether your organization has numberOfPoints mode enabled, test in sandbox or confirm with your account manager.

Get Program Fields

Each partner program may require different user identifiers. This endpoint reveals which fields you must include in the destination account object.

Endpoint:

GET /programs/<programId>/fields


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Programs/paths/~1programs~1%7BprogramId%7D~1fields/get

When to use:

  • Before validating a user
  • Before issuing points
  • To dynamically build your destinationAccount object

Response:

destinationUserId

destinationUserEmail

Use these fields to ensure your payload matches each program’s requirements.

Get Transaction

Use this endpoint to retrieve the full details of a previously issued transaction. This is important for reconciliation, customer support, audit trails, and verifying the final state of a transaction.

Endpoint:

GET /transactions/<transactionId>


See full documentation for this endpoint here:

https://api.cosmopoints.com/docs#tag/Transactions/paths/~1transactions~1%7BtransactionId%7D/get

When to use:

  • To confirm the final status of a transaction (especially after asynchronous flows)
  • To reconcile your internal ledger with Cosmo’s ledger
  • To display transaction details in your dashboard or to the end-user
  • For troubleshooting failed or partial transactions
  • When handling webhook retries or verifying you haven’t double-processed a transaction

Request:

transactionId (path parameter)

Production Integration

Once your integration works as expected in Sandbox, you can move to Production. The production environment uses the same API structure and endpoints, so no code changes are required — only updated credentials and real program configurations.

Production Credentials

Your production client_id and client_secret will be issued after:

  • Your KYB is approved
  • At least one partner program is enabled for your organization

These credentials must be stored securely and should never be exposed in client-side code.

Environment Changes

Production differs from Sandbox in the following ways:

  • Transactions interact with live partner systems
  • User validation checks real member accounts
  • All issued points are financially binding
  • Error simulation is not available

Recommended Steps Before Going Live

  • Confirm your organization has active partnerships
  • Validate the required destination fields for each program
  • Ensure all error cases are handled gracefully
  • Verify your reconciliation logic
  • Test your webhook handling (if used)

Once you replace your Sandbox token flow with Production credentials, your integration is considered live.

Going Live

Going Live means your system will start issuing real points to real user accounts. To ensure a smooth launch, your backend should follow a few final checks and operational best practices.

Final Pre-Launch Checks

  • Confirm your Production authentication flow is functioning
  • Validate at least one real user account using the Validate Member endpoint
  • Issue a small live transaction for internal testing
  • Confirm that you can retrieve the transaction via GET /transactions/<transactionId>
  • Verify all transaction details are stored in your internal system

Monitoring

After launch, monitor your integration for:

  • Failed transaction attempts
  • Token expiry errors
  • Incorrect or missing destination user fields
  • Unexpected increases in traffic
  • Any mismatches during reconciliation

Operational Notes

  • All Production transactions are permanent and billable
  • You should alert your team on any error spikes or partner program failures
  • Keep logs for validation, preview, and issue calls to support downstream audits

Once these items are confirmed, your integration is fully operational and ready to handle real users at scale.

Purchase Widget Integration

The Purchase widget lets you offer point purchases or exchanges without building your own frontend. You embed the widget in your web or mobile app; your backend handles authentication and post-transaction logic.

Use this if you:

  • Want a ready-made UX for buying/exchanging points
  • Prefer to keep all sensitive logic (auth, debits, reconciliation) on your backend

Authentication

Before launching the widget, your backend must obtain a short-lived access token.

This token:

  • Is valid for 10 minutes
  • Is passed as a query parameter to the widget URL
  • Must be obtained server-side only
  • Must never expose clientId or clientSecret in the frontend

Endpoint:

Request BodyCopy
1
Response BodyCopy
1

Your backend should return only the accessToken (or a wrapper around it) to your frontend.

Launching the Widget

On the frontend, you embed the widget using the access token returned by your backend.

Example (web, iFrame)Copy
1

Replace ACCESS_TOKEN with the token you obtained from the authentication step.

You can host the widget:

  • In a web app (iFrame or WebView)
  • In a mobile app via an in-app browser / webview

The widget handles:

  • Displaying available purchase/exchange options
  • Collecting any required user inputs
  • Sending the transaction request to Cosmo

Transaction Completion and Webhooks

When a transaction is completed via the Purchase widget, Cosmo sends a Transaction Webhook to your configured endpoint.

Your backend should:

  • Verify the webhook (see Section 10 – Webhooks)
  • Confirm the transactionId, value, and destination account details
  • Only then apply post-completion logic (for example: debit the user’s balance or update internal ledgers)

For the exact payload structure and signature verification, refer to the Transaction Webhook format in Section 10.

Multibrand Widget

The Multibrand widget lets users manage their reward preferences for a Multibrand card.

Users can:

  • Select and edit their preferred loyalty programs
  • Decide how rewards are allocated across multiple programs
  • Update preferences over time, with changes pushed back to your system via webhooks

Authentication

The Multibrand widget uses the same pattern as the Purchase widget: your backend obtains a short-lived access token for a specific user, then your frontend uses that token to launch the widget.

Key points:

  • Token lifetime: 10 minutes
  • Obtained via backend-to-backend call
  • Passed in the widget URL as a token query parameter
  • Never expose clientId or clientSecret to the frontend

Request BodyCopy
1
Response BodyCopy
1

Your backend should associate the user and card metadata with this token so you can later reconcile changes coming from webhooks.

Launching the Widget

On the frontend, embed the Multibrand widget using the access token provided by your backend.

Example (web, iFrame)Copy
1

Once launched, the widget:

  • Displays the list of available programs for that card
  • Allows users to add, remove, or edit reward preferences
  • Sends any changes back to your backend via webhooks

Program Preference Changes and Webhooks

Whenever a user changes their reward preferences in the Multibrand widget, Cosmo sends a Program Connection Webhook to your configured endpoint.

Your backend should:

  • Verify the webhook signature (see Section 10 – Webhooks)
  • Update the user’s reward configuration in your system based on:
    • destinationProgramId
    • destinationAccount fields (e.g., destinationUserId, destinationUserEmail)
    • sourceUserId
    • type (e.g., "LINKED", "DELINKED")

For the exact payload and signature verification example, refer to the Program Connection Webhook description in Section 10.

Webhooks

Cosmo uses webhooks to notify your backend of important events, such as completed point transactions or updates to a user’s Multibrand program preferences.

All webhook deliveries support multiple authentication mechanisms and include a signed payload for verification.

You can configure your webhook endpoints in the Cosmo Portal Developers Webhooks.

Authentication Methods

Cosmo supports three authentication modes for webhook delivery:

Basic Auth

Cosmo includes your configured username and password in the HTTP request.

Your server should verify these credentials before processing the payload.

OAuth 2.0

Cosmo obtains a token from the token endpoint you provide and includes it in webhook requests.

You may choose whether credentials are passed via:

  • Basic Auth header
  • Form-encoded in the body

Signature-Based Authentication (Recommended)

Cosmo signs every webhook request using your configured secret.

This enables your backend to cryptographically verify that the request is authentic and untampered.

The signature is included in the headers:

  • x-signature: <hex-encoded HMAC>
  • x-timestamp: <unix timestamp>

Use the verification steps below for every webhook type.

Transaction Webhook

Sent when a transaction (via API or Purchase widget) completes successfully.

Your backend should process the transaction only after receiving this webhook.

PayloadCopy
1

Typical uses:

  • Debit the user’s balance
  • Update your internal ledger
  • Display transaction results
  • Trigger downstream notifications

Program Connection Webhook

Sent when a user links, edits, or removes reward preferences in the Multibrand Widget.

PayloadCopy
1

Your backend should update your internal preference model based on this message.

Verifying Webhook Signatures

Every webhook delivered using Signature-Based Authentication includes:

  • x-signature: <computed HMAC SHA-256>
  • x-timestamp: <unix timestamp>

Your backend must:

  • Read the headers.
  • Obtain the raw JSON body exactly as sent.
  • Build the string: `${timestamp}:${rawBody}`
  • Compute: HMAC_SHA-256(secret, `${timestamp}:${rawBody}`)
  • Compare the result with x-signature.
  • Only process the webhook if the signatures match.

Full Node.js ExampleCopy
1

Best Practices

  • Always verify webhook signatures before processing any event.
  • Use timingSafeEqual to prevent timing attacks.
  • Log invalid signatures for security monitoring.
  • Store multiple versions of secrets if you rotate keys.
  • Do not parse or trust the webhook body until after signature validation.
  • Ensure your webhook endpoint is publicly reachable and uses HTTPS.