question

mikko avatar image
mikko asked

ForbiddenApi error when calling a handler

We are getting this ForbiddenApi error when calling a handler from another handler.

public static dispatchFunctionInstant(server: IPlayFabServerAPI): any {
    // some things left out, parameters etc
    // invoke function
    const executeResult = server.ExecuteCloudScript({
        PlayFabId: player.PlayFabId,
        FunctionName: "_dispatchFunction",
        FunctionParameter: parameters,
        GeneratePlayStreamEvent: Configuration.ShouldGeneratePlayStreamEvents,
        RevisionSelection: "Specific",
        SpecificRevision: script.revision
    });
}

Error in playfab logs.

{
    "Message": "PlayFab API request failure",
    "Level": "Error",
    "Data": {
        "request": {
            "FunctionName": "_dispatchFunction",
            "GeneratePlayStreamEvent": true,
            "PlayFabId": "DDC6A9EB63D83764",
            "RevisionSelection": "Specific",
            "FunctionParameter": {
                "param1": "val1",
                "param2": {
                    "val2": "etc."
                },
            },
            "SpecificRevision": 8
        },
        "error": "ForbiddenApi",
        "api": "/Server/ExecuteCloudScript"
    }
}

"stack": "Error\n at Object.server_request (Script:162:24)\n at Object.server.ExecuteCloudScript (Script:518:75)\n at CounterServerAPIProxy.InvokeRequest (C6805-all:2618:16)\n at CounterServerAPIProxy.ExecuteCloudScript (C6805-all:2264:21)\n at Function.dispatchFunctionInstant (C6805-all:1405:38)\n at LocalPlayer.dispatchFunctionInstant (C6805-all:1359:23)\n at Function.checkRollActions (C6805-all:1605:23)\n at C6805-all:1585:43\n at Array.forEach (<anonymous>)\n at Function.checkRollsActions (C6805-all:1584:17)"

This has seemed to work before. Has something changed in permissions required, how to fix?

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

·
Gosen Gao avatar image
Gosen Gao answered

You should implement your function in a single handler. Calling server.ExecuteCloudScript in a CloudScript handler is not support, not only is this inefficient for the customer, it also ties up multiple JavaScript engines, affecting our cost and other customers' experience. If the CloudScript cannot meet your requirement, we recommend that you can use Azure Function which is more powerful and flexible.

3 comments
10 |1200

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

mikko avatar image mikko commented ·

Thanks for the recommendation. Did something change when it comes to calling server.ExecuteCloudScript in a CloudScript handler? I think it was possible before.

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao mikko commented ·

Yes, a change was recently applied, calling server.ExecuteCloudScript in a CloudScript handler is not allowed now.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ mikko commented ·
@mikko

Feel free to provide more information about your scenario because usually it is unnecessary to execute Cloud Script inside a Cloud Script function.

0 Likes 0 ·

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.