I am trying to use the Azure PlayFab cloud script tool to make a web request to the PlayFab client API in order to add credentials to an account. From my research, it looks like the way to send a web request inside of the PlayFab cloud script is using http.request()
, however whenever I use it, the catch portion of my try-catch block runs meaning that the method threw an exception.
Here is that code:
javascript
// Call AddUsernamePassword from CloudScript using the client API
// Define the request object for AddUsernamePassword
// Make a POST request to the client API endpoint
var url = "https://4f38a.playfabapi.com/Client/AddUsernamePassword"; // Define the API endpoint URL
// Define the request headers
var headers = {
"Content-Type": "application/json",
"X-Authorization": sessionTicket //This is what we pulled from args in previously
};
//Define data
var data = {
"Username": username,
"Email": contactEmail,
"Password": password
};
//Log stuff
const json_headers = JSON.stringify(headers);
const json_data = JSON.stringify(data);
log.debug(`Headers: ${json_headers}`);
log.debug(`Data: ${json_data}`);
//Attempt the web request
try
{
// Make the request
http.request(url, "POST", json_data, json_headers, null, function(error, response) {
log.debug("Web request made!");
});
}
catch (e)
{
return { success: false, message: "Unable to make web request", data: e.message };
}
When setting the parameters for this request, I verified they contained the proper information by using log.debug()
statements. Below are my request headers and data which were logged by the cloud script function and match the data scheme match the documentation:
Headers: {"Content-Type":"application/json","X-Authorization":"SESSION TICKET REDACTED"}
Data: {"Username":"testing12","Email":"contact@bluescreenstudios.net","Password":"abcdefg"}
Because the web request kept failing, I originally assumed that I was entering the parameters wrong, but when I copied the messages from the log.debug()
statements back on my client and put them into insomnia, the web request returned 200 OK and was successful.
Can somebody please let me know what I am doing wrong?
Helpful Links: