I've just started converting some existing cloudscript to azure functions. As a test I'm starting with a simple function that we currently use to add a daily bonus key right now during development( instead of waiting for 24 hrs), works great currently:
handlers.AddDailyBonus = function(args, context) { server.AddUserVirtualCurrency({ "Amount": 1, "PlayFabId" : currentPlayerId, "VirtualCurrency": "DB"}); }
I started with the basic helloworld tutorial and uploaded it to my azure instance, and that operates correctly, so I know the basics of connecting to the azure functions is working. Following various tutorials and sample code I've arrived at the following to duplicate the above cloudscript:
[FunctionName("AddDailyBonus")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync()); dynamic args = context.FunctionArgument; /* var message = $"Hello {context.CallerEntityProfile.Lineage.MasterPlayerAccountId}!"; log.LogInformation(message); dynamic inputValue = null; if (args != null && args["inputValue"] != null) { inputValue = args["inputValue"]; } log.LogDebug($"HelloWorld: {new { input = inputValue} }"); */ var apiSettings = new PlayFab.PlayFabApiSettings () { TitleId = context.TitleAuthenticationContext.Id }; PlayFab.PlayFabAuthenticationContext titlecontext = new PlayFab.PlayFabAuthenticationContext (); titlecontext.EntityToken = context.TitleAuthenticationContext.EntityToken; var request = new PlayFab.ServerModels.AddUserVirtualCurrencyRequest(); request.Amount = 1; request.PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId; request.VirtualCurrency = "DB"; var serverApi = new PlayFab.PlayFabServerInstanceAPI(apiSettings, titlecontext); var result = await serverApi.AddUserVirtualCurrencyAsync(request); return result; //new { messageValue = message }; } }
you can see where I've commented out the original helloworld function body. I've also switched from anonymous to function, and removed the "get" path.
When I attempt to call this from cloudscript, I get a 400 with 1473 error code, and I've tried a variety of options. As far as I can tell my other azure settings are correct, i.e. the title ID and dev key are in the host json and I can see them in my azure portal.
Any help would be greatly appreciated, feels like I'm missing something basic. Also, the various examples and the sample at https://github.com/PlayFab/PlayFab-Samples/blob/master/Samples/CSharp/AzureFunctions/ExampleFunctions/Handlers.cs vary enough that I'm not sure which is correct. I could not get the handlers.cs version to work correctly, probably something basic in my project settings.