Sonar User Tokens API

API token generation and management

OpenAPI Specification

sonar-user-tokens-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: SonarCloud Issues User Tokens API
  description: The SonarCloud API provides HTTP endpoints for programmatic interaction with SonarCloud — Sonar's cloud-based code quality and security analysis service. It enables management of organizations, projects, quality gates, issues, and analysis integrations with GitHub, GitLab, Bitbucket, and Azure DevOps. Token-based authentication is required for all endpoints.
  version: 1.0.0
  contact:
    name: SonarSource
    url: https://community.sonarsource.com/
  license:
    name: GNU Lesser General Public License v3.0
    url: https://www.gnu.org/licenses/lgpl-3.0.html
servers:
- url: https://sonarcloud.io/api
  description: SonarCloud API
tags:
- name: User Tokens
  description: API token generation and management
paths:
  /user_tokens/search:
    get:
      operationId: searchUserTokens
      summary: Search User Tokens
      description: List the user tokens associated with the authenticated user account. Returns token names and creation dates (not the actual token values).
      tags:
      - User Tokens
      security:
      - bearerAuth: []
      responses:
        '200':
          description: Successfully retrieved user tokens
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserTokenSearchResponse'
        '401':
          description: Unauthorized
  /user_tokens/generate:
    post:
      operationId: generateUserToken
      summary: Generate User Token
      description: Generate a new user token for API authentication. The token value is returned only once and must be stored securely. Tokens can be scoped to specific organizations.
      tags:
      - User Tokens
      security:
      - bearerAuth: []
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              required:
              - name
              properties:
                name:
                  type: string
                  description: Token name
                organizationKey:
                  type: string
                  description: Scope token to a specific organization
      responses:
        '200':
          description: Token generated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserToken'
        '400':
          description: Bad request
        '401':
          description: Unauthorized
components:
  schemas:
    UserToken:
      type: object
      properties:
        login:
          type: string
        name:
          type: string
        token:
          type: string
          description: Token value — only returned once at generation time
        createdAt:
          type: string
          format: date-time
    UserTokenSearchResponse:
      type: object
      properties:
        login:
          type: string
        userTokens:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              createdAt:
                type: string
                format: date-time
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: SonarCloud user token. Generate at https://sonarcloud.io/account/security. Pass as Bearer token or as basic auth username with empty password.