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

# Login User

> Logs in a user and creates a session.



## OpenAPI

````yaml api-reference/v2/openapi-v2-stable.yaml post /login
openapi: 3.0.3
info:
  title: CoCart - Cart API v2
  version: 4.6.0
  description: >
    CoCart REST API v2 for managing shopping carts, products, and store
    functionality.

    Compared to API v1, this version provides enhanced endpoints for cart
    operations, product management,

    and administrative functions with improved response structures and better
    error handling.
  termsOfService: http://cocartapi.com/terms-of-conditions-polar/
  contact:
    email: support@cocartapi.com
  license:
    name: GNU General Public License v3.0
    url: http://www.gnu.org/licenses/gpl-3.0.html
servers:
  - url: '{protocol}://{host}/wp-json/cocart/v2'
    description: API v2
    variables:
      protocol:
        enum:
          - http
          - https
        default: https
      host:
        default: example-store.com
        description: Your store domain
security: []
tags:
  - name: cart
    description: Operations for managing the shopping cart
  - name: cart-items
    description: Operations for managing cart items
  - name: cart-calculate
    description: Operations for calculating cart totals
  - name: products
    description: Operations for browsing and retrieving product information
  - name: product-attributes
    description: Operations for retrieving product attributes and attribute terms
  - name: product-categories
    description: Operations for browsing and filtering product categories
  - name: product-tags
    description: Operations for browsing and filtering product tags
  - name: product-reviews
    description: Operations for retrieving product reviews and ratings
  - name: product-variations
    description: Operations for retrieving variable product variations
  - name: admin-sessions
    description: Administrative operations for managing cart sessions
  - name: authentication
    description: Operations for user authentication
  - name: store
    description: Operations for retrieving store information and configuration
externalDocs:
  description: Find out more about CoCart API
  url: https://docs.cocartapi.com
paths:
  /login:
    post:
      tags:
        - authentication
      summary: Login user
      description: Logs in a user and creates a session.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  description: Username or email address.
                  type: string
                password:
                  description: User password.
                  type: string
              required:
                - username
                - password
      responses:
        '200':
          description: User logged in successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoginResponse'
              example:
                user_id: '42'
                first_name: John
                last_name: Doe
                display_name: John Doe
                role: Customer
                avatar_urls:
                  '24': https://secure.gravatar.com/avatar/example?s=24&d=mm&r=g
                  '48': https://secure.gravatar.com/avatar/example?s=48&d=mm&r=g
                  '96': https://secure.gravatar.com/avatar/example?s=96&d=mm&r=g
                email: john.doe@example.com
                extras: {}
                dev_note: >-
                  Don't forget to store the users login information in order to
                  authenticate all other routes with CoCart.
        '400':
          description: Bad request - invalid credentials.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: cocart_invalid_credentials
                message: Invalid username or password.
                data:
                  status: 400
        '403':
          description: Authentication failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: cocart_authentication_failed
                message: Authentication failed. Please check your credentials.
                data:
                  status: 403
components:
  schemas:
    LoginResponse:
      type: object
      properties:
        user_id:
          type: string
          description: Unique ID of the user on the site.
        first_name:
          type: string
          description: The first name of the user (if any).
        last_name:
          type: string
          description: The last name of the user (if any).
        display_name:
          type: string
          description: The display name of the user (if any).
        role:
          type: string
          description: The role type assigned to the user.
        avatar_urls:
          type: object
          description: The avatar URLs of the user for each avatar size registered.
          additionalProperties:
            type: string
        email:
          type: string
          description: The email address of the user.
        extras:
          type: object
          description: Extra details added via the filter.
          additionalProperties: true
        dev_note:
          type: string
          description: A message to developers.
    ErrorResponse:
      type: object
      description: Standard error response structure.
      properties:
        code:
          type: string
          description: Machine-readable error code.
          example: cocart_invalid_parameter
        message:
          type: string
          description: Human-readable error message.
          example: Invalid parameter provided.
        data:
          type: object
          description: Additional error data.
          properties:
            status:
              type: integer
              description: HTTP status code.
              example: 400
            params:
              type: object
              description: Parameter-specific error details.
              additionalProperties: true
          additionalProperties: true

````