question

Brent Batas (Lisk) avatar image
Brent Batas (Lisk) asked

PlayFabServerAPI Cloudscript without playFabId

I'm trying to use the PlayFabServerAPI to run a Cloudscript, but it is returning an error that
"The PlayFabId field is required"

My Cloudscript is not specific to a particular user/player, so I want to omit the PlayFabId field.

Am I missing some other Cloudscript API call? Alternatively, would there be concerns on running this cloudscript on dummy player account?

Edit: I'm using the C# SDK, latest version.

sdks
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

·
Sarah Zhang avatar image
Sarah Zhang answered

The request of Server API ExecuteCloudScript requires the PlayFabId field, it’s by design, you can check the API reference - Server-Side Cloud Script - Execute Cloud Script - REST API (PlayFab Server) | Microsoft Docs for more information.

For clarification, you can execute a CloudScript function as a Scheduled Task. If you use Scheduled Tasks to execute the CloudScript function, you can provide no PlayFabId. Please note you can only execute the Scheduled Task in the specific time or execute it manually in your title’s Game Manager. You can check this documentation - Scheduled tasks quickstart - PlayFab | Microsoft Docs for more information.

[Edited] If the type of the Scheduled Task is "Run actions on each player in a segment", and you set the action to “Execute Cloud Script”. When running the Scheduled Task, each CloudScript function execution will automatically set the Cloud Script’s global variable currentPlayerId to the PlayFabId in the current segment automatically.

If the type of the Scheduled Task is “Run Cloud Script function once”. When running the Scheduled Task, the global variable – currentPlayerId won’t be updated.

So, like what the Scheduled Tasks do, passing a PlayFabId to the Server API ExecuteCloudScript to trigger a function won’t cause the issue. You can pass the player account you registered to the Server API ExecuteCloudScript as the workaround.

3 comments
10 |1200

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

Brent Batas (Lisk) avatar image Brent Batas (Lisk) commented ·

Can you clarify what this means?

And essentially, the Scheduled Task will choose a PlayFabId automatically and pass it to the CloudScript.

what do you mean by "automatically" in this case?

For now, my workaround is just to pass in the PlayFabId of a test account, and it seems to be working fine.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Brent Batas (Lisk) commented ·

Yes, your workaround is feasible. And after researching, we can give a supplement to the original answer. If you don’t want to pass any player information to CloudScript, you can also use the Entity API ExecuteEntityCloudScript to execute the CloudScript functions. This API requires the field – Entity, not requires the PlayFabId. The Entity you passed to ExecuteEntityCloudScript can be title_player_account entity or title entity either.

If you post the API request with the title entity, no player information will be passed to the CloudScript, and this API will verify your title-level entity token.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Brent Batas (Lisk) commented ·

>> what do you mean by "automatically" in this case?

Apologies for the confusion, we will edit this answer to correct the description about “Essentially, the Scheduled Task will choose a PlayFabId automatically and pass it to the CloudScript.”

In fact, if the type of the Scheduled Task is "Run actions on each player in a segment", and you set the action to “Execute Cloud Script”. When running the Scheduled Task, each CloudScript function execution will automatically set the Cloud Script’s global variable currentPlayerId to the PlayFabId in the current segment automatically. So, you can use the above method to execute actions to the players in a segment in batches.

If the type of the Scheduled Task is “Run Cloud Script function once”. When running the Scheduled Task, the global variable – currentPlayerId won’t be updated.

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.