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

# Create Leaderboard Definition

> Creates a new leaderboard definition.

Allowed entity token types: title, game_server

## Error codes

This operation may return the following PlayFab errors:

| Error | Code |
| --- | --- |
| ApiNotEnabledForTitle | 1520 |
| DuplicateColumnNameFound | 1585 |
| DuplicateLinkedStatisticColumnNameFound | 1589 |
| EntityTypeMismatchWithStatDefinition | 1582 |
| ExternalEntityNotAllowedForTier | 1580 |
| InvalidBaseTimeForInterval | 1581 |
| LeaderboardCountLimitExceeded | 1574 |
| LeaderboardNameConflict | 1569 |
| LeaderboardSizeLimitExceeded | 1575 |
| LinkedStatisticColumnMismatch | 1570 |
| LinkedStatisticColumnNotFound | 1586 |
| LinkedStatisticColumnRequired | 1587 |
| LinkingStatsNotAllowedForEntityType | 1573 |
| MaxQueryableVersionsExceeded | 23015 |
| MaxQueryableVersionsValueNotAllowedForTier | 1591 |
| MultipleLinkedStatisticsNotAllowed | 1588 |
| PlayFabErrorEventNotSupportedForEntityType | 23013 |
| StatDefinitionAlreadyLinkedToLeaderboard | 1572 |
| StatisticNotFound | 1195 |
| VersionConfigurationIsRequired | 23005 |




## OpenAPI

````yaml post /Leaderboard/CreateLeaderboardDefinition
openapi: 3.0.0
info:
  version: '260922'
  title: PlayFab Progression API
  description: Manage entity statistics Manage entity leaderboards
  termsOfService: https://playfab.com/terms/
  contact:
    url: https://community.playfab.com/index.html
  license:
    name: Apache 2.0
    url: https://github.com/PlayFab/API_Specs/blob/master/LICENSE
servers:
  - url: https://{titleId}.playfabapi.com
    description: PlayFab title endpoint
    variables:
      titleId:
        default: your_title_id
        description: Your PlayFab title ID (hex).
security: []
tags:
  - name: Leaderboards
    description: Leaderboards APIs
  - name: Statistics
    description: Statistics APIs
paths:
  /Leaderboard/CreateLeaderboardDefinition:
    post:
      tags:
        - Leaderboards
      summary: Create Leaderboard Definition
      description: |
        Creates a new leaderboard definition.

        Allowed entity token types: title, game_server

        ## Error codes

        This operation may return the following PlayFab errors:

        | Error | Code |
        | --- | --- |
        | ApiNotEnabledForTitle | 1520 |
        | DuplicateColumnNameFound | 1585 |
        | DuplicateLinkedStatisticColumnNameFound | 1589 |
        | EntityTypeMismatchWithStatDefinition | 1582 |
        | ExternalEntityNotAllowedForTier | 1580 |
        | InvalidBaseTimeForInterval | 1581 |
        | LeaderboardCountLimitExceeded | 1574 |
        | LeaderboardNameConflict | 1569 |
        | LeaderboardSizeLimitExceeded | 1575 |
        | LinkedStatisticColumnMismatch | 1570 |
        | LinkedStatisticColumnNotFound | 1586 |
        | LinkedStatisticColumnRequired | 1587 |
        | LinkingStatsNotAllowedForEntityType | 1573 |
        | MaxQueryableVersionsExceeded | 23015 |
        | MaxQueryableVersionsValueNotAllowedForTier | 1591 |
        | MultipleLinkedStatisticsNotAllowed | 1588 |
        | PlayFabErrorEventNotSupportedForEntityType | 23013 |
        | StatDefinitionAlreadyLinkedToLeaderboard | 1572 |
        | StatisticNotFound | 1195 |
        | VersionConfigurationIsRequired | 23005 |
      operationId: CreateLeaderboardDefinition
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateLeaderboardDefinitionRequest'
      responses:
        '200':
          $ref: '#/components/responses/EmptyResponse'
        '400':
          $ref: '#/components/responses/ApiErrorWrapper'
      security:
        - EntityToken: []
components:
  schemas:
    CreateLeaderboardDefinitionRequest:
      type: object
      properties:
        Columns:
          description: >-
            Leaderboard columns describing the sort directions, cannot be
            changed after creation. A maximum of 5 columns are allowed.
          type: array
          items:
            $ref: '#/components/schemas/LeaderboardColumn'
          x-isclass: true
        CustomTags:
          description: >-
            The optional custom tags associated with the request (e.g. build
            number, external trace identifiers, etc.).
          type: object
        EntityType:
          description: >-
            The entity type being represented on the leaderboard. If it doesn't
            correspond to the PlayFab entity types, use 'external' as the type.
          type: string
        EventEmissionConfig:
          allOf:
            - $ref: '#/components/schemas/LeaderboardEventEmissionConfig'
          description: >-
            [In Preview]: The configuration for the events emitted by this
            leaderboard. If not specified, no events will be emitted.
        Name:
          description: A name for the leaderboard, unique per title.
          type: string
        SizeLimit:
          description: Maximum number of entries on this leaderboard
          type: number
          x-actualtype: int32
        VersionConfiguration:
          allOf:
            - $ref: '#/components/schemas/VersionConfiguration'
          description: The version reset configuration for the leaderboard definition.
      required:
        - Name
        - EntityType
        - Columns
        - SizeLimit
      example:
        Name: HighestScoresByLevel
        EntityType: title_player_account
        VersionConfiguration:
          MaxQueryableVersions: 1
        Columns:
          - Name: Hits
        SizeLimit: 1000
        EventEmissionConfig:
          VersionEndConfig: {}
          EntityRankOnVersionEndConfig:
            RankLimit: 1
    LeaderboardColumn:
      type: object
      properties:
        LinkedStatisticColumn:
          allOf:
            - $ref: '#/components/schemas/LinkedStatisticColumn'
          description: >-
            If the value for this column is sourced from a statistic, details of
            the linked column. Null if the leaderboard is not linked.
        Name:
          description: >-
            A name for the leaderboard column, unique per leaderboard
            definition.
          type: string
        SortDirection:
          allOf:
            - $ref: '#/components/schemas/LeaderboardSortDirection'
          description: The sort direction for this column.
      required:
        - Name
        - SortDirection
    LeaderboardEventEmissionConfig:
      type: object
      properties:
        EntityRankOnVersionEndConfig:
          allOf:
            - $ref: '#/components/schemas/LeaderboardEntityRankOnVersionEndConfig'
          description: >-
            This event emits the top ranks of the leaderboard when the
            leaderboard version end.
        VersionEndConfig:
          allOf:
            - $ref: '#/components/schemas/LeaderboardVersionEndConfig'
          description: This event is emitted when the leaderboard version end.
    VersionConfiguration:
      type: object
      properties:
        MaxQueryableVersions:
          description: >-
            The maximum number of versions of this leaderboard/statistic that
            can be queried. 
          type: number
          x-actualtype: int32
        ResetInterval:
          allOf:
            - $ref: '#/components/schemas/ResetInterval'
          description: >-
            Reset interval that statistics or leaderboards will reset on. When
            using Manual intervalthe reset can only be increased by calling the
            Increase version API. When using Hour interval the resetwill occur
            at the start of the next hour UTC time. When using Day interval the
            reset will occur at thestart of the next day in UTC time. When using
            the Week interval the reset will occur at the start ofthe next
            Monday in UTC time. When using Month interval the reset will occur
            at the start of the nextmonth in UTC time.
      required:
        - ResetInterval
        - MaxQueryableVersions
    EmptyResponse:
      type: object
      properties: {}
    ApiErrorWrapper:
      description: The basic wrapper around every failed API response
      type: object
      properties:
        code:
          description: Numerical HTTP code
          type: integer
        status:
          description: String HTTP code
          type: string
        error:
          description: Playfab error code
          type: string
        errorCode:
          description: Numerical PlayFab error code
          type: integer
        errorMessage:
          description: Description for the PlayFab errorCode
          type: string
        errorDetails:
          description: Detailed description of individual issues with the request object
          type: object
      required:
        - code
        - errorCode
    LinkedStatisticColumn:
      type: object
      properties:
        LinkedStatisticColumnName:
          description: >-
            The name of the statistic column that this leaderboard column is
            sourced from.
          type: string
        LinkedStatisticName:
          description: The name of the statistic.
          type: string
      required:
        - LinkedStatisticName
        - LinkedStatisticColumnName
    LeaderboardSortDirection:
      type: string
      enum:
        - Descending
        - Ascending
    LeaderboardEntityRankOnVersionEndConfig:
      type: object
      properties:
        EventType:
          allOf:
            - $ref: '#/components/schemas/EventType'
          description: The type of event to emit when the leaderboard version end.
        RankLimit:
          description: >-
            The maximum number of entity to return on leaderboard version end.
            Range is 1 to 1000.
          type: number
          x-actualtype: int32
      required:
        - EventType
        - RankLimit
    LeaderboardVersionEndConfig:
      type: object
      properties:
        EventType:
          allOf:
            - $ref: '#/components/schemas/EventType'
          description: The type of event to emit when the leaderboard version end.
      required:
        - EventType
    ResetInterval:
      type: string
      enum:
        - Manual
        - Hour
        - Day
        - Week
        - Month
    EventType:
      type: string
      enum:
        - None
        - Telemetry
        - PlayStream
  responses:
    EmptyResponse:
      description: ''
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: integer
                description: >-
                  The Http status code. If X-ReportErrorAsSuccess header is set
                  to true, this will report the actual http error code.
              status:
                type: string
                description: The Http status code as a string.
              data:
                $ref: '#/components/schemas/EmptyResponse'
    ApiErrorWrapper:
      description: This is the outer wrapper for all responses with errors
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorWrapper'
  securitySchemes:
    EntityToken:
      type: apiKey
      in: header
      name: X-EntityToken
      description: >-
        This API requires an Entity Session Token, available from the Entity
        GetEntityToken method.

````

## Related topics

- [Create Leaderboard Definition](/api-reference/leaderboards/create-leaderboard-definition.md)
- [PFLeaderboardsCreateLeaderboardDefinitionAsync](/services/playfab/api-references/c/pfleaderboards/functions/pfleaderboardscreateleaderboarddefinitionasync.md)
- [PFLeaderboardsCreateLeaderboardDefinitionRequest](/services/playfab/api-references/c/pfleaderboardstypes/structs/pfleaderboardscreateleaderboarddefinitionrequest.md)
- [PFLeaderboardsDeleteLeaderboardDefinitionAsync](/services/playfab/api-references/c/pfleaderboards/functions/pfleaderboardsdeleteleaderboarddefinitionasync.md)
- [API Leaderboard reference](/services/playfab/community/leaderboards/api-reference.md)
