question

Kim Strasser avatar image
Kim Strasser asked

How can I use server API in Azure Functions?

I want to use server API UpdateUserReadOnlyData in my Azure function but I don't know how to do that. This code is not working:

var request = new PlayFab.ServerModels.UpdateUserReadOnlyDataRequest();

I get an error message:

The type or namespace name 'UpdateUserReadOnlyDataRequest' does not exist in the namespace 'PlayFab.ServerModels' (are you missing an assembly reference?) [Newfunctions]

In addition, I don't know how to create PlayFabServerInstanceAPI:

var serverAPI = new PlayFabServerInstanceAPI();

My Azure function:

 [FunctionName("UpdateUserReadOnlyData")]
        public static async Task<dynamic> MakeApiCall(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, ILogger log)
        {
            var context = await FunctionContext<dynamic>.Create(req);
            var args = context.FunctionArgument;

            var serverAPI = new PlayFabServerInstanceAPI();

            var request = new PlayFab.ServerModels.UpdateUserReadOnlyDataRequest();

            var result = await serverAPI.UpdateUserReadOnlyDataAsync(request);
            if (result.Error != null)
            {
              ...
            }
            else
            {
              ...
            }
            return ...
        }

How can I use server API UpdateUserReadOnlyData in Azure Functions?

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Hernando avatar image
Hernando answered

Actally, CsharpSDK does not provide a special data structure implementation for UpdateUserReadOnlyData, you can use UpdateUserDataRequest as an alternative.

For to generate PlayFabServerInstanceAPI from PlayerPlayStreamFunctionExecutionContext, you can try the following code in C# SDK:

 var apiSettings = new PlayFabApiSettings   {  
	TitleId =
	Environment.GetEnvironmentVariable("PlayFab.TitleId",
	EnvironmentVariableTarget.Process), 
	DeveloperSecretKey =
	Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY",EnvironmentVariableTarget.Process),  

};   

var serverApi = new PlayFabServerInstanceAPI(apiSettings);

As you've set title Id and dev key in Azure portal, you should be able to get dev key with "GetEnvironmentVariable" method, but you may need to change the key to match your setting.

Besides, this thread may be helpful for you: https://community.playfab.com/questions/45136/is-it-possible-to-use-addorupdatecontactemail-in-a.html

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.