0

I followed the official rest-api documentation of sylius but couldn't create the user with field user[authorizationRoles]. Since role_user is default role, i provided arrays of roles as mentioned in docs like this

    POST http://localhost:8000/api/customers/

    firstName = Ram
    lastName = Thakuri
    email = ram@yahoo.com
    gender = m
    user[plainPassword] = ******
    user[authorizationRoles] = [ROLE_API_ACCESS]

I even searched in similar posts but couldn't found right answer, don't know where i am wrong but got validation failed message and errors as below (i am using POSTMAN).

{
  "code": 400,
  "message": "Validation Failed",
  "errors": {
    "errors": [
       "This form should not contain extra fields."
     ],
    "children": {
    "firstName": {},
    "lastName": {},
    "email": {},
    "birthday": {},
    "gender": {},
    "phoneNumber": {},
    "subscribedToNewsletter": {},
    "group": {},
    "user": {
      "children": {
        "plainPassword": {},
        "enabled": {}
      }
    }
   }
  }
}

I want to receive an access token using an OAUTH for every registered user to have an api access.

I am newbie to sylius so please help me out on this.

Thanks in advance

1 Answers1

1

You are not able to do it out-of-the-box. The endpoint you are trying to use is related to customers, therefore setting authorization roles has been removed. This part of the documentation is outdated. You can open a PR with the fix, if you want :)

Anyway, it will be possible to do it with the PR #7711 which will allow managing SyliusUsers but through /users/ endpoint which will not create a customer.

The best solution for you would be to customise Sylius\Bundle\CoreBundle\Form\Type\User\ShopUserType and add that field to FormType. Just take a look at the PR I have mentioned before.

Just as a warning, I want to stress, that ShopApi is an experimental concept for Sylius, so you can meet a lot more complex problems if you want to use it this way. It is doable, but not trivial.

lchrusciel
  • 361
  • 1
  • 5