> ## Documentation Index
> Fetch the complete documentation index at: https://developers.perkstar.co.uk/llms.txt
> Use this file to discover all available pages before exploring further.

# Create an enrollment



## OpenAPI

````yaml /api/openapi.yaml post /enrollments
openapi: 3.1.0
info:
  title: Perkstar Public REST API
  version: 2026-05-04.oauth
  description: |
    Programmatic access to your Perkstar loyalty data. Two authentication
    modes are supported:

    - **API key.** Per-org bearer token issued from Settings → API keys
      (`pk_live_…` / `pk_test_…`). Right choice for direct integrations,
      single-tenant POS adapters, and back-office sync.
    - **OAuth 2.0.** Three-legged authorization-code flow with PKCE,
      for marketplace listings (Square App Marketplace, Shopify App
      Store, Toast Partner Marketplace, Lightspeed). The merchant
      installs your app from the partner marketplace, lands on
      `/oauth/authorize`, approves the requested scopes, and your
      server exchanges the code at `/api/oauth/token` for a short-lived
      access token. See the dedicated OAuth section below.

    Every endpoint is scoped, rate-limited, and idempotent on POST.
    POS-adapter builders should start with the `/marketplace/*`
    endpoints — they collapse the typical "find-or-create customer +
    enrolment + post transaction" flow into a single round-trip with
    permanent dedupe via `external_transaction_id`.

    ## Test credentials

    Test credentials (`pk_test_…` or OAuth applications in TEST mode)
    can read API data, create isolated test transactions, and simulate
    wallet pushes. They cannot create, update, or delete live customers,
    enrolments, or webhook configuration. Test calls to
    `/marketplace/accrue` only work with an existing customer and
    enrolment; `/marketplace/enroll` is live-only. This prevents a
    sandbox integration from changing live customer records.

    Copy-paste cURL recipes are published at `/api/v1/curl-recipes.md`
    for teams that want to test the API before wiring the SDK.

    ## Response headers (universal)

    Every response, success or error, carries:

    - **X-Request-Id** — unique per request. Echo this in support
      tickets; we can find the exact call in the per-key audit log.
    - **X-API-Version** — date-versioned schema marker
      (`2026-05-04` as of writing). 12-month deprecation policy.
    - **X-RateLimit-Limit** — per-minute quota for the credential.
    - **X-RateLimit-Remaining** — tokens left in the current window.
    - **X-RateLimit-Reset** — unix-seconds when the window refills.
    - **Retry-After** — emitted on 429 only; seconds to wait.

    The reusable error responses below (`Unauthorized`, `Forbidden`,
    `NotFound`, `RateLimited`, `ValidationError`) declare these as
    strongly-typed `headers` so codegen against an error path has
    them. Success responses inline their `"200"` / `"201"` and rely
    on this convention rather than per-endpoint header declarations.
  contact:
    name: Perkstar
    url: https://perkstar.co.uk
servers:
  - url: https://dashboard.perkstar.co.uk/api/v1
    description: Production
security:
  - bearerAuth: []
paths:
  /enrollments:
    post:
      tags:
        - Enrollments
      summary: Create an enrollment
      operationId: createEnrollment
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EnrollmentCreate'
      responses:
        '200':
          description: Existing enrollment returned (idempotent)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Enrollment'
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Enrollment'
      security:
        - bearerAuth: []
components:
  parameters:
    IdempotencyKey:
      in: header
      name: Idempotency-Key
      schema:
        type: string
        maxLength: 255
      description: |
        Replay-safe request key. Repeated requests with the same value
        within 24h return the original response unchanged.
  schemas:
    EnrollmentCreate:
      type: object
      required:
        - customer_id
        - card_id
      properties:
        customer_id:
          type: string
        card_id:
          type: string
        source:
          type: string
    Enrollment:
      type: object
      properties:
        id:
          type: string
        customer_id:
          type: string
        card_id:
          type: string
        status:
          type: string
          enum:
            - ACTIVE
            - INACTIVE
            - REVOKED
        balance:
          type: number
          multipleOf: 0.01
        redemptions_count:
          type: integer
        cumulative_spend_pence:
          type: integer
        bonus_points_balance:
          type: integer
        enrolled_at:
          type: string
          format: date-time
        last_activity_at:
          type: string
          nullable: true
          format: date-time
        wallet_passes:
          nullable: true
          description: |
            Install URLs for the Apple / Google wallet passes
            attached to this enrollment. Null when no passes have
            been issued yet (poll `GET /enrollments/{id}` to pick
            them up later). Per-platform values may be null when
            that platform's credentials aren't configured for the
            org. Always reuse these URLs — never reconstruct them.
          type: object
          properties:
            apple:
              type: string
              nullable: true
              description: pkpass download URL.
            google:
              type: string
              nullable: true
              description: |
                Freshly-signed Add-to-Wallet save link
                (`https://pay.google.com/gp/v/save/<jwt>`).
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: pk_live_… / pk_test_… or perk_at_…

````

## Related topics

- [Find-or-create customer + enrolment (no transaction)](/api-reference/marketplace/find-or-create-customer-+-enrolment-no-transaction.md)
- [Find-or-create customer + post transaction in one call](/api-reference/marketplace/find-or-create-customer-+-post-transaction-in-one-call.md)
- [Authentication and scopes](/fundamentals/authentication.md)
- [Update an enrollment](/api-reference/enrollments/update-an-enrollment.md)
- [Get an enrollment](/api-reference/enrollments/get-an-enrollment.md)
