Retrieving role from context
I've created an audit trail model which captures changes to other models so we can view the entire history of a record, I'd like to be able to capture which role / API key triggered the change so it's clear if it was a user who made the change, or us. Is this possible? I can't find anything in the docs.
6 Replies
Hello,
I believe that you should be able to get the session information from the context and then make a request to the session model to look at the role. There might be some other way to do it but I'm not sure. Let me take a quick look
We don’t use browser sessions, all our API usage is server to server
Here's one way to do it


session.get(field)
That won't work because there's no session in server to server so the result is always null. The closest I can get to identifying the role is retrieving the API key which is on
request.headers["authorization"]
but it's not particularly useful when trying to identify the role being used. Should I add this as a feature request?Sure!