16 Mar 2024 02:58 PM
I want to use the Dynatrace API to query logs. Following the documentation requirements, I created an Access Token and granted it the 'logs.read' scope.
However, when calling the API, the following error occurred:
{
"error": {
"code": 401,
"message": "OAuth token is missing"
}
}
The way I called it:
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.get("https://{environmentid}.live.dynatrace.com/api/v2/logs/search")
.header("Authorization", "Api-Token dt0c01.xxxxx.xxxxx")
.header("Content-Type", "application/json")
.body("")
.asString();
Solved! Go to Solution.
16 Mar 2024 02:58 PM
The document I refer to is : https://docs.dynatrace.com/docs/dynatrace-api/environment-api/log-monitoring-v2/get-search-logs
01 May 2024 04:37 PM
Did you find a solution? I have the exact same issue. I'm using a freshly created token with only log.read access.
On a side note, with your request in the example, you don't need to set the content-type header on a GET request. You're not sending any data for which you need to specify the type of content. However, you do need to specify your query parameters.
I guess there aren't that many of us using this API.
19 Jul 2024 07:19 AM
A bit late to the party, but found that you need to use a token from an OAuth client with the permissions storage:buckets:read and storage:logs:read.
You first need to create a client on the UI, then obtain a bearer token with the right scopes and use that to authenticate with the logs API (note you'll need to pass a header Authorization: Bearer <token> as opposed to the old Authorization: Api-token <token>).
This docs page should help guide you even though it's for biz events/DQL queries. The process is the same, the only thing that changes are the scopes you need.