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

**URL:** <https://community.dynatrace.com/t/when-calling-the-log-search-api-encountered-error-oauth-token-is-missing/44701>\
**Category:** Dynatrace API\
**Tags:** tokens, dynatrace-api\
**Created:** [March 16, 2024, 2:58pm UTC](https://community.dynatrace.com/t/when-calling-the-log-search-api-encountered-error-oauth-token-is-missing/44701 "2024-03-16T14:58:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ning](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Ning](https://community.dynatrace.com/u/Ning)\
**Post date:** [March 16, 2024, 2:58pm UTC](https://community.dynatrace.com/t/when-calling-the-log-search-api-encountered-error-oauth-token-is-missing/44701/1 "2024-03-16T14:58:11Z")

</div>

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:

```markup
{
    "error": {
        "code": 401,
        "message": "OAuth token is missing"
    }
}

```

The way I called it:

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

```

 ![WechatIMG2.jpg](https://global.discourse-cdn.com/dynatrace/original/3X/8/3/83061fd3db7db59a5a054ccb3024e6b7413ce74c.jpeg)

---

<div class="post-metadata">

**Author:** ![Ning](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Ning](https://community.dynatrace.com/u/Ning)\
**Post date:** [March 16, 2024, 2:58pm UTC](https://community.dynatrace.com/t/when-calling-the-log-search-api-encountered-error-oauth-token-is-missing/44701/2 "2024-03-16T14:58:51Z")

</div>

The document I refer to is : [Log Monitoring API v2 - GET search logs — Dynatrace Docs](https://docs.dynatrace.com/docs/dynatrace-api/environment-api/log-monitoring-v2/get-search-logs)

---

<div class="post-metadata">

**Author:** ![Donald\_Foss\_SCC](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@Donald\_Foss\_SCC](https://community.dynatrace.com/u/Donald_Foss_SCC)\
**Post date:** [May 1, 2024, 3:37pm UTC](https://community.dynatrace.com/t/when-calling-the-log-search-api-encountered-error-oauth-token-is-missing/44701/3 "2024-05-01T15:37:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tom\_sSeroteRoos](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@Tom\_sSeroteRoos](https://community.dynatrace.com/u/Tom_sSeroteRoos)\
**Post date:** [July 19, 2024, 6:19am UTC](https://community.dynatrace.com/t/when-calling-the-log-search-api-encountered-error-oauth-token-is-missing/44701/4 "2024-07-19T06:19:52Z")

</div>

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](https://docs.dynatrace.com/docs/shortlink/ba-api-ingest#authentication) 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.
