My PlayFab reset email API POST request seems not to have a payload

150 Views Asked by At

I am trying to submit a php response to the following PlayFab API: https://learn.microsoft.com/en-us/rest/api/playfab/admin/account-management/reset-password?view=playfab-rest

This is my first ever php script and I have been working with this for quite some time and being able to run my script without errors but it seems like I have no payload.

The echo in the code:

echo ' The resp: ' .$resp;

...response from the above echo is:

The resp: string(0) ""

Unfortunately I really do not know what is wrong and how to fix it as there is not error messages. I have tried to echo $options array to control if there is a payload but not succeeded. I realise I need help and would really appreciate that.

$url = "https://titleId.playfabapi.com/Admin/ResetPassword/json/";

        $data = array('Password' => $pw1, 'Token' => $params['token']);

        $options = array(
            'http' => array(
                'method'  => 'POST',                    
                'content' => http_build_query($data),
                'header' => 'X-SecretKey: xxxxxxxxxxxx\r\n',
                'ignore_errors' => true
            )
        );

        $context  = stream_context_create($options);
        $resp = file_get_contents($url, false, $context);
        echo ' The resp: ' .$resp;
        var_dump($resp);
1

There are 1 best solutions below

0
PeterK On

Ok here is the solution. I was able to get this to work in Postman and when I test the code it works.

Here is the snippet that work:

echo '>>>>>>>>>> TEST <<<<<<<<<<';

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://99999.playfabapi.com/Admin/ResetPassword?Password=pekapeka&Token=1B5A9C01EFD5DB69',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_HTTPHEADER => array(
            'X-SecretKey: xxxxxxx',
            'Content-Type: application/json\\'
        ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
    echo $response;
    print_r($response);

    echo '<br>========== END ==========';