question

moises avatar image
moises asked

ProfileDoesNotExist in Azure cloud function when adding Economy v2 item to Player inventory

Hello,

I'm trying to add an Economy v2 item to a player inventory when the player is created. For testing purposes I set up a PlayerStream rule to execute the function when a com.playfab.player_logged_in event occur and I'm getting a ProfileDoesNotExist error message. The player profile definitely exists, so I guess the message is not really about the player profile.

This is the code for the function: public static class setupPlayer { [FunctionName("setupPlayer")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { PlayerPlayStreamFunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<PlayerPlayStreamFunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());

             PlayFabSettings.staticSettings.TitleId = "my-title-id";
             PlayFabSettings.staticSettings.DeveloperSecretKey = "my-secret-key";
    
             var titleEntityResponse = await PlayFabAuthenticationAPI.GetEntityTokenAsync(new GetEntityTokenRequest());
             if (titleEntityResponse.Result != null)
             {
                 var addItemResponse = await PlayFabEconomyAPI.AddInventoryItemsAsync(new AddInventoryItemsRequest() {
                     Entity = new PlayFab.EconomyModels.EntityKey() {
                         Type = "title_player_account",
                         Id = context.PlayerProfile.PlayerId
                     },
                     Amount = 100,
                     Item = new InventoryItemReference() {
                         Id = "my-economy-v2-item-id"
                     }
                 });
    
                 if(addItemResponse.Result != null) {
                     log.LogInformation("addPawsResponse Result is not null");
                 } else {
                     log.LogInformation("addPawsResponse Result is null");
                     log.LogInformation(addItemResponse.Error.ErrorMessage);
                 }
             }
                
             var message = $"Hello {context.PlayerProfile.PlayerId}!";
             log.LogInformation(message);
             return new { messageValue = message };
         }
     }

I'm currently stuck, any help is welcome! Thank you.

CloudScriptIn-Game Economy
1 comment
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 ·

I'm doing some tests, which could take a while, your patience is appreciated.

1 Like 1 ·

1 Answer

·
Simon Cui avatar image
Simon Cui answered

According to your code, if you look at the line 9 and 10,

 Type = "title_player_account",
 Id = context.PlayerProfile.PlayerId

The Id you got from "context.PlayerProfile.PlayerId" belongs to the type of “master_player_account”, not "title_player_account". You may use other methods to get a correct Id whose type is "title_player_account". For example, you can use GetUserAccountInfo of server API by applying “context.PlayerProfile.PlayerId” as the request body to get “result.UserInfo.TitleInfo.TitlePlayerAccount”.

1 comment
10 |1200

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

moises avatar image moises commented ·

That was it! Doing what you suggested worked perfectly.

Thanks a lot!!

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.