For some reason our backend team write azure function in JavaScript. Can anyone give us an example of Azure Function that write in JS and call some simple server api.
For some reason our backend team write azure function in JavaScript. Can anyone give us an example of Azure Function that write in JS and call some simple server api.
You could do the following steps to implement the JavaScript Azure Function and calling a server API.
var PlayFab = require("playfab-sdk/Scripts/PlayFab/PlayFab"); var PlayFabServer = require("playfab-sdk/Scripts/PlayFab/PlayFabServer"); const yourDeveloperSecretKey = "your developer secret key here"; module.exports = function (context, req){ PlayFab.settings.titleId = req.body.TitleAuthenticationContext.Id; PlayFab.settings.developerSecretKey = yourDeveloperSecretKey; var getdataRequest = { PlayFabId: req.body.CallerEntityProfile.Lineage.MasterPlayerAccountId, Keys: req.body.FunctionArgument.keys, } context.log("calling the get user api"); PlayFabServer.GetUserData( getdataRequest, (error, result)=>{ if (result !== null) { context.log("API call was successful."); context.res = { status: 200, body: result }; context.done(); } else if (error !== null) { context.log("Something went wrong with the API call."); context.log("Here's some debug information:"); context.log(CompileErrorReport(error)); context.res = { status: 500, }; context.done(); } } ) } function CompileErrorReport(error) { if (error == null) return ""; var fullErrors = error.errorMessage; for (var paramName in error.errorDetails) for (var msgIdx in error.errorDetails[paramName]) fullErrors += "\n" + paramName + ": " + error.errorDetails[paramName][msgIdx]; return fullErrors; }
{ "FunctionName": "YourAzureFunctionName", "FunctionParameter": { "Keys": [ "preferences", "progress" ] } }
{ "code": 200, "status": "OK", "data": { "ExecutionTimeMilliseconds": 2409, "FunctionName": "YourAzureFunctionName", "FunctionResult": { "code": 200, "status": "OK", "data": { "PlayFabId": "1FCAC4066224C1FB", "DataVersion": 1, "Data": { "preferences": { "Value": "fish&chips", "LastUpdated": "2021-07-20T08:28:54.223Z", "Permission": "Private" }, "progress": { "Value": "50%", "LastUpdated": "2021-07-20T08:28:54.223Z", "Permission": "Private" } } } } } }
2 People are following this question.