I always get this error message in the client code: "Invocation of cloud script function NewFunction failed".
I get no event in PlayStream when the error happens. What does this error message mean and what is wrong with my code?
How can I find out if my Azure function works correctly? I don't know if there is a problem with my Azure function or with the client code that calls the Azure function.
Client code:
var result = await PlayFabCloudScriptAPI.ExecuteFunctionAsync(new ExecuteFunctionRequest() { Entity = new PlayFab.CloudScriptModels.EntityKey() { Id = entityid, Type = entitytype, }, FunctionName = "NewFunction", FunctionParameter = new { NewDisplayname = "Sydney" }, GeneratePlayStreamEvent = true }); if (result.Error != null) { } else { if (result.Result.FunctionResultTooLarge ?? false) { Console.WriteLine("This can happen if you exceed the limit that can be returned from an Azure Function, See PlayFab Limits Page for details."); } Console.WriteLine("The " + result.Result.FunctionName + "function took " + result.Result.ExecutionTimeMilliseconds.ToString() + " to complete."); Console.WriteLine(result.Result.FunctionResult.ToString()); }
Azure Function:
namespace My.Functions { public static class NewFunction { [FunctionName("NewFunction")] public static async Task<dynamic> MakeApiCall( [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 args = context.FunctionArgument; var desireddisplayname = args["NewDisplayname"]; /* Create the request object through the SDK models */ var request = new UpdateUserTitleDisplayNameRequest(); request.PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId; request.DisplayName = desireddisplayname; /* Use the ApiSettings and AuthenticationContext provided to the function as context for making API calls. */ var adminApi = new PlayFabAdminInstanceAPI(context.ApiSettings, context.AuthenticationContext); /* The PlayFabServerAPI SDK methods provide means of making HTTP request to the PlayFab Main Server without any * extra code needed to issue the HTTP requests. */ return await adminApi.UpdateUserTitleDisplayNameAsync(request); } } }
I have chosen "Authorization level: Anonymous" when I created my Azure project in Visual Studio Code. And I have added "PLAYFAB_DEV_SECRET_KEY": "...", and "PLAYFAB_TITLE_ID": "..." to my local.settings.json file.
In addition, I selected the Register Function button in my PlayFab account and I have created the following cloud script function:
Trigger type: HTTP Function name: NewFunction Function URL: https://myplayfabfunctionapp.azurewebsites.net/api/NewFunction