I am using your guide to writing Playfab cloudscript with Azure.
As specified in your guide, I have first followed Microsoft's guide to creating my first Azure function. This works as expected and I can call via a browser.
I have added the function url in the Playfab dashboard, and have used the example code (modified) to execute it in my Unity project.
I get an error back:
CloudScriptAzureFunctionsHTTPRequestError
Invocation of cloud script function HttpExample failed
Code 400
I have checked everything. I'm using the entity id and type returned from the login call. The function name is correct, as is the parameter name.
Microsoft's function looks like this:
public static class HttpExample { [FunctionName("HttpExample")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; return name != null ? (ActionResult)new OkObjectResult($"Hello, {name}") : new BadRequestObjectResult("Please pass a name on the query string or in the request body"); } }
This is how I'm calling it:
IEnumerator ExecuteFunction() { print("entityId: " + entityId); print("entityType: " + entityType); var request = new ExecuteFunctionRequest() { Entity = new PlayFab.CloudScriptModels.EntityKey() { Id = entityId, //Get this from when you logged in, Type = entityType //Get this from when you logged in }, FunctionName = "HttpExample", //This should be the name of your Azure Function that you created. FunctionParameter = new Dictionary<string, object>() { {"name","Mads"} }, GeneratePlayStreamEvent = true }; bool? success = null; ExecuteFunctionResult result = null; PlayFabError playFabError = null; PlayFabCloudScriptAPI.ExecuteFunction(request,(r) => { result = r; success = true; print("ExecutionTimeMilliseconds: " + r.ExecutionTimeMilliseconds); print("FunctionName: " + r.FunctionName); print("FunctionResultTooLarge: " + r.FunctionResultTooLarge); }, (e) => { playFabError = e; success = false; Error(e); }); while (!success.HasValue) yield return null; print("success: " + success); }