Refport
API ReferenceEmbed Tokens

Create Embed Token

Generate a short-lived public token for rendering the embedded referral portal for a specific partner.

POST /api/embed/token

Generates a short-lived public token that authorises a specific partner to view the embedded referral portal. The token is safe to expose to the browser — it's scoped to a single partner and expires quickly.

Request

Headers

HeaderValue
AuthorizationBearer YOUR_API_KEY
Content-Typeapplication/json

Body

{
  "partner": {
    "email": "alice@example.com",
    "name": "Alice"
  },
  "tenantId": "org_001"
}

At least one of tenantId, enrollmentId, or partner must be provided.

FieldTypeRequiredDescription
partner.emailstringYes (if partner provided)Partner's email address — used to look up or create the partner
partner.namestringNoPartner's display name — used when creating a new partner
tenantIdstringNoYour internal organisation or tenant ID
enrollmentIdstringNoBind the token to an existing enrollment record

If the partner does not exist in the program yet, Refport creates them automatically using the provided email and name.

Response

200 OK

{
  "publicToken": "pt_abc123...",
  "expires": "2024-01-15T12:30:00.000Z"
}
FieldTypeDescription
publicTokenstringThe token to pass to <RefportEmbed> or use in the iframe URL
expiresstringISO 8601 timestamp indicating when the token expires

Error responses

StatusCodeDescription
401UNAUTHORIZEDInvalid or missing API key
404NOT_FOUNDNo active referral program found for the organization
422VALIDATION_ERRORMissing or malformed required field
429RATE_LIMIT_EXCEEDEDToo many requests — retry after backing off

Token lifetime

Tokens expire after a short period (see the expires field in the response). Generate a fresh token on each page load — do not cache tokens across sessions or users.

SDK equivalent

const token = await refport.embedTokens.create({
  tenantId: 'org_001',
  partner: {
    email: 'alice@example.com',
    name: 'Alice',
  },
});
// token.publicToken — pass to <RefportEmbed>
// token.expires — Date object

See the Node.js SDK reference and Embedded Portal guide for full usage.

On this page