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

# Link Card

> Link a parent NFC card to a subscriber account

<Info>
  Linking a card associates it with a subscriber's wallet. The subscriber's PIN is used for card transactions.
</Info>

## Request

<ParamField header="Authorization" type="string" required>
  `Bearer olive_live_xxx` or `Bearer eyJ...` (JWT)
</ParamField>

### Body Parameters

<ParamField body="subscriber_id" type="string" required>
  Subscriber UUID to link the card to
</ParamField>

<ParamField body="card_serial" type="string" required>
  Card serial number (e.g., `OLIV0001`)
</ParamField>

<ParamField body="pin" type="string" required>
  Subscriber's 4-digit PIN for verification
</ParamField>

***

## Response

<ResponseField name="success" type="boolean">
  Whether linking succeeded
</ResponseField>

<ResponseField name="message" type="string">
  Result message
</ResponseField>

<ResponseField name="card" type="object">
  Linked card details
</ResponseField>

***

## Examples

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://demo.api.vultlocal.com/api/v1/cards/link" \
    -H "Authorization: Bearer olive_live_xxx" \
    -H "Content-Type: application/json" \
    -d '{
      "subscriber_id": "sub_abc123",
      "card_serial": "OLIV0001",
      "pin": "1234"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "success": true,
    "message": "Card linked successfully",
    "card": {
      "serial": "OLIV0001",
      "mac_address": "AA:BB:CC:DD:EE:01",
      "type": "PARENT",
      "status": "ACTIVE",
      "subscriber_id": "sub_abc123",
      "linked_at": "2025-01-15T10:30:00Z"
    }
  }
  ```

  ```json 400 Already Linked theme={null}
  {
    "error": "Card is already linked to a subscriber",
    "code": "CARD_ALREADY_LINKED"
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "error": "Card not found",
    "code": "CARD_NOT_FOUND"
  }
  ```
</ResponseExample>

***

## Prerequisites

<CardGroup cols={2}>
  <Card title="Card Exists" icon="credit-card">
    Card must be uploaded via CSV first
  </Card>

  <Card title="Card Unassigned" icon="circle">
    Card status must be "Unassigned"
  </Card>
</CardGroup>

***

## Errors

| Status | Code                   | Description                       |
| ------ | ---------------------- | --------------------------------- |
| 400    | `INVALID_PIN`          | PIN verification failed           |
| 400    | `CARD_ALREADY_LINKED`  | Card linked to another subscriber |
| 401    | `UNAUTHORIZED`         | Invalid or missing API key        |
| 404    | `CARD_NOT_FOUND`       | Card serial doesn't exist         |
| 404    | `SUBSCRIBER_NOT_FOUND` | Subscriber ID invalid             |
| 500    | `INTERNAL_ERROR`       | Server error                      |


## OpenAPI

````yaml olive-openapi.json POST /cards/link
openapi: 3.0.0
info:
  description: >-
    API Gateway for OLIVE NFC Card Payment System - Comprehensive payment, card
    management, agent operations, and admin authentication. All /api/v1 routes
    require authentication using either API Key or JWT token.
  title: OLIVE NFC Card Payment API
  termsOfService: http://swagger.io/terms/
  contact:
    name: API Support
    email: support@olive.sl
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.0
servers:
  - url: https://olive-gateway-a6ba.onrender.com/api/v1
security: []
paths:
  /cards/link:
    post:
      tags:
        - Cards
      summary: Link parent card to subscriber
      description: Link a parent NFC card to a subscriber account
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/handler.LinkCardRequest'
        description: Link card details
        required: true
      responses:
        '200':
          description: Card linked successfully
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
      security:
        - ApiKeyAuth: []
        - BearerAuth: []
components:
  schemas:
    handler.LinkCardRequest:
      type: object
      required:
        - card_serial
        - pin
        - subscriber_id
      properties:
        card_serial:
          description: 'Supports any alphanumeric: CARD0001, 48290173K, etc.'
          type: string
          example: OLIV0001
        pin:
          type: string
          example: '1234'
        subscriber_id:
          type: string
          example: subscriber-uuid
  securitySchemes:
    ApiKeyAuth:
      description: >-
        API Key for third-party integrations (WhatsApp, Smart PAY, VULT).
        Format: 'Bearer olive_live_xxxxxxxxxxxxx'
      type: apiKey
      name: Authorization
      in: header
    BearerAuth:
      description: >-
        JWT token from admin login for administrative operations. Format:
        'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
      type: apiKey
      name: Authorization
      in: header

````