In general, I'm having a tough time debugging the HttpRequest of an Azure Function when it's being called by a rule. I've been considering calling an external API and giving them the json just so I can read it! Let me show you what I've been struggling with:
My code so far:
using System.Threading.Tasks; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using PlayFab; using PlayFab.Samples; using Newtonsoft.Json; using Microsoft.AspNetCore.Mvc; namespace OnPurchasedCommander.Function { public static class OnCommanderWasPurchased { [FunctionName("OnCommanderWasPurchased")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { string json = await req.ReadAsStringAsync(); FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(json); var settings = new PlayFabApiSettings { TitleId = context.TitleAuthenticationContext.Id, DeveloperSecretKey = "-----" //this is hardcoded }; PlayFabAuthenticationContext authContext = new PlayFabAuthenticationContext() { EntityToken = context.TitleAuthenticationContext.EntityToken }; PlayFabServerInstanceAPI sapi = new PlayFabServerInstanceAPI(settings, authContext); PlayFab.PlayFabResult<PlayFab.ServerModels.GrantCharacterToUserResult> result = await sapi.GrantCharacterToUserAsync(new PlayFab.ServerModels.GrantCharacterToUserRequest() { CharacterName = "test", //I wanted to use the purchased ItemId here CharacterType = "Commander", PlayFabId = "----" //This is hardcoded }); log.LogInformation("Testing log.LogInformation"); if (result.Error != null) { return new BadRequestObjectResult("Oops"); } else { return new OkObjectResult("All good!"); } } } }
For this code, I need to know how to get the PlayerId and the ItemId of the item that was added to the player's inventory when that rule was called.
Being able to debug the context would help me a lot! I can't use PostMan for that because the HttpRequest is built by PlayFab when the rule is triggered.I also tried returning data and using the log, to no avail.
I really just want to see what's on that json string.
Any tips?