โ07-28-2025 06:58 AM
I have a weird issue with Databricks.
I'm using the query history API:
https://docs.databricks.com/api/workspace/queryhistory/list
When I'm using the API with Personal Access Token, it works great.
When i'm using the API with Service Principal, i'm getting only the history of the service principal.
I made sure that Service Principal has "Can Manage" Permission to the SQL Warehouse.
In addition, I added the Service Principal to the "admins" group but it didn't help.
This is very critical for one of our customers.
Thanks!
โ07-29-2025 09:47 AM
Hi @lio-illumex ,
Have you applied the filter while making the API call?
Try adding all target user IDs to the filter_by.user_ids field in your request bodyโthis might help retrieve the full query history you're expecting.
โ07-29-2025 10:55 AM - edited โ07-29-2025 10:55 AM
@lio-illumex I think the API gets a paginated response. you need to hit the API recursively untill it reached the last page. Loop in until you get next_page_token. I would say the best way is to use the databricks SDK. It is simpler then the APIs.
https://databricks-sdk-py.readthedocs.io/en/stable/workspace/sql/query_history.html
โ07-29-2025 09:23 PM
The Query History API is scoped to the calling identity, so even with admin rights, service principals can only access their own queriesโcross-user access isn't supported.
โ07-30-2025 08:17 AM
@SP_6721 I don't filter by user ids in both scenarios, it shouldn't matter
@nayan_wylde I also tried with the SDK but it's the same API call behind the scenes. I made sure it's not a pagination issue.
@jhonm_839 This is so weird. PAT and SP have the same admin rights.... and the admin PAT can see the SP queries.... I don't understand how it's not possible the other way around
โ07-30-2025 06:24 PM
Is your workspace Unity Catalog Enabled? If yes try to give the SPN metastore admin permissions. Hopefully it should resolve the issue.