cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

When calling the log search API, encountered error: 'OAuth token is missing'

Ning
Newcomer

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();

 

 

3 REPLIES 3

Donald_Foss_SCC
Newcomer

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.

TomásSeroteRoos
Dynatrace Helper
Dynatrace Helper

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.

Featured Posts