question

Rich avatar image
Rich asked

Example calling an Azure Function from a Javascript (Typescript) client?

Hi there,

Can someone share an example of calling a Azure Function that has been added to PlayFab (preview) and then calling this function from a Javascript (Typescript) client.

The script can be executed from within the dashboard succesfully. But I don't really know how to get it to work from a javascript client. It should be something down these lines:

PlayFab.CloudScriptApi.ExecuteFunction({

"FunctionName" : "HelloWorld",

},

function(result){ console.log("Function called: " + result.status); });

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

I assume that you don’t know how to craft a http request for ExecuteFunction, here is an example from the Postman SDK. Postman is a restful testing tools and PlayFab SDK normally provides an sample request for each API. Thus, the API documentation is still the best place to learn.

var request = {
  "FunctionName": "LevelCompleted",
  "FunctionParameter": {
    "level": 3,
    "points": 400
  },
  "GeneratePlayStreamEvent": true,
  "Entity": {
    "Id": "aaa",
    "Type": "master_player_account",
    "TypeString": "master_player_account"
  }
};

var result = PlayFab.CloudScriptApi.ExecuteFunction(request);
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.