Joseph Distler avatar image
Joseph Distler asked

Calling Playfab Admin API from Server


I have set-up a Scheduled Task to run once weekly using the Revisions(legacy) section on the playfab dashboard. The problem is, I need to call CreatePlayerStatisticDefinition and IncrementPlayerStatisticVersion at the same time that my Scheduled Task runs. These functions are part of the Playfab Admin API which is reportedly (past report) impossible to call from the server. However, reportedly "You can make URL calls, these URL calls can be the Playfab title Admin endpoints." So this is now what I am trying to achieve. My problem is that I have no idea how to do this... I have been digging through a lot of the documentation (specifically webhook-calls-from-cloudscript and Rest-API) But I'm afraid I am in a bit over my head and I am not able to fully understand how to make a call to the IncrementPlayerStatisticVersion endpoint from my code on the Revisions(legacy) playfab server. I think my code needs to look something like this:

var url = "https://[titleID]";
var method = "post";
var contentBody = "";
var contentType = "application/json";
var headers = {};
var responseString =  http.request(url,method,contentBody,contentType,headers);

Where obviously I need to replace [titleID] with my title ID and to include somewhere an X-SecretKey and a Statistic name argument, though I have no clue how these arguments should be formatted or what they should look like. Normally I can look at a similar example and derive what my method should look like from there, but I have not been able to find such useful information in this case. I don't even know what the code to http.request looks like so I feel I am just grasping at straws in this case. Any help or advice you can give regarding calling these Playfab Admin API functions from the server and/or structuring the clousdcript requests would be greatly appreciated!

I have a feeling a suggestion might be to use Azure functions but I have never touched Azure and would prefer not open a new can of worms when I am already so close to the functionality I am trying to achieve here. I don't have any way of running a scheduled task with my own tools or have much expertise in these types of cloud computing so any bit of help would go a long way.

apisCloudScriptscheduled tasks
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

Xiao Zha avatar image
Xiao Zha answered

If you insist on calling PlayFab Admin API from CloudScript (Legacy), the following is a code example:

 var headers = {
        "X-SecretKey": "XXX"
    var body = {
    var url = "";
    var content = JSON.stringify(body);
    var httpMethod = "post";
    var contentType = "application/json";
    var response = http.request(url, httpMethod, content, contentType, headers);     
    return { responseContent: response };
10 |1200

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

Joseph Distler avatar image Joseph Distler commented ·

Thank you so much, I am curious what kind of security risk is it to keep the X-SecretKey in plain text on the server... Can anyone see this code? Is there another way to store this key or access it in a safe way, perhaps as a TitleInternalData or something?

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha Joseph Distler commented ·

If you set the Secret Key in CloudScript and do not return this key to players, there is no risk of exposing the secret key.

1 Like 1 ·
Joseph Distler avatar image Joseph Distler Xiao Zha commented ·

Thank you so much for all your help!

0 Likes 0 ·

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.