14 Aug 2025 03:50 PM
Hi all,
Due to limitations in Grail currently (from previous post), I'm trying to get data from the Dynatrace API into a dashboard. I am using this code in Dynatrace:
export default async function () {
const fake_api_token = 'dtc10.faketoken';
const response = await fetch('https://api.dynatrace.com/kdsdkeokkdeokfoekfeofko');
const result = response.json();
return result;
The query successfully returns but it is all bunched up in the column result. I've tried doing things like result.value and result.data so it auto-formats into a table but it does not.
I am using the Dynatrace Metrics Query V2 from the API and have been following this article:
26 Aug 2025 03:35 PM
Hi,
I tested the code you sent, and I changed it to extract the SLOs using the Dynatrace API and you’re right—it returns a table with the API results, and one column contains the information (in my case, it’s called “slo”) when using "return result", as shown below:
Code:
export default async function () {
const token = 'dt0c01.token';
const response = await fetch('https://dynatrace.com/e/8436fe7/api/v2/slo', {
headers: {
Accept: "application/json",
Authorization: "Api-Token " + token
}});
const result = response.json();
return result;
}
Result:
If we try to use return "result.slo", it shows that there’s no data:
Code:
export default async function () {
const token = 'dt0c01.token';
const response = await fetch('https://dynatrace.com/e/8436fe7/api/v2/slo', {
headers: {
Accept: "application/json",
Authorization: "Api-Token " + token
}});
const result = response.json();
return result.slo;
}
Result:
So, I then tried adding "await" to "const result = response.json();", making it "const result = await response.json();", and that did return the table with the SLOs. Just to clarify, I added the headers because the API call requires authorization:
Code:
export default async function () {
const token = 'dt0c01.token';
const response = await fetch('https://dynatrace.com/e/8436fe7/api/v2/slo', {
headers: {
Accept: "application/json",
Authorization: "Api-Token " + token
}});
const result = await response.json();
return result.slo;
}
Result:
I’m not sure if this answers your question, but if you have any other doubts, please feel free to ask.