# CakePHP 4 Auth plugin API call

**URL:** <https://discourse.cakephp.org/t/cakephp-4-auth-plugin-api-call/8142>\
**Category:** Need Help\
**Created:** [July 29, 2020, 8:39am UTC](https://discourse.cakephp.org/t/cakephp-4-auth-plugin-api-call/8142 "2020-07-29T08:39:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [July 29, 2020, 8:39am UTC](https://discourse.cakephp.org/t/cakephp-4-auth-plugin-api-call/8142/1 "2020-07-29T08:39:27Z")

</div>

I am building an API and try to log in the users to he CakePHP backend. The users sends their email and password and they get a token and after that all API calls authenticated with the token.

I used the example codes from the cookbook.

When I send the credentials to the API’s `/users/login.json` url than `$this->Authentication->getResult()` status is FAILURE\_OTHER with or without the correct credentials.

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [July 29, 2020, 8:49am UTC](https://discourse.cakephp.org/t/cakephp-4-auth-plugin-api-call/8142/2 "2020-07-29T08:49:20Z")

</div>

That is why forums are great tools… After a few hours of stuck with this problem I found the solution 2 minutes after posting the question 🙂

```php
$service->loadAuthenticator('Authentication.Form', [
  'fields' => $fields,
  'loginUrl' => '/users/login.json'
  ]);

```

As the frontend app calls `/users/login.json` we have to have it as the `loginUrl` and not just `/users/login`.
