Evan Bloemer
Evan Bloemer

Reputation: 1081

Loopback Update User Field

I am trying to update a field in a model that extends the user model. In the API explorer, I set the where field to {"id": 59}, and have the access token one that corresponds with id 59. In the data field I have {"age": 55} where I am just trying to update the age to 55.

The request URL ends up being: http://IP:3000/api/MODEL/update?where=%7B%22id%22%3A%2059%7D&access_token=LONG ACCESS TOKEN VALUE

Which gives an error:

{
  "error": {
    "statusCode": 401,
    "name": "Error",
    "message": "Authorization Required",
    "code": "AUTHORIZATION_REQUIRED",
    }
}

I don't understand why authorization is required when I have a correct access token and the email has been verified. What am I doing wrong?

Upvotes: 0

Views: 636

Answers (1)

itssajan
itssajan

Reputation: 830

Loopback by default provides ACL to user model. So by default the update operation can only be changed by the $OWNER, ie. the person himself.

So first login with the username and password, you get the accesstoken. Copy and set the accesstoken in Api Explorer.

Now use the PUT method, which will say Users/{$id}

Open it and you will see 2 fields, data and id. Provide your model's id and provide the data object (the data that needs to be changed)

Hope this helps.

Upvotes: 1

Related Questions