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": "[email protected]"
  }
],
"pass": [
  {
    "value": "test"
  }
]  }

Response is: 500 service unavailable (with message)

What should I do to solve the problem?

2
  • Check your Drupal log - it should show an error. What is the error?
    – Jaypan
    Commented Feb 17, 2017 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).
    – Mdeh
    Commented Feb 17, 2017 at 5:52

1 Answer 1

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": "[email protected]"
    }
  ],
  "created": [
    {
      "value": 1487319576
    }
  ],
  "changed": [
    {
      "value": 1487319576
    }
  ],
  "default_langcode": [
    {
      "value": true
    }
  ],
  "user_picture": []
}

Hope this helps!!

6
  • I deleted the square brackets, now it returns : {422 Unprocessable Entity} error!
    – Mdeh
    Commented Feb 17, 2017 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).
    – Mdeh
    Commented Feb 17, 2017 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? Commented Feb 17, 2017 at 8:16
  • Of course, user needs password. I think it's a core issue, where should I propose it to be solved?
    – Mdeh
    Commented Feb 17, 2017 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. Commented Feb 17, 2017 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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