> ## 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 Entity Cloud Script

> Cloud Script is one of PlayFab's most versatile features. It allows client code to request execution of any kind of custom server-side functionality you can implement, and it can be used in conjunction with virtually anything.

## Error codes

This operation may return the following PlayFab errors:

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




## OpenAPI

````yaml /services/playfab/api-references/rest/cloudscript/cloudscript.openapi.json post /CloudScript/ExecuteEntityCloudScript
openapi: 3.0.0
info:
  version: '260922'
  title: PlayFab CloudScript API
  description: API methods for executing CloudScript using an Entity Profile
  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: Server-Side Cloud Script
    description: Server-Side Cloud Script APIs
paths:
  /CloudScript/ExecuteEntityCloudScript:
    post:
      tags:
        - Server-Side Cloud Script
      summary: Execute Entity Cloud Script
      description: >
        Cloud Script is one of PlayFab's most versatile features. It allows
        client code to request execution of any kind of custom server-side
        functionality you can implement, and it can be used in conjunction with
        virtually anything.


        ## Error codes


        This operation may return the following PlayFab errors:


        | Error | Code |

        | --- | --- |

        | CloudScriptAPIRequestCountExceeded | 1209 |

        | CloudScriptAPIRequestError | 1210 |

        | CloudScriptFunctionArgumentSizeExceeded | 1208 |

        | CloudScriptHTTPRequestError | 1211 |

        | CloudScriptNotFound | 1136 |

        | InvalidEntityType | 1373 |

        | JavascriptException | 1099 |

        | TitleDeleted | 1347 |
      operationId: ExecuteEntityCloudScript
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExecuteEntityCloudScriptRequest'
        description: >-
          Executes CloudScript with the entity profile that is defined in the
          request.
      responses:
        '200':
          $ref: '#/components/responses/ExecuteCloudScriptResult'
        '400':
          $ref: '#/components/responses/ApiErrorWrapper'
      security:
        - EntityToken: []
components:
  schemas:
    ExecuteEntityCloudScriptRequest:
      description: >-
        Executes CloudScript with the entity profile that is defined in the
        request.
      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.
        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 'entity_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
        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
            SpecificRevision parameter is specified, otherwise it is 'Live'.
        SpecificRevision:
          description: >-
            The specific revision to execute, when RevisionSelection is set to
            'Specific'
          type: number
          x-actualtype: int32
      required:
        - FunctionName
      example:
        FunctionName: levelCompleted
        FunctionParameter:
          level: 3
          points: 400
        RevisionSelection: Live
        GeneratePlayStreamEvent: true
        Entity:
          Id: aaa
          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
    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:
    EntityToken:
      type: apiKey
      in: header
      name: X-EntityToken
      description: >-
        This API requires an Entity Session Token, available from the Entity
        GetEntityToken method.

````

## Related topics

- [Execute Entity Cloud Script](/services/playfab/api-references/rest/cloudscript/server-side-cloud-script/execute-entity-cloud-script.md)
- [PFCloudScriptExecuteEntityCloudScriptRequest](/services/playfab/api-references/c/pfcloudscripttypes/structs/pfcloudscriptexecuteentitycloudscriptrequest.md)
- [PFCloudScriptExecuteEntityCloudScriptAsync](/services/playfab/api-references/c/pfcloudscript/functions/pfcloudscriptexecuteentitycloudscriptasync.md)
- [PFCloudScriptExecuteEntityCloudScriptGetResult](/services/playfab/api-references/c/pfcloudscript/functions/pfcloudscriptexecuteentitycloudscriptgetresult.md)
- [entity_executed_cloud_script](/services/playfab/api-references/events/CloudScript/entity-executed-cloud-script.md)
