question

subbakerlo avatar image
subbakerlo asked

Write Custom Event from within a Rule Action

Hi,

I don't really understand why this error occurs:

"Level": "Error",
                    "Message": "PlayFab API request error",
                    "Data": {
                        "api": "/Server/WritePlayerEvent",
                        "request": {
                            "PlayFabId": "691A5BXXXXXXXXX",
                            "EventName": "Add_Missing_Char_Data",
                            "body": [
                                {
                                    "CharacterId": "482XXXXXXXXXXX",
                                    "CharacterName": "Test",
                                    "CharacterType": "Server"
                                },
                                {
                                    "CharacterId": "90C4XXXXXXXXXX",
                                    "CharacterName": "SubbaKerl",
                                    "CharacterType": "Server"
                                }
                            ]
                        },
                        "result": null,
                        "apiError": {
                            "code": 400,
                            "status": "BadRequest",
                            "retryAfterSeconds": null,
                            "error": "InvalidParams",
                            "errorCode": 1000,
                            "errorMessage": "Invalid input parameters",
                            "errorHash": null,
                            "errorDetails": {
                                "EventName": [
                                    "The EventName field is required."
                                ],
                                "PlayFabId": [
                                    "The PlayFabId field is required."
                                ]
                            }

			}
                    }
                }
            ],
            "ExecutionTimeSeconds": 0.0554118,
            "ProcessorTimeSeconds": 0.00329,
            "MemoryConsumedBytes": 42792,
            "APIRequestsIssued": 3,
            "HttpRequestsIssued": 0,
            "Error": {
                "Error": "CloudScriptAPIRequestError",
                "Message": "The script called a PlayFab API, which returned an error. See the Error logs for details.",
                "StackTrace": "Error\n    at Object.server_request (Script:181:24)\n    at Object.server.WritePlayerEvent (Script:636:73)\n    at handlers.XXXXX (50758-.CloudScript.js:316:20)\n    at Object.invokeFunction (Script:117:33)"

What I am trying to achieve is to write a custom player event from within a cloudscript. As you can see above, the request provides an "EventName" as well as a "PlayFabId". Still it gives an error that "The EventName field is required." and "The PlayFabId field is required.".

Could it be possible that this has something to do with the fact that I am trying to write a custom player event withtin an action that was already called due to another custom event?

If so, why? And why does it give me this strange error?

My code to call the event looks as follows:

server.WritePlayerEvent({ PlayFabId: context.playerProfile.PlayerId, EventName: "Add_Missing_Char_Data", body: chars });

P.S.: I anonymized the Char and PlayFab IDs in the script above. The PlayFabId as well as the Event Name is correct and exist.

Thanks in advance.

Best

PlayStream
1 comment
10 |1200

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

subbakerlo avatar image subbakerlo commented ·

Added some missing code in the question

0 Likes 0 ·

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

This issue is caused by the Body (Line 8) you pass is not correct, it should be an Object not a List. Please refer to the official API document -- Analytics - Write Player Event - REST API (PlayFab Client) | Microsoft Docs.

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.