Kvaba Interactive avatar image
Kvaba Interactive asked

Call a CloudScript (legacy) function on all players with parameters

I need to get some data for each player. The data is currently stored in player.readOnlyData. I'll then combine the data, build a CSV and use it for a report.

I am using CloudScript (Legacy).

How I imagine it should happen: 1. I call PlayFab API and trigger a scheduled action 2. In the call I send new arguments to be passed when calling the CloudScript function on each player 3. Each player handles the function and broadcasts their data either as a PlayStream event or makes a post call to an external webhook 4. The payload contains a common InstanceId parameter I've passed in step 2, so I can bundle the results, and results from the queried data. It will be like this

    transactionid: 123, 
    player: "ASD123",  
    type: "boarKills",
    value: 3

The problem is - I can't seem to find a way to programmatically call a cloudscript function on every player WITH CUSTOM parameters. If I create a Scheduled task, I can either schedule it, or trigger it via API but I don't seem to have access to the function's args. Can I make an API call and say "Hey, Playfab, run function X on every player with arguments: {x=1, y=0}" ?

I don't care about the transactionID being my value. If there's some FunctionTriggerInstanceID available - it could work. All I need is a common id for all player's results, so I can differentiate them from running the same function X hours later.

EDIT: I saw the UpdateTask method in the API, but I can't find a way to use it to update the Scheduled Tasks's actions > arguments

scheduled 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.

Simon Cui avatar image Simon Cui commented ·

Hi, i'm not sure if this example can help:5488-game-manager-tasks-new-scheduled-task.png 5489-js.png You may try to manually set the Argument via [Game Manager] -> [Your Title] -> [Automation] -> [Scheduled Tasks] -> [New Scheduled Task]. For more information, please refer to Scheduled tasks quickstart and Writing custom CloudScript.

0 Likes 0 ·
Kvaba Interactive avatar image Kvaba Interactive Simon Cui commented ·

Yes, but that's a manual action via the PlayFab admin panel. I want to automate this so I can call the same function with different arguments via API.

There is an API method Update Task, which allows me to change basic things about saved tasks, like the one on the screenshot, but I don't believe Arguments are exposed there. I can change the function's name, but can't change the arguments.

0 Likes 0 ·

1 Answer

Simon Cui avatar image
Simon Cui answered

You can use API UpdateTask and set Parameter containing Argument and FunctionName. The type of Parameter is "object", which means it can be any scheduled task type. You can check each task type's create API documentation for details. I did a test in postman as the screenshot shown below: 5626-image.png

The scheduled task in Game Manager portal is: 5627-image.png

image.png (66.8 KiB)
image.png (43.4 KiB)
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.