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
Chocci_Milk
Chocci_Milk4w ago
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
Dave
DaveOP4w ago
We don’t use browser sessions, all our API usage is server to server
Chocci_Milk
Chocci_Milk4w ago
Here's one way to do it
No description
No description
Chocci_Milk
Chocci_Milk4w ago
session.get(field)
Dave
DaveOP4w ago
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?
Chocci_Milk
Chocci_Milk4w ago
Sure!

Did you find this page helpful?