Documentation

GetCloudScriptRevision

Gets the contents and information of a specific Cloud Script revision.

Request Details

GetCloudScriptRevisionRequest
Request Properties
Revision int32

Revision number. If left null, defaults to the latest revision

Version int32

Version number. If left null, defaults to the latest version

POST https://{{TitleID}}.playfabapi.com/Admin/GetCloudScriptRevision
    Content-Type: application/json
    X-SecretKey: <developer_secret_key>
{
  "Version": 1,
  "Revision": 3
}
        

Response Details

GetCloudScriptRevisionResult
Result Properties
CreatedAt (required) DateTime

Time this revision was created

Files List<CloudScriptFile>

List of Cloud Script files in this revision.

IsPublished (required) Boolean

True if this is the currently published revision

Revision (required) int32

Revision number.

Version (required) int32

Version number.

Sample Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
  "code": 200,
  "status": "OK",
  "data": {
    "Version": 1,
    "Revision": 3,
    "CreatedAt": "2015-01-03T17:44:21Z",
    "Files": [
      {
        "Filename": "main.js",
        "FileContents": "var LevelRewards =\r\n[\r\n\t[\"TestItem1\"],\r\n\t[\"TestItem2\"],\r\n\t[\"TestItem3\"],\r\n\t[\"TestItem1\", \"TestItem2\"],\r\n\t[\"TestItem2\", \"TestItem2\"],\r\n\t[\"TestItem3\", \"TestItem3\"]\r\n]\r\n\r\nhandlers.onLevelComplete = function(args)\r\n{\r\n\tvar levelNum = args.level;\r\n\t\r\n\t// Do some basic input validation\r\n\tif(levelNum < 0 || levelNum >= LevelRewards.length)\r\n\t{\r\n\t\tlog.info(\"Invalid level \"+levelNum+\" completed by \"+currentPlayerId);\r\n\t\treturn {};\r\n\t}\r\n\t\r\n\tvar levelCompleteKey = \"LevelCompleted\"+levelNum;\r\n\t\r\n\t// Get the user's internal data\r\n\tvar playerInternalData = server.GetUserInternalData(\r\n\t{\r\n\t\tPlayFabId: currentPlayerId,\r\n\t\tKeys: [levelCompleteKey]\r\n\t});\r\n\t\r\n\t// Did they already complete this level?\r\n\tif(playerInternalData.Data[levelCompleteKey])\r\n\t{\r\n\t\tlog.info(\"Player \"+currentPlayerId+\" already completed level \"+levelNum);\r\n\t\treturn {};\r\n\t}\r\n\t\r\n\tvar rewards = LevelRewards[levelNum];\r\n\t\r\n\tvar resultItems = null;\r\n\tif(rewards)\r\n\t{\r\n\t\t// Grant reward items to player for completing the level\r\n\t\tvar itemGrantResult = server.GrantItemsToUser(\r\n\t\t{\r\n\t\t\tPlayFabId: currentPlayerId,\r\n\t\t\tAnnotation: \"Given by completing level \"+levelNum,\r\n\t\t\tItemIds: rewards\r\n\t\t});\r\n\t\t\r\n\t\tresultItems = itemGrantResult.ItemGrantResults;\r\n\t}\r\n\t\r\n\t// Mark the level as being completed so they can't get the reward again\r\n\tvar saveData = {};\r\n\tsaveData[levelCompleteKey] = \"true\";\r\n\tserver.UpdateUserInternalData(\r\n\t{\r\n\t\tPlayFabId: currentPlayerId,\r\n\t\tData: saveData\r\n\t});\r\n\r\n\t// Return the results of the item grant so the client can see what they got\r\n\treturn {\r\n\t\trewards: resultItems\r\n\t};\r\n}\r\n\r\nvar monsterRewards =\r\n{\r\n\t\"skrill\" : { \"ChumpCoins\" : 100},\r\n\t\"lumpur\" : { \"ChumpCoins\" : 200}\r\n}\r\n\r\nvar killCoolDown = 60;\r\n\r\nfunction currTimeSeconds()\r\n{\r\n\tvar now = new Date();\r\n\treturn now.getTime() / 1000;\r\n}\r\n\r\nhandlers.monsterKilled = function(args)\r\n{\r\n\tvar monsterType = args.type;\r\n\t\r\n\tvar now = currTimeSeconds();\r\n\t\r\n\t// Get the user's internal data\r\n\tvar playerInternalData = server.GetUserInternalData(\r\n\t{\r\n\t\tPlayFabId: currentPlayerId,\r\n\t\tKeys: [\"lastKill\"]\r\n\t});\r\n\t\r\n\t// Check when the last time they killed a monster was \r\n\tvar lastKill = playerInternalData.Data[\"lastKill\"];\r\n\tif(lastKill)\r\n\t{\r\n\t\t// We have a value, see when it is\r\n\t\tvar lastKillTime = parseInt(lastKill.Value);\r\n\t\tif(now - lastKillTime < killCoolDown)\r\n\t\t{\r\n\t\t\t// In this particular game, it should not be possible to kill a monster more often than once a minute, so they might be cheating\r\n\t\t\tlog.info(\"Player \"+currentPlayerId+\" killed \"+monsterType+\" again too quickly!\");\r\n\t\t\treturn {};\r\n\t\t}\r\n\t}\r\n\t\r\n\tvar killReward = monsterRewards[monsterType];\r\n\t\r\n\tif(killReward)\r\n\t{\r\n\t\tfor(var currency in killReward)\r\n\t\t{\r\n\t\t\tvar amount = killReward[currency];\r\n\t\t\tserver.AddUserVirtualCurrency({ PlayFabId: currentPlayerId, VirtualCurrency: currency, Amount: amount });\r\n\t\t}\r\n\t}\r\n\t\r\n\t// Reset the kill timer\r\n\tserver.UpdateUserInternalData(\r\n\t{\r\n\t\tPlayFabId: currentPlayerId,\r\n\t\tData: {\r\n\t\t\t\"lastKill\" : String(now)\r\n\t\t}\r\n\t});\r\n\t\r\n\treturn {\r\n\t\trewards: killReward\r\n\t};\r\n}"
      }
    ],
    "IsPublished": true
  }
}

Authentication

SecretKey

Possible Error Codes

Name Code
RevisionNotFound 1125
VersionNotFound 1124