Hi, I would like to update a user in the directory...
# permit-saas
m
Hi, I would like to update a user in the directory using the PUT method. How can I specify the resource role assignment? When I tried 'Top Level Role' such as 'Admin', it worked, but 'Application#Trade' is not working for me.
Copy code
curl -X PUT "<https://api.permit.io/v2/facts/default/dev/users/Test@Test.com>" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer xxx" \
  -d '{
    "key": "<mailto:Test@Test.com|Test@Test.com>",
    "email": "<mailto:Test@Test.com|Test@Test.com>",
    "first_name": "Jane",
    "last_name": "Doe",
    "attributes": {
      "department": "marketing",
      "age": 30,
      "subscription": {}
    },
    "role_assignments": [
      {
        "role": "application#Trade",
        "tenant": "default"
      }
    ]
  }'
response
Copy code
{
  "id": "4826aa77c24042a4bd4ca460ff37ddd7",
  "title": "We could not find the requested object/s",
  "error_code": "NOT_FOUND",
  "message": "The requested data could not be found, we could not find 'Role' with the given filters: id='application#Trade'. Please try again with different filters.\nIf you are sure there is an object with the given filters, contact our support on Slack for further guidance.",
  "additional_info": {
    "filters": {
      "id": "application#Trade"
    }
  }
}
Role exist in the project.
a
Hi @Michał Wójcik, I'm an AI assistant for Permit.io. I'll analyze available sources and get back to you shortly.
The issue is that you're trying to assign a resource-level role (like
Application#Trade
) directly through the user update endpoint, but resource-level roles require a
resource_instance
to be specified. (1) For resource-level roles, you need to use the role assignments endpoint instead. Here's how to properly assign a resource-level role:
Copy code
await permit.api.roleAssignments.assign({
  role: "Marketer",
  tenant: "default",
  resource_instance: `Dashboard:${dashboard.id}`,
  user: "auth0|elon",
}) ;
Or using cURL:
Copy code
curl '<https://api.permit.io/v2/facts/{proj_id}/{env_id}/role_assignments>' \
  --request POST \
  --data '{
    "user": "<mailto:jane@coolcompany.com|jane@coolcompany.com>",
    "role": "admin",
    "tenant": "stripe-inc"
  }'
To learn more, see the sources I considered: [[1] Sync Data into your App](https://docs.permit.io/overview/sync-applications-data) [[2] Fintech / Banking Demo Application](https://docs.permit.io/modeling/mesa-verde)
o
AI gave solid advice here (i.e. resource vs resource instance)
✅ 1
a
Thanks for the feedback, glad I was helpful.