0

I'm trying to log in to drupal8 via api rest using postman.

POST: https://example.com/user/login?_format=json
Content-type: application/json

{
"name": "admin",
"pass": "password"
}

The problem is that this error is returned to me.

An unexpected error has occurred. Please try again later, thanks.
Symfony\Component\Serializer\Exception\NotEncodableValueException: Syntax error in Symfony\Component\Serializer\Encoder\JsonDecode->decode() (line 78 of C:\www\drupal-composer\vendor\symfony\serializer\Encoder\JsonDecode.php).

Symfony\Component\Serializer\Encoder\JsonEncoder->decode('', 'json', Array) (Line: 40)
Symfony\Component\Serializer\Encoder\ChainDecoder->decode('', 'json', Array) (Line: 280)
Symfony\Component\Serializer\Serializer->decode('', 'json') (Line: 167)
Drupal\user\Controller\UserAuthenticationController->login(Object) call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Does anyone have a solution? I am using Drupal 8.7.1.

  • Is the payload correct? The error thrown is NotEncodableValueException. See comment #4 in what you linked to. – Kevin May 13 at 14:16
  • Yes the payload is correct, obviously I have inserted some sample data. Even trying with curl I get the same error. – Fabio Marsigliano May 13 at 14:30
  • The error stack is indicating that the $data is empty though – Kevin May 13 at 14:31
  • I'm trying to log-in following the official documentation here: drupal.org/docs/8/core/modules/rest/… using postman with the correct payload and the correct endpoint, but nothing. Always the same error. I also try other drupal installations, same mistake :-( – Fabio Marsigliano May 13 at 14:42
  • 1
    Solution found! Postman: method POST; endpoint: http://{your_url}/user/login?_format=json; section Header: Content-Type: application/json; section body: { "name": "admin","pass": "admin"} – Fabio Marsigliano May 13 at 14:56
1

Solution found! In Postman:

  • method: POST
  • endpoint: http://{your_url}/user/login?_format=json
  • in section Header: Content-Type: application/json
  • in section body: {"name":"admin","pass": "admin"}

Note: name and password must be entered in the body section (raw)

  • You just saved my life... i spent 4 hours already :D – Abdul Sadik Yalcin Dec 4 at 15:17

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.