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

# Execute Cloud Script

> Executes a CloudScript function, with the 'currentPlayerId' set to the PlayFab ID of the authenticated player. The PlayFab ID is the entity ID of the player's master_player_account entity.

## Error codes

This operation may return the following PlayFab errors:

| Error | Code |
| --- | --- |
| CloudScriptAPIRequestCountExceeded | 1209 |
| CloudScriptAPIRequestError | 1210 |
| CloudScriptFunctionArgumentSizeExceeded | 1208 |
| CloudScriptHTTPRequestError | 1211 |
| CloudScriptNotFound | 1136 |
| JavascriptException | 1099 |
| ProductDisabledForTitle | 1609 |
| TitleDeleted | 1347 |




## OpenAPI

````yaml post /Server/ExecuteCloudScript
openapi: 3.0.0
info:
  version: '260922'
  title: PlayFab Server API
  description: >-
    Provides functionality to allow external (developer-controlled) servers to
    interact with user inventories and data in a trusted manner, and to handle
    matchmaking and client connection orchestration
  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: Account Management
    description: Account Management APIs
  - name: Analytics
    description: Analytics APIs
  - name: Authentication
    description: Authentication APIs
  - name: Character Data
    description: Character Data APIs
  - name: Characters
    description: Characters APIs
  - name: Content
    description: Content Service APIs
  - name: Friend List Management
    description: Friend List Management APIs
  - name: Matchmaking
    description: Matchmaking APIs
  - name: Platform Specific Methods
    description: Platform Specific Methods APIs
  - name: Player Data Management
    description: Player Data Management APIs
  - name: Player Item Management
    description: Player Item Management APIs
  - name: PlayStream
    description: PlayStream Management APIs
  - name: Server-Side Cloud Script
    description: Server-Side Cloud Script APIs
  - name: Shared Group Data
    description: Shared Group Data APIs
  - name: Title-Wide Data Management
    description: Title-Wide Data Management APIs
paths:
  /Server/ExecuteCloudScript:
    post:
      tags:
        - Server-Side Cloud Script
      summary: Execute Cloud Script
      description: >
        Executes a CloudScript function, with the 'currentPlayerId' set to the
        PlayFab ID of the authenticated player. The PlayFab ID is the entity ID
        of the player's master_player_account entity.


        ## Error codes


        This operation may return the following PlayFab errors:


        | Error | Code |

        | --- | --- |

        | CloudScriptAPIRequestCountExceeded | 1209 |

        | CloudScriptAPIRequestError | 1210 |

        | CloudScriptFunctionArgumentSizeExceeded | 1208 |

        | CloudScriptHTTPRequestError | 1211 |

        | CloudScriptNotFound | 1136 |

        | JavascriptException | 1099 |

        | ProductDisabledForTitle | 1609 |

        | TitleDeleted | 1347 |
      operationId: ExecuteCloudScript
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExecuteCloudScriptServerRequest'
      responses:
        '200':
          $ref: '#/components/responses/ExecuteCloudScriptResult'
        '400':
          $ref: '#/components/responses/ApiErrorWrapper'
      security:
        - SecretKey: []
components:
  schemas:
    ExecuteCloudScriptServerRequest:
      type: object
      properties:
        CustomTags:
          description: >-
            The optional custom tags associated with the request (e.g. build
            number, external trace identifiers, etc.).
          type: object
        FunctionName:
          description: The name of the CloudScript function to execute
          type: string
        FunctionParameter:
          description: Object that is passed in to the function as the first argument
          type: object
        GeneratePlayStreamEvent:
          description: >-
            Generate a 'player_executed_cloudscript' PlayStream event containing
            the results of the function execution and other contextual
            information. This event will show up in the PlayStream debugger
            console for the player in Game Manager.
          type: boolean
        PlayFabId:
          description: >-
            The unique user identifier for the player on whose behalf the script
            is being run
          type: string
        RevisionSelection:
          allOf:
            - $ref: '#/components/schemas/CloudScriptRevisionOption'
          description: >-
            Option for which revision of the CloudScript to execute. 'Latest'
            executes the most recently created revision, 'Live' executes the
            current live, published revision, and 'Specific' executes the
            specified revision. The default value is 'Specific', if the
            SpeificRevision parameter is specified, otherwise it is 'Live'.
        SpecificRevision:
          description: >-
            The specivic revision to execute, when RevisionSelection is set to
            'Specific'
          type: number
          x-actualtype: int32
      required:
        - PlayFabId
        - FunctionName
      example:
        PlayFabId: 1337D00D
        FunctionName: levelCompleted
        FunctionParameter:
          level: 3
          points: 400
        RevisionSelection: Live
        GeneratePlayStreamEvent: true
    CloudScriptRevisionOption:
      type: string
      enum:
        - Live
        - Latest
        - Specific
    ExecuteCloudScriptResult:
      type: object
      properties:
        APIRequestsIssued:
          description: Number of PlayFab API requests issued by the CloudScript function
          type: number
          x-actualtype: int32
        Error:
          allOf:
            - $ref: '#/components/schemas/ScriptExecutionError'
          description: Information about the error, if any, that occurred during execution
        ExecutionTimeSeconds:
          type: number
          x-actualtype: double
        FunctionName:
          description: The name of the function that executed
          type: string
        FunctionResult:
          description: The object returned from the CloudScript function, if any
          type: object
        FunctionResultTooLarge:
          description: >-
            Flag indicating if the FunctionResult was too large and was
            subsequently dropped from this event. This only occurs if the total
            event size is larger than 350KB.
          type: boolean
        HttpRequestsIssued:
          description: Number of external HTTP requests issued by the CloudScript function
          type: number
          x-actualtype: int32
        Logs:
          description: >-
            Entries logged during the function execution. These include both
            entries logged in the function code using log.info() and log.error()
            and error entries for API and HTTP request failures.
          type: array
          items:
            $ref: '#/components/schemas/LogStatement'
          x-isclass: true
        LogsTooLarge:
          description: >-
            Flag indicating if the logs were too large and were subsequently
            dropped from this event. This only occurs if the total event size is
            larger than 350KB after the FunctionResult was removed.
          type: boolean
        MemoryConsumedBytes:
          type: number
          x-actualtype: uint32
        ProcessorTimeSeconds:
          description: >-
            Processor time consumed while executing the function. This does not
            include time spent waiting on API calls or HTTP requests.
          type: number
          x-actualtype: double
        Revision:
          description: The revision of the CloudScript that executed
          type: number
          x-actualtype: int32
      required:
        - Revision
        - ExecutionTimeSeconds
        - ProcessorTimeSeconds
        - MemoryConsumedBytes
        - APIRequestsIssued
        - HttpRequestsIssued
      example:
        Revision: 3
        FunctionResult:
          newScore: 25
        Logs:
          - Level: Info
            Message: Something normal happened
            Data:
              secondsAfterStart: 75
          - Level: Error
            Message: Something unexpected happened
        ExecutionTimeSeconds: 0.03670790046453476
        MemoryConsumedBytes: 38904
        APIRequestsIssued: 2
    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
    ScriptExecutionError:
      type: object
      properties:
        Error:
          description: >-
            Error code, such as CloudScriptNotFound, JavascriptException,
            CloudScriptFunctionArgumentSizeExceeded,
            CloudScriptAPIRequestCountExceeded, CloudScriptAPIRequestError, or
            CloudScriptHTTPRequestError
          type: string
        Message:
          description: Details about the error
          type: string
        StackTrace:
          description: >-
            Point during the execution of the script at which the error
            occurred, if any
          type: string
    LogStatement:
      type: object
      properties:
        Data:
          description: Optional object accompanying the message as contextual information
          type: object
        Level:
          description: '''Debug'', ''Info'', or ''Error'''
          type: string
        Message:
          type: string
  responses:
    ExecuteCloudScriptResult:
      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/ExecuteCloudScriptResult'
            example:
              code: 200
              status: OK
              data:
                Revision: 3
                FunctionResult:
                  newScore: 25
                Logs:
                  - Level: Info
                    Message: Something normal happened
                    Data:
                      secondsAfterStart: 75
                  - Level: Error
                    Message: Something unexpected happened
                ExecutionTimeSeconds: 0.03670790046453476
                MemoryConsumedBytes: 38904
                APIRequestsIssued: 2
    ApiErrorWrapper:
      description: This is the outer wrapper for all responses with errors
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorWrapper'
  securitySchemes:
    SecretKey:
      type: apiKey
      in: header
      name: X-SecretKey
      description: >-
        This API requires a title secret key, available to title admins, from
        PlayFab Game Manager.

````

## Related topics

- [Execute Cloud Script](/services/playfab/api-references/rest/client/server-side-cloud-script/execute-cloud-script.md)
- [PFCloudScriptExecuteCloudScriptRequest](/services/playfab/api-references/c/pfcloudscripttypes/structs/pfcloudscriptexecutecloudscriptrequest.md)
- [PFCloudScriptExecuteCloudScriptResult](/services/playfab/api-references/c/pfcloudscripttypes/structs/pfcloudscriptexecutecloudscriptresult.md)
- [PFCloudScriptExecuteCloudScriptServerRequest](/services/playfab/api-references/c/pfcloudscripttypes/structs/pfcloudscriptexecutecloudscriptserverrequest.md)
- [PFCloudScriptClientExecuteCloudScriptAsync](/services/playfab/api-references/c/pfcloudscript/functions/pfcloudscriptclientexecutecloudscriptasync.md)
