> ## Documentation Index
> Fetch the complete documentation index at: https://tapcoupon.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Apply template

> Activate a blank card or reconfigure an eligible existing card.

## POST `/cards/apply`

Activate a blank card or reconfigure an eligible existing card.

Send `Authorization: Bearer YOUR_API_KEY` and `X-Device-ID: YOUR_DEVICE_ID`. Also send `X-Employee-Token: YOUR_EMPLOYEE_TOKEN`. See [authentication](https://tapcoupon.mintlify.site/authentication.md).

A blank card can receive its first template. An existing card must be activated and fully used before normal reconfiguration.

To replace a freshly issued card, set `cancelPrevious: true`. This is rejected for blank cards, cards already used (`422 CANNOT_CANCEL_USED_CARD`), or cards already billed (`422 CARD_ALREADY_BILLED`). An unfinished card without cancellation returns `422 CARD_NOT_FINISHED`. See [card lifecycle](https://tapcoupon.mintlify.site/card-lifecycle.md).

For coupon templates, `isAmountSpecified: true` uses the fixed template amount. When false, supply a positive `amount` in cents. Supplying a nonpositive amount returns `400`.

`customer` is optional. When supplied, it must use the [nested customer format](https://tapcoupon.mintlify.site/customer-data.md) and satisfy the account's mandatory fields. `testCard` defaults to false. Test issuance is subject to test-window and count limits. Activation can generate a billing event.

### Example request

```bash theme={null}
curl -X POST "https://tapcoupon.at/api/v1/cards/apply" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "X-Device-ID: YOUR_DEVICE_ID" \
  -H "X-Employee-Token: YOUR_EMPLOYEE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "cardId": "9866191586296",
  "templateId": "693869428d49e641ba110e17",
  "customer": {
    "email": "bob@example.com",
    "contact": {
      "fullName": "Bob Example",
      "phone": "+43123456789"
    },
    "address": {
      "line1": "Bakers Street 41",
      "city": "Vienna",
      "postalCode": "1010",
      "countryCode": "AT"
    },
    "birthdate": "1990-06-15T00:00:00Z",
    "privacyConsentGiven": true
  }
}'
```

### Example response

```json theme={null}
{
  "success": true,
  "message": "Template applied to card successfully"
}
```


## OpenAPI

````yaml api-reference/openapi.json POST /cards/apply
openapi: 3.1.0
info:
  title: TapCoupon POS and partner API
  version: 1.0.0
  description: >-
    API-key POS operations, customer card views, and partner payment sessions.
    Verified against the tap_coupon backend on 2026-10-02. Dashboard /clients
    and administrative routes use separate authentication and are outside this
    reference.
servers:
  - url: https://tapcoupon.at/api/v1
security: []
paths:
  /cards/apply:
    post:
      tags:
        - Cards
      summary: Apply template
      description: Activate a blank card or reconfigure an eligible existing card.
      operationId: cards_apply_template
      parameters:
        - name: X-Device-ID
          in: header
          required: true
          description: Stable device identifier. API key binds to this value on first use.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                cardId:
                  type: string
                templateId:
                  type: string
                  description: MongoDB object id.
                  pattern: ^[a-fA-F0-9]{24}$
                amount:
                  type: integer
                  description: >-
                    Positive coupon amount in cents. Required for variable-value
                    coupon templates.
                  minimum: 1
                testCard:
                  type: boolean
                  description: >-
                    Request a test card, subject to the account test period and
                    card limit.
                customer:
                  $ref: '#/components/schemas/CustomerInput'
                cancelPrevious:
                  type: boolean
              required:
                - cardId
                - templateId
            example:
              cardId: '9866191586296'
              templateId: 693869428d49e641ba110e17
              customer:
                email: bob@example.com
                contact:
                  fullName: Bob Example
                  phone: '+43123456789'
                address:
                  line1: Bakers Street 41
                  city: Vienna
                  postalCode: '1010'
                  countryCode: AT
                birthdate: '1990-06-15T00:00:00Z'
                privacyConsentGiven: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
              example:
                success: true
                message: Template applied to card successfully
        '400':
          description: Invalid request, card type, balance, points, or location.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: >-
            Missing or invalid API key, device id, employee token, or
            credentials.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >-
            Device binding mismatch, archived location, employee location
            restriction, or account restriction.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Resource not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: Card inactive, fully used, or cannot be reconfigured.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: >-
            Rate limit exceeded. The response body is determined by the
            rate-limit middleware.
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
          employeeToken: []
components:
  schemas:
    CustomerInput:
      type: object
      properties:
        email:
          type: string
          format: email
          maxLength: 255
        contact:
          $ref: '#/components/schemas/Contact'
        address:
          anyOf:
            - $ref: '#/components/schemas/Address'
            - type: 'null'
        birthdate:
          type: string
          format: date-time
        privacyConsentGiven:
          type: boolean
      required:
        - email
        - contact
    Error:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error.
        errorCode:
          type: string
          description: >-
            Handler errors include a machine-readable code; middleware errors
            may omit it.
      required:
        - error
    Contact:
      type: object
      properties:
        fullName:
          type: string
          maxLength: 200
        displayName:
          type: string
          maxLength: 100
        company:
          type: string
          maxLength: 100
        phone:
          type: string
          maxLength: 20
      required:
        - fullName
    Address:
      type: object
      properties:
        line1:
          type: string
          maxLength: 255
        line2:
          type: string
          maxLength: 255
        city:
          type: string
          maxLength: 100
        state:
          type: string
          maxLength: 100
        postalCode:
          type: string
          maxLength: 20
        countryCode:
          type: string
          description: Two-letter country code.
          minLength: 2
          maxLength: 2
      required:
        - line1
        - city
        - postalCode
        - countryCode
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Location API key. Also requires X-Device-ID.
    employeeToken:
      type: apiKey
      in: header
      name: X-Employee-Token
      description: Employee session token from /employee/login.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.