Documentation

ExecuteEntityCloudScript

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.

Request Details

Executes CloudScript with the entity profile that is defined in the request.

ExecuteEntityCloudScriptRequest
Request Properties
Entity EntityKey

The entity to perform this action on.

FunctionName (required) String

The name of the CloudScript function to execute

FunctionParameter object

Object that is passed in to the function as the first argument

GeneratePlayStreamEvent Boolean

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.

RevisionSelection CloudScriptRevisionOption

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 int32

The specific revision to execute, when RevisionSelection is set to 'Specific'

POST https://{{TitleID}}.playfabapi.com/CloudScript/ExecuteEntityCloudScript
    Content-Type: application/json
{
  "FunctionName": "levelCompleted",
  "FunctionParameter": {
    "level": 3,
    "points": 400
  },
  "RevisionSelection": "Live",
  "GeneratePlayStreamEvent": true,
  "Entity": {
    "Id": "master_player_account",
    "Type": "aaa",
    "TypeString": "aaa"
  }
}
        

Response Details

ExecuteCloudScriptResult
Result Properties
APIRequestsIssued (required) int32

Number of PlayFab API requests issued by the CloudScript function

Error ScriptExecutionError

Information about the error, if any, that occurred during execution

ExecutionTimeSeconds (required) double

FunctionName String

The name of the function that executed

FunctionResult object

The object returned from the CloudScript function, if any

FunctionResultTooLarge Boolean

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.

HttpRequestsIssued (required) int32

Number of external HTTP requests issued by the CloudScript function

Logs List<LogStatement>

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.

LogsTooLarge Boolean

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.

MemoryConsumedBytes (required) uint32

ProcessorTimeSeconds (required) double

Processor time consumed while executing the function. This does not include time spent waiting on API calls or HTTP requests.

Revision (required) int32

The revision of the CloudScript that executed

Sample Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
  "code": 200,
  "status": "OK",
  "data": {
    "Revision": 3,
    "FunctionResult": {
      "newScore": 25,
      "isWinner": false
    },
    "Logs": [
      {
        "Level": "Info",
        "Message": "Something normal happened",
        "Data": {
          "secondsAfterStart": 75
        }
      },
      {
        "Level": "Error",
        "Message": "Something unexpected happened"
      }
    ],
    "ExecutionTimeSeconds": 0.03670790046453476,
    "ProcessorTimeSeconds": 0.0,
    "MemoryConsumedBytes": 38904,
    "APIRequestsIssued": 2,
    "HttpRequestsIssued": 0
  }
}

Authentication

EntityToken

Possible Error Codes

Name Code
CloudScriptAPIRequestCountExceeded 1209
CloudScriptAPIRequestError 1210
CloudScriptFunctionArgumentSizeExceeded 1208
CloudScriptHTTPRequestError 1211
CloudScriptNotFound 1136
JavascriptException 1099