Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Kim Strasser · Sep 16, 2020 at 06:55 PM · CloudScript

Azure Functions: "Invocation of cloud script function NewFunction failed"

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
bildschirmfoto-2020-09-16-um-202955.png (75.1 kB)
Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by SethDu · Sep 17, 2020 at 06:27 AM

By default, the local.setting.json won't be uploaded. You will need to click "Upload Settings" after the codes have been uploaded successfully, please refer to: https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs-code?tabs=csharp#publish-application-settings

Otherwise, you may manually configure the settings on Azure Portal on [Configuration] => [Application Settings] => [New Application settings]. Input “PLAYFAB_DEV_SECRET_KEY” as the key and your secret key as value. Of course, you may modify the source code to any key you want. It will work as long as the code matches the Azure Portal configuration.

PS. To troubleshot Azure Function, you may start streaming log, and after that, call PlayFab API to see the log output in the console.


snipaste-2020-09-17-14-21-14.png (149.8 kB)
Comment

People who like this

0 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kim Strasser · Sep 17, 2020 at 09:02 AM 0
Share

"Start Streaming Logs" is not displayed in my Visual Studio Code menu. Why is it not displayed when I click on my function?

bildschirmfoto-2020-09-17-um-105213.png (179.4 kB)
avatar image SethDu ♦ Kim Strasser · Sep 17, 2020 at 09:10 AM 0
Share

It will need to publish to the online azure portal:

untitled-picture.png (94.0 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    Disable GitHub Integration 2 Answers

    Saving data in Unity on Pause/Quit/Lose Focus 1 Answer

    ailed to import package with error: Couldn't decompress package 1 Answer

    Was the "CloudScript execution API requests issued" limit raised to 15? 1 Answer

    CloudScript execution? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges