API PHP Login doesnt work — CyberPanel - WebHosting Control Panel for OpenLiteSpeed
CyberHosting

API PHP Login doesnt work

I was testing https://cyberpanel.docs.apiary.io/#reference/server/login-as-user/login-as-user.

Set up my hostnames URL and username and password however I get below error message

string(62) "{"userID": 0, "loginStatus": 0, "error_message": "'username'"}"






my PHP code


<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://xxxxxxx:8090/api/loginAPI");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"username\": \"myusername\",
\"password\": \"mypassword\"
}");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));

$response = curl_exec($ch);
curl_close($ch);

var_dump($response);

?>

Any idea how to fix this ? is it from my side or is it a bug?

Thank you,

Comments

  • Hi I also faced the same issue, the fix for this is the header type which is Content-Type: application/x-www-form-urlencoded"

    I have creates a html file for this

    <form id="lform" class="cyberpanel" action="https://45.79.127.198:8090/api/loginAPI" method="post">
    <input type="hidden" name="username" value="your-user-name" />
    <input type="hidden" name="password" value="the-password-for-user" />
    </form>

    With this the user is allowed to login and dashboard is loaded.
Sign In or Register to comment.
CyberPanel Discord

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion