question

Mateus Moura avatar image
Mateus Moura asked

Javascript execute cloud script errorLoggedIn, how to fix?

So, I am trying to make a feedback system for my website, where people login in their playfab account (working fine) and then they can send a feedback using a cloudscript (execute cloud script API) but I am getting a login error everytime...When the player login in the website, the session ticket gets stored so I can use it later, so in this cloud script function I use it, but I guess the session ticket is invalid? Here is the code: (p.s: I am making it in javascript)

var sendfeedbackrequest = new PlayFabClientSDK.ExecuteCloudScript({"X-Authorization": Ticket, "FunctionName": "sendFeedbackWebsiteNoLogin"});
    sendfeedbackrequest.FunctionParameter = {
        "topic": topico,
	"message": mensagem,
	"email": email
    };
PlayFabClientSDK.ExecuteCloudScript(sendfeedbackrequest, SendFeedbackCallback);






The "Ticket" at the header is a variable that gets the stored session ticket value that I mentioned.
CloudScript
2 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.

Ivan Cai avatar image Ivan Cai ♦ commented ·

Can you provide your corresponding cloud script function code?

0 Likes 0 ·
Mateus Moura avatar image Mateus Moura Ivan Cai ♦ commented ·
This is a function to send a message via discord webhook system. The function is called at the end "No login" because I have 2 of this functions and this one doesnt get the currentPlayerId because I wanted to make this a function for people that aren't logged in too. But I tryied both methods, with and without login. I think I am calling the wrong API function or something like that...



handlers.sendFeedbackWebsiteNoLogin = function(args){
    var topic = args.topic;
    var message = args.message;
    var email = args.email;
    var contentBody = {
        "content": null,
        "embeds": [
            {
            "title": topic,
            "description": message,
            "color": 14342874,
            "author": {
                "name": email
            },
            "footer": {
                "text": "sent via website",
                "icon_url": "https://imgur.com/BgMwYqu.png"
            }
            }
        ]
    }
    var url="https://discord.com/api/webhooks/(censored)";
    var method="post";
    var contentType="application/json";
    var headers={};
    var responseString= http.request(url,method,JSON.stringify(contentBody),contentType,headers);
}
0 Likes 0 ·

1 Answer

·
Ivan Cai avatar image
Ivan Cai answered

Hi, I'm confused to find the "X-Authorization" in your ExecuteCloudScriptRequest. The X-Authorization should be in request header instead of request body. You can refer to executecloudscript api to learn more. Generally, the session ticket is automatically set by the SDK and does not require you to set it .

2 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.

Mateus Moura avatar image Mateus Moura commented ·

But do I need a X-Authorization key in the Cloud Script? I used this same function in my app that I am making and the call worked properly with this same function. The changes where only when make the API call. I just can't use the same method I did in the app to call the API, because there is already a built in resource to make API calls, so I just needed to fill in the informations in the header and body.

0 Likes 0 ·
Ivan Cai avatar image Ivan Cai ♦ Mateus Moura commented ·

Calling client API is not supported in cloudscript. In general, X-Authorization (sessionticket) is not required in cloudscript.

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.