0

I want to register a user on drupal site through REST, I read this article, and implemented the instructtins exactly the same using Postman on drupal 8.3.

specially when I send this specification :

POST: http://example.com/user/register
Content-type: application/json
Data: { "name": [
  {
    "value": "test"
  }
],
"mail": [
  {
    "value": "aa@bb.com"
  }
],
"pass": [
  {
    "value": "test"
  }
]  }

Response is: 500 service unavailable (with message)

What should I do to solve the problem?

  • Check your Drupal log - it should show an error. What is the error? – Jaypan Feb 17 '17 at 5:44
  • error: InvalidArgumentException: Field 0 is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 506 of D:\wamp95\www\drupal83\core\lib\Drupal\Core\Entity\ContentEntityBase.php). – Mde Feb 17 '17 at 5:52
1

Just a stab in the dark here.

It seems that you have extra square brackets. I think this is why your error message refers to field 0 -- you're sending it an array. Try it exactly as the article displays, with no square brackets?

For example: "pass": { "value": "test" }

Good luck.

Update

To enable setting a password, you need to change a setting which is default in the install.

Go to admin/config/people/accounts (Configuration > People > Account Settings) and uncheck "Require email verification when a visitor creates an account":

Correct settings

Granted you are allowing POST to Anonymous users as described in the article above, you should be good to go and get a response such as the following in PostMan:

{
  "uid": [
    {
      "value": "5"
    }
  ],
  "uuid": [
    {
      "value": "70738718-d4e9-455e-a1f6-cf95df613507"
    }
  ],
  "langcode": [
    {
      "value": "en"
    }
  ],
  "name": [
    {
      "value": "ac@bb.com"
    }
  ],
  "created": [
    {
      "value": 1487319576
    }
  ],
  "changed": [
    {
      "value": 1487319576
    }
  ],
  "default_langcode": [
    {
      "value": true
    }
  ],
  "user_picture": []
}

Hope this helps!!

  • I deleted the square brackets, now it returns : {422 Unprocessable Entity} error! – Mde Feb 17 '17 at 7:05
  • and log report is: Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException: A Password cannot be specified. It will be generated on login. in Drupal\user\Plugin\rest\resource\UserRegistrationResource->ensureAccountCanRegister() (line 164 of D:\wamp95\www\drupal83\core\modules\user\src\Plugin\rest\resource\UserRegistrationResource.php). – Mde Feb 17 '17 at 7:11
  • I'm running into the same error as you now. It goes away if I remove the pass parameter, but I think the point is that you wanted to generate a user with a password? – Christopher Borchert Feb 17 '17 at 8:16
  • Of course, user needs password. I think it's a core issue, where should I propose it to be solved? – Mde Feb 17 '17 at 8:24
  • Updated my answer. If you want to ASSIGN the user a password, you must change your Account Settings Configuration. Otherwise, the user will be sent an email and they will set their own password. – Christopher Borchert Feb 17 '17 at 8:26

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.