0

AUTH REST API:

if(isset($_POST)){
    print_r($_POST);
    $email=$_POST['email'];
    $pass=$_POST['pwd'];

    //$email='memotest@gmailtest.com';
    //$pass='memo@123';

$userData= array("username" => "api", "password" => "*********");
$link = "4ao8yk15rvchyqhc.mojostratus.io";


//generateApiToken();

$ch = curl_init("$link/index.php/rest/V1/integration/admin/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));
$token = curl_exec($ch);



 $ch = curl_init("$link/index.php/rest/V1/Login/check/$email/$pass");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_encode($token)));
$result = curl_exec($ch); 
$result = json_decode($result, True);
echo "<pre>";

var_dump($result);die;

And Result : enter image description here

1
  • Have you created new API with endpoint as rest/V1/Login/check/email/pass. – Ramkishan Suthar Nov 9 '18 at 15:43
1

The user api needs to have a role with permissions to access that resource.

As a debug method though, I would first try to var_dump($token) to make sure you are first getting the token.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.