# Retrieving DQL Data while connecting to PowerBI

**URL:** <https://community.dynatrace.com/t/retrieving-dql-data-while-connecting-to-powerbi/42041>\
**Category:** Logs\
**Tags:** power-bi, logs\
**Created:** [October 11, 2023, 4:30pm UTC](https://community.dynatrace.com/t/retrieving-dql-data-while-connecting-to-powerbi/42041 "2023-10-11T16:30:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kris\_T](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@Kris\_T](https://community.dynatrace.com/u/Kris_T)\
**Post date:** [October 11, 2023, 4:30pm UTC](https://community.dynatrace.com/t/retrieving-dql-data-while-connecting-to-powerbi/42041/1 "2023-10-11T16:30:20Z")

</div>

We are trying to connecting Dynatrace to PowerBI. We want to run DQL Query and have the results in PowerBI, so we can use:&nbsp;DQL queries via API:&nbsp;[https://www.dynatrace.com/support/help/shortlink/ba-api-ingest#dql-via-api](https://www.dynatrace.com/support/help/shortlink/ba-api-ingest#dql-via-api)

But this is a POST Method and not a GET. I have worked with a colleague and we can authenticate with Tokens for the classic platform APIs and use PowerBI/Excel to integrate with the methods mentioned here and in the [Dynatrace and PowerBI](https://youtu.be/PNX0jCL8AHc?si=zYTzEzC3UE5AqPHR&t=1072)&nbsp;(YT Video).

I see something similar, but not the same, this is more of RFE ([Grail to PowerBI Connector](https://community.dynatrace.com/post/211404))

How can we connect from PowerBI/Excel to DT, to retrieve DQL Response using the DQL API (POST Method)

---

<div class="post-metadata">

**Author:** ![AntonPineiro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antonpineiro/32/49_2.png) [@AntonPineiro](https://community.dynatrace.com/u/AntonPineiro)\
**Post date:** [October 11, 2023, 10:12pm UTC](https://community.dynatrace.com/t/retrieving-dql-data-while-connecting-to-powerbi/42041/2 "2023-10-11T22:12:30Z")

</div>

Hi,

Do you know if you token has “Read logs&nbsp;(logs.read)” permission?

I would check [Log Monitoring API](https://www.dynatrace.com/support/help/shortlink/api-log-monitoring-v2).

Best regards

---

<div class="post-metadata">

**Author:** ![Kris\_T](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@Kris\_T](https://community.dynatrace.com/u/Kris_T)\
**Post date:** [October 12, 2023, 10:22am UTC](https://community.dynatrace.com/t/retrieving-dql-data-while-connecting-to-powerbi/42041/3 "2023-10-12T10:22:15Z")

</div>

I have read logs permission&nbsp;  
I have client token for OAuth and Token ID for API V2 when using token ID method for getting logs using Get method i am getting Error Token Authentication failed&nbsp;Token Authentication failed

and got stuck,&nbsp; Since i am new using API’s i don’t know how to generate bearer token

---

<div class="post-metadata">

**Author:** ![AntonPineiro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antonpineiro/32/49_2.png) [@AntonPineiro](https://community.dynatrace.com/u/AntonPineiro)\
**Post date:** [October 12, 2023, 1:28pm UTC](https://community.dynatrace.com/t/retrieving-dql-data-while-connecting-to-powerbi/42041/4 "2023-10-12T13:28:41Z")

</div>

Hi,

For me, easier way is from here:

 ![AntonPineiro_0-1697117282591.png](https://global.discourse-cdn.com/dynatrace/original/2X/d/dd326fe21bd284a1a5b4a2642058c4a752edf3e3.png)

You can create your token there and play with Dynatrace API Explorer.

Best regards

---

<div class="post-metadata">

**Author:** ![radek\_jasinski](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radek_jasinski/32/10432_2.png) [@radek\_jasinski](https://community.dynatrace.com/u/radek_jasinski)\
**Post date:** [October 13, 2023, 7:04am UTC](https://community.dynatrace.com/t/retrieving-dql-data-while-connecting-to-powerbi/42041/5 "2023-10-13T07:04:55Z")

</div>

Remember also to select the appropriate scope of such a token:

> **[Dynatrace API - Tokens and authentication](https://docs.dynatrace.com/docs/dynatrace-api/basics/dynatrace-api-authentication)**
>
> Find out how to get authenticated to use the Dynatrace API.

---

<div class="post-metadata">

**Author:** ![gordon\_meyer](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@gordon\_meyer](https://community.dynatrace.com/u/gordon_meyer)\
**Post date:** [December 21, 2023, 8:42am UTC](https://community.dynatrace.com/t/retrieving-dql-data-while-connecting-to-powerbi/42041/6 "2023-12-21T08:42:36Z")

</div>

Hi!

Yes it is possible and here is a rudimentary piece of code to help:  
Note you would need to create an oauth client on your tenant to be able to use this as described here:&nbsp;[Access platform APIs from outside | Dynatrace Developer](https://developer.dynatrace.com/develop/access-platform-apis-from-outside/)

then in your Power query connection in Powerbi use the following (this example runs a fetch logs 1000 records DQL query):

let  
body = grant\_type=client\_credentials&client\_id=\<your oauth client id here\>&client\_secret=\<your oauth secret here\>&scope=\<your scope required here(e.g. storage:logs:read+storage:buckets:read)\>,  
Data= Web.Contents(“[https://sso.dynatrace.com/sso/oauth2/token](https://sso-dev.dynatracelabs.com/sso/oauth2/token)”,  
[Content=Text.ToBinary(body),  
Headers=[#“Content-Type”=“application/x-www-form-urlencoded”]]),  
DataRecord = Json.Document(Data) ,  
token=DataRecord[access\_token],  
postBody = \<your dql query here, e.g. {“query”: “fetch logs | limit 1000”,“timezone”: “UTC”,“locale”: “en\_US”,“requestTimeoutMilliseconds”: 60000,“maxResultRecords”: 1000}\>,  
Source = Json.Document(Web.Contents(“https://\<your DT tenant here\>/platform/storage/query/v1/query:execute?enrich=metric-metadata”,  
[Headers=[#“Authorization”="Bearer "&token, #“Content-Type”=“application/json”],  
Content=Text.ToBinary(postBody)])),  
result = Source[result],  
records = result[records],  
#“Converted to Table” = Table.FromList(records, Splitter.SplitByNothing(), null, null, ExtraValues.Error),  
#“Expanded Column1” = Table.ExpandRecordColumn(#“Converted to Table”, “Column1”, {“timestamp”, “content”, “container.image.name”, “container.name”, “dt.entity.container\_group”, “dt.entity.container\_group\_instance”, “dt.entity.host”, “dt.entity.process\_group”, “dt.entity.process\_group\_instance”, “dt.process.name”, “dt.source\_entity”, “event.type”, “host.name”, “log.source”, “loglevel”, “process.technology”, “status”, “container.id”, “log.iostream”}, {“Column1.timestamp”, “Column1.content”, “Column1.container.image.name”, “Column1.container.name”, “Column1.dt.entity.container\_group”, “Column1.dt.entity.container\_group\_instance”, “Column1.dt.entity.host”, “Column1.dt.entity.process\_group”, “Column1.dt.entity.process\_group\_instance”, “Column1.dt.process.name”, “Column1.dt.source\_entity”, “Column1.event.type”, “Column1.host.name”, “Column1.log.source”, “Column1.loglevel”, “Column1.process.technology”, “Column1.status”, “Column1.container.id”, “Column1.log.iostream”})  
in  
#“Expanded Column1”
