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

# Create Session

> Create a session and use it to initialize the SDK.

The value you receive in this endpoint should be subsequently passed into `KnotConfiguration` class of the SDK during initialization. Sessions last **30 minutes**. It is best practice to create a new session each time you initialize the SDK and not log the session in any internal or 3rd party tooling.


## OpenAPI

````yaml POST /session/create
openapi: 3.1.0
info:
  title: Knot API
  description: An API to interact with the Knot merchant connectivity platform.
  version: 1.0.0
servers:
  - url: https://development.knotapi.com
    description: Development server
security:
  - basicAuth: []
paths:
  /session/create:
    post:
      description: Create a session and use it to initialize the SDK.
      operationId: session_create
      requestBody:
        description: The input parameters required for creating a session.
        content:
          application/json:
            schema:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - card_switcher
                    - transaction_link
                    - link
                    - vault
                  description: Product to associate the session with.
                  example: card_switcher
                external_user_id:
                  type: string
                  description: Your unique identifier for the user.
                  example: 123abc
                card_id:
                  type:
                    - string
                    - 'null'
                  description: >-
                    Your unique identifier for a specific card. **Required when
                    `type = card_switcher`.** Optionally accepted when `type =
                    vault`.
                  example: 81n9al10a0ayn13
                  default: null
                email:
                  type:
                    - string
                    - 'null'
                  description: >-
                    User's email address. When provided, Knot will automatically
                    detect the user's online merchant accounts to personalize
                    the experience in the SDK.
                  example: ada.lovelace@gmail.com
                  default: null
                phone_number:
                  type:
                    - string
                    - 'null'
                  description: >-
                    User's phone number in E.164 format. When provided, Knot
                    will automatically detect the user's online merchant
                    accounts to personalize the experience in the SDK.
                  example: '+11234567890'
                  default: null
                processor_token:
                  type:
                    - string
                    - 'null'
                  description: >-
                    Plaid processor_token if using transaction data from Plaid
                    to detect merchants.
                  default: null
                metadata:
                  type:
                    - object
                    - 'null'
                  additionalProperties:
                    type: string
                    maxLength: 500
                  maxProperties: 10
                  description: >-
                    Optional key-value pairs to include in webhook payloads.
                    Maximum 10 keys, 500 characters per value.
                  example:
                    reference_token: abc123
                    trace_id: def456
                  default: null
              required:
                - type
                - external_user_id
            examples:
              CardSwitcher:
                summary: Card Switcher
                value:
                  type: card_switcher
                  external_user_id: abc123
                  card_id: 81n9al10a0ayn13
                  merchant_id: 45
                  email: ada.lovelace@gmail.com
                  phone_number: '+11234567890'
              TransactionLink:
                summary: Transaction Link
                value:
                  type: transaction_link
                  external_user_id: abc123
                  merchant_id: 45
              Link:
                summary: Link
                value:
                  type: link
                  external_user_id: abc123
                  merchant_id: 45
              Vault:
                summary: Vault
                value:
                  type: vault
                  external_user_id: abc123
                  merchant_id: 45
      responses:
        '200':
          description: Successful request.
          content:
            application/json:
              schema:
                type: object
                properties:
                  session:
                    type: string
                    description: A session.
                    example: 915efe72-5136-4652-z91q-d9d48003c102
        '400':
          description: Bad request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                CardIdRequired:
                  summary: 'card_id is missing for type: card_switcher'
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The card_id field is required when type = card_switcher.
                ExternalUserIdRequired:
                  summary: external_user_id is missing
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The external user id field is required.
                TypeRequired:
                  summary: type is missing
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The type field is required.
                InvalidPhoneNumber:
                  summary: Phone number is invalid
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The phone number format is invalid.
                InvalidEmail:
                  summary: Email is invalid
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The email must be a valid email address.
                InvalidProcessorToken:
                  summary: Processor token is invalid
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The processor token must be a string.
                InvalidCardBlocked:
                  summary: card.blocked is invalid
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The card.blocked field must be true or false.
        '401':
          description: Unauthorized request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                AuthFailed:
                  summary: Auth failed
                  value:
                    error_type: INVALID_INPUT
                    error_code: INVALID_API_KEYS
                    error_message: Invalid client_id or secret provided.
        '403':
          description: Forbidden request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                NoAccess:
                  summary: No access
                  value:
                    error_type: INVALID_REQUEST
                    error_code: NO_ACCESS
                    error_message: >-
                      The type is not enabled. Please contact Knot for access to
                      this endpoint.
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                InternalServerError:
                  summary: Unexpected server error
                  value:
                    message: Server Error
components:
  schemas:
    Error:
      type: object
      properties:
        error_type:
          type: string
          description: Type of error.
          enum:
            - INVALID_INPUT
            - INVALID_REQUEST
            - USER_ERROR
            - SESSION_ERROR
            - MERCHANT_ACCOUNT_ERROR
            - MERCHANT_ERROR
            - SUBSCRIPTION_ERROR
            - TRANSACTION_ERROR
            - CART_ERROR
          example: INVALID_REQUEST
        error_code:
          type: string
          description: Error code.
          enum:
            - INVALID_API_KEYS
            - INVALID_FIELD
            - INVALID_JWE
            - INVALID_CURSOR_FORMAT
            - USER_NOT_FOUND
            - MERCHANT_ACCOUNT_NOT_FOUND
            - MERCHANT_ACCOUNT_DISCONNECTED
            - SESSION_NOT_FOUND
            - EXTEND_NOT_SUPPORTED
            - MERCHANT_UNAVAILABLE
            - NO_ACCESS
            - TRANSACTION_NOT_FOUND
            - NO_TRANSACTIONS
            - SUBSCRIPTION_NOT_FOUND
            - ONGOING_OPERATION
            - CART_NOT_FOUND
            - FULFILLMENT_NOT_FOUND
          example: INVALID_FIELD
        error_message:
          type: string
          description: Detailed error message.
          example: The limit may not be greater than 10.
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: >-
        Basic authentication header of the form `Basic <encoded-value>`, where
        `<encoded-value>` is the base64-encoded string `username:password`. Use
        your `client_id` as the `username` and your `secret` as the `password`
        value.

````