> ## 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.

# Update Statistics

> Update statistics on an entity profile. Depending on the statistic definition, this may result in entity being ranked on various leaderboards.

Allowed entity token types: title, title_player_account, game_server

## Error codes

This operation may return the following PlayFab errors:

| Error | Code |
| --- | --- |
| APINotEnabledForGameClientAccess | 1082 |
| EntityIsNotAMember | 1615 |
| EntityTypeMismatchWithStatDefinition | 1582 |
| InvalidEntityType | 1373 |
| InvalidEntityTypeForAggregation | 23006 |
| InvalidExternalEntityId | 1594 |
| InvalidStatisticScore | 1563 |
| MetadataLengthExceeded | 23014 |
| NotAuthorized | 1089 |
| StatisticColumnLengthMismatch | 1593 |
| StatisticNotFound | 1195 |
| StatisticUpdateNotAllowedWhileLinked | 23010 |
| TransactionAlreadyApplied | 1596 |
| UpdatingStatisticsUsingTransactionIdNotAvailableForFreeTier | 1595 |




## OpenAPI

````yaml post /Statistic/UpdateStatistics
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:
  /Statistic/UpdateStatistics:
    post:
      tags:
        - Statistics
      summary: Update Statistics
      description: >
        Update statistics on an entity profile. Depending on the statistic
        definition, this may result in entity being ranked on various
        leaderboards.


        Allowed entity token types: title, title_player_account, game_server


        ## Error codes


        This operation may return the following PlayFab errors:


        | Error | Code |

        | --- | --- |

        | APINotEnabledForGameClientAccess | 1082 |

        | EntityIsNotAMember | 1615 |

        | EntityTypeMismatchWithStatDefinition | 1582 |

        | InvalidEntityType | 1373 |

        | InvalidEntityTypeForAggregation | 23006 |

        | InvalidExternalEntityId | 1594 |

        | InvalidStatisticScore | 1563 |

        | MetadataLengthExceeded | 23014 |

        | NotAuthorized | 1089 |

        | StatisticColumnLengthMismatch | 1593 |

        | StatisticNotFound | 1195 |

        | StatisticUpdateNotAllowedWhileLinked | 23010 |

        | TransactionAlreadyApplied | 1596 |

        | UpdatingStatisticsUsingTransactionIdNotAvailableForFreeTier | 1595 |
      operationId: UpdateStatistics
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateStatisticsRequest'
      responses:
        '200':
          $ref: '#/components/responses/UpdateStatisticsResponse'
        '400':
          $ref: '#/components/responses/ApiErrorWrapper'
      security:
        - EntityToken: []
components:
  schemas:
    UpdateStatisticsRequest:
      type: object
      properties:
        CustomTags:
          description: >-
            The optional custom tags associated with the request (e.g. build
            number, external trace identifiers, etc.).
          type: object
        Entity:
          allOf:
            - $ref: '#/components/schemas/EntityKey'
          description: >-
            The optional entity to perform this action on. Defaults to the
            currently logged in entity.
        Statistics:
          description: Collection of statistics to update, maximum 50.
          type: array
          items:
            $ref: '#/components/schemas/StatisticUpdate'
          x-isclass: true
        TransactionId:
          description: >-
            Optional transactionId of this update which can be used to ensure
            idempotence.
          type: string
      required:
        - Statistics
      example:
        Statistics:
          - Name: RoundsWon
            Metadata: BestRun:34.13,Car:13452
            Scores:
              - '100'
              - '200'
          - Name: FastestTimesByMap
            Metadata: Car:13452
            Scores:
              - '200'
              - '300'
          - Name: TotalCarTime
            Scores:
              - '300'
              - '400'
        Entity:
          Id: A197412JDA
          Type: title_player_account
          TypeString: title_player_account
    EntityKey:
      description: >-
        Combined entity type and ID structure which uniquely identifies a single
        entity.
      type: object
      properties:
        Id:
          description: Unique ID of the entity.
          type: string
        Type:
          description: >-
            Entity type. See
            https://learn.microsoft.com/gaming/playfab/features/data/entities/available-built-in-entity-types
          type: string
      required:
        - Id
    StatisticUpdate:
      type: object
      properties:
        AggregationTargetEntityKeys:
          description: >-
            A list of entities to which the statistic update must be aggregated
            to, in addition to the entity being updated. For example, for Group
            stats where the stat value is aggregated based on the group members,
            this would refer to the Group entity. For a community stat that's
            aggregated at the Title, it is not required to populate this
            property (Title is the default).
          type: array
          items:
            $ref: '#/components/schemas/EntityKey'
          x-isclass: true
        Metadata:
          description: >-
            Arbitrary metadata to store along side the statistic, will be
            returned by all Leaderboard APIs.
          type: string
        Name:
          description: Name of the statistic, as originally configured.
          type: string
        Scores:
          description: >-
            Statistic scores for the entity. This will be used in accordance
            with the aggregation method configured for the statistics.The
            maximum value allowed for each individual score is
            9223372036854775807. The minimum value for each individual score is
            -9223372036854775807The values are formatted as strings to avoid
            interop issues with client libraries unable to handle 64bit
            integers.
          type: array
          items:
            type: string
        Version:
          description: >-
            Optional field to indicate the version of the statistic to set. When
            empty defaults to the statistic's current version.
          type: number
          x-actualtype: uint32
      required:
        - Name
    UpdateStatisticsResponse:
      type: object
      properties:
        ColumnDetails:
          allOf:
            - $ref: '#/components/schemas/StatisticColumnCollection'
          description: >-
            A mapping of statistic name to the columns defined in the
            corresponding definition.
        Entity:
          allOf:
            - $ref: '#/components/schemas/EntityKey'
          description: The entity id and type.
        Statistics:
          allOf:
            - $ref: '#/components/schemas/EntityStatisticValue'
          description: Updated entity profile statistics.
      example:
        ProfileVersion: 56
        Statistics:
          SpeedRuns:
            Name: SpeedRuns
            Value: 89
        Entity:
          Id: '184131840178'
          Type: title_player_account
          TypeString: title_player_account
    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
    StatisticColumnCollection:
      type: object
      properties:
        Columns:
          description: >-
            Columns for the statistic defining the aggregation method for each
            column.
          type: array
          items:
            $ref: '#/components/schemas/StatisticColumn'
          x-isclass: true
    EntityStatisticValue:
      type: object
      properties:
        Metadata:
          description: Metadata associated with the Statistic.
          type: string
        Name:
          description: Statistic name
          type: string
        Scores:
          description: Statistic scores
          type: array
          items:
            type: string
        Version:
          description: Statistic version
          type: number
          x-actualtype: int32
      required:
        - Version
    StatisticColumn:
      type: object
      properties:
        AggregationMethod:
          allOf:
            - $ref: '#/components/schemas/StatisticAggregationMethod'
          description: Aggregation method for calculating new value of a statistic.
        Name:
          description: Name of the statistic column, as originally configured.
          type: string
      required:
        - Name
        - AggregationMethod
    StatisticAggregationMethod:
      type: string
      enum:
        - Last
        - Min
        - Max
        - Sum
  responses:
    UpdateStatisticsResponse:
      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/UpdateStatisticsResponse'
            example:
              code: 200
              status: OK
              data:
                ProfileVersion: 56
                Statistics:
                  SpeedRuns:
                    Name: SpeedRuns
                    Value: 89
                Entity:
                  Id: '184131840178'
                  Type: title_player_account
                  TypeString: title_player_account
    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

- [Update Statistics](/api-reference/statistics/update-statistics.md)
- [Update Player Statistics](/services/playfab/api-references/rest/client/player-data-management/update-player-statistics.md)
- [Update Character Statistics](/services/playfab/api-references/rest/client/characters/update-character-statistics.md)
- [Update Statistic Definition](/api-reference/statistics/update-statistic-definition.md)
- [PFStatisticsUpdateStatisticsRequest](/services/playfab/api-references/c/pfstatisticstypes/structs/pfstatisticsupdatestatisticsrequest.md)
