13 Jul 2023 02:57 PM - last edited on 13 Jul 2023 03:25 PM by educampver
Hey guys,
We are testing the potential of using the new Dashboards with the use of Javascript, so you can concentrate the telemetry and governance data of my Managed Clusters in the SelfMonitoring environment.
We would like to have a Governance panel for tokens created on the Dynatrace platform and for that we perform the GET ALL in the respective API and then we need to perform a loop to obtain the details of each id returned in the vector. I would not like to use an external solution with python for this, is the ad-hoc function capable of doing this?
Our code example follows below, where an "HTTP Error 540: Unknown" error is displayed and no further details of the actual reason for the error are reported:
export default async function () {
const environment = "{}/endpoint"
const token = "{token}";
const params = '/api/v2/apiTokens?pageSize=600&sort=-creationDate';
const uri = environment + params;
const response = await fetch(uri, {
headers: {
Accept: "application/json",
Authorization: "Api-Token " + token
}});
const result = await response.json();
const apiTokens = result.apiTokens;
const secondAPIresults = [];
await Promise.all(apiTokens.map(async (token) => {
const uri2 = environment + '/api/v2/apiTokens/${token.id}';
const response2 = await fetch(uri2, {
headers: {
Accept: "application/json",
Authorization: "Api-Token " + token
}});
const data = await response2.json();
const { name, lastUsedDate } = data;
secondAPIResults.push({ name, lastUsedDate });
}));
return secondAPIResults;
}
Solved! Go to Solution.
13 Jul 2023 03:24 PM
Hi @MarcioKaue, the error 540 means there's an issue with the code. At the moment, you can debug these errors by catching them in your ad-hoc function and returning the error message as part of the response. Here's an example https://developer.dynatrace.com/develop/functions/error-handling/#custom-error-reporting.
At first glance, it looks like a typo. You're declaring a variable called secondAPIresults
with lowercase r
, but then using secondAPIResults
with uppercase R
.
13 Jul 2023 04:09 PM
Hello @educampver , the variable actually had this incorrect character, but the code does not work with the suggested adjustment.
Thank you for coming back with the documentation, we will evaluate it in order to have a more detailed troubleshooting of the reason for the error.