question

jpgordon00 avatar image
jpgordon00 asked

Cloudscript Function "Failed to Enumerate RequestId"

I have gotten a HelloWorld function running and several API calls work as expected. However, when I call the following code from the client via PlayFab invoke Cloudscript, I get the following error:

{
    "ExecutionTimeMilliseconds": 351,
    "FunctionName": "HelloWorld",
    "FunctionResult": {
        "result": null,
        "customData": null,
        "error": {
            "httpCode": 400,
            "httpStatus": "BadRequest",
            "error": 1001,
            "errorMessage": "master_player_account 3159395147665980277 not found in namespace 1AF050D54886430B",
            "errorDetails": null,
            "requestId": "Failed to Enumerate RequestId. Exception message: Enumeration has not started. Call MoveNext."
        }
    },
    "FunctionResultTooLarge": null,
    "Error": null,
    "Status": 200
}

Bellow is my Azure Function. Please note I made other API calls and environment variables are setup properly.

[FunctionName("HelloWorld")]
        public static async Task<dynamic> HelloWorld(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, ILogger log)
        {
            /* Create the function execution's context through the request */
            var context = await FunctionContext<dynamic>.Create(req);
            var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext);
            log.LogInformation("Updated user data for " + context.CurrentPlayerId);
            return await serverApi.UpdateUserDataAsync(new UpdateUserDataRequest
                {
                    PlayFabId = context.CurrentPlayerId,
                    Data = new Dictionary<string, string>() { { "PLS", "haha"} }
            });
  }

Why is this error happening? I am following the same code from the docs. Fuctions V3.

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

jpgordon00 avatar image jpgordon00 commented ·
An example log: 2021-01-20T07:05:29.679 [Information] Updated user data for 2BD86D25C9B93B75
0 Likes 0 ·
Citrus Yan avatar image Citrus Yan jpgordon00 commented ·

May I know your title id?

0 Likes 0 ·
jpgordon00 avatar image jpgordon00 Citrus Yan commented ·

Keep in mind I can make valid API calls to get title data, etc.

0 Likes 0 ·
Show more comments
jpgordon00 avatar image jpgordon00 commented ·

I get the same error no matter how I create the player or execute the CloudScript.

In the PlayFab portal I create a new player and then run the same script as posted above, and get the same namespace error:

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan jpgordon00 commented ·

I created a test account in your title and can reproduce the same issue. To further investigate this, could you please use Postman to manually make a call to the Server/UpdateUserData and see the result?

Quickstart PlayFab REST API collection for Postman - PlayFab | Microsoft Docs

0 Likes 0 ·
jpgordon00 avatar image jpgordon00 Citrus Yan commented ·

A manual invocation of Server/UpdateUserData works on any player.

0 Likes 0 ·
Show more comments

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

I found the root cause for your case: context.CurrentPlayerId in your code refers to the player's title player account id whereas UpdateUserData requires the player's master player account id:

CurrentPlayerId = contextInternal.CallerEntityProfile.Lineage.TitlePlayerAccountId

https://github.com/PlayFab/CSharpSDK/blob/d61ba9f23bf459e6b766bc3fd6b0945ede9ef553/Plugins/CloudScript/source/PlayFabFunctionContexts.cs#L64

Therefore, to make UpdateUserData work, please use the master player id instead:

PlayFabId= context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
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.

Citrus Yan avatar image Citrus Yan commented ·

In addition, the context FunctionContext used in our sample is still in beta mode and is subject to change at any time, please see the following code:

https://github.com/PlayFab/CSharpSDK/blob/d61ba9f23bf459e6b766bc3fd6b0945ede9ef553/Plugins/CloudScript/source/PlayFabFunctionContexts.cs#L2

Instead, we provide several context models for developers to use when dealing with CloudScript using Azure Functions, please check out this tutorial:

https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/cloudscript-af-context

1 Like 1 ·
jpgordon00 avatar image jpgordon00 Citrus Yan commented ·

Thank you so much for your help. The documentation never specifies if the PlayFabId should be the Master or Title account.

For calls like UpdatePlayerStatistics and such, do those take the Master account id as well?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan jpgordon00 commented ·

Yes, "PlayFabId" refers to the Master account id, if you ever see any API that requires the "PlayFabId", master account id is the one to put in.

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.