Menta, SivaKumar, thank you for posting this question and apologies for the delayed response.
Based on the error reported "Provided credentials have insufficient access...", it seems that the step below was missed/not followed completely for the app registered in Azure AD (of which the client and secret is being used to get token): Register an App to request authorization tokens and work with Log Analytics APIs.
I would suggest running the first half of the python script shared to get the access token and then use tools like VS Code with REST Client OR Postman to make the request directly and get the response back. This would help validate the token and its authorization to use the API.
The following additional links should help you in this regard:
- Azure Monitor Query client library for Python - version 1.2.0.
- Log Analytics REST API Reference If the step above does not help, can you please share a more complete script for me to try out (Please remove the client id, secret, workspace id etc.) I would like to understand module used and the exact API and queries being used.
Hope this helps.