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

# Create a user

> Creates a Stockly user. At least one of `email` or `externalId` must be provided; both are unique within your app. Once created, a user can be given stock and have a portfolio.



## OpenAPI

````yaml /openapi.json post /v1/users
openapi: 3.1.0
info:
  title: Stockly Partner API
  description: >-
    Create users, give them stock, and read their portfolios. All requests and
    responses are JSON.
  version: 1.0.0
servers:
  - url: https://api.stockly.com
    description: Production (replace with your Stockly API base URL)
security:
  - apiKey: []
tags:
  - name: Users
    description: Your customers.
  - name: Stock awards
    description: Give users stock and read back award status.
  - name: Portfolio
    description: A user's live stock holdings.
  - name: Catalog
    description: Stocks available to give.
paths:
  /v1/users:
    post:
      tags:
        - Users
      summary: Create a user
      description: >-
        Creates a Stockly user. At least one of `email` or `externalId` must be
        provided; both are unique within your app. Once created, a user can be
        given stock and have a portfolio.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateUserRequest'
            example:
              email: jane@example.com
              externalId: acme-user-42
      responses:
        '201':
          description: User created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserResponse'
              example:
                user:
                  id: 6f1d2a3b-7c8d-4e9f-a0b1-c2d3e4f5a6b7
                  appId: 1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d
                  email: jane@example.com
                  externalId: acme-user-42
                  createdAt: '2026-06-13T12:00:00.000Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          description: A user with this email or externalId already exists in your app
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CreateUserRequest:
      type: object
      description: At least one of email or externalId is required.
      properties:
        email:
          type: string
          format: email
          maxLength: 320
          description: Unique within your app.
        externalId:
          type: string
          minLength: 1
          maxLength: 128
          description: Your own user identifier. Unique within your app.
    UserResponse:
      type: object
      properties:
        user:
          $ref: '#/components/schemas/User'
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - bad_request
                - unauthorized
                - forbidden
                - not_found
                - conflict
                - unprocessable_entity
                - internal_error
                - upstream_error
            message:
              type: string
            details:
              description: Optional structured detail (e.g. validation issues).
            requestId:
              type: string
              description: Correlation id, also returned in the x-request-id header.
      example:
        error:
          code: conflict
          message: idempotencyKey was already used with a different payload
          details:
            idempotencyKey: order-1001-reward
          requestId: f0e1d2c3-4b5a-6789-0abc-def012345678
    User:
      type: object
      properties:
        id:
          type: string
          format: uuid
        appId:
          type: string
          format: uuid
        email:
          type:
            - string
            - 'null'
        externalId:
          type:
            - string
            - 'null'
        createdAt:
          type: string
          format: date-time
  responses:
    BadRequest:
      description: >-
        Invalid JSON or request validation failed (details contains the specific
        issues)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing or invalid x-api-key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Your Stockly API key. Identifies your app; you never pass an app id.

````