<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is it possible to use ad-hoc functions to query endpoints by looping? in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Is-it-possible-to-use-ad-hoc-functions-to-query-endpoints-by/m-p/217956#M390</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/55571"&gt;@MarcioKaue&lt;/a&gt;, 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&amp;nbsp;&lt;A href="https://developer.dynatrace.com/develop/functions/error-handling/#custom-error-reporting" target="_blank"&gt;https://developer.dynatrace.com/develop/functions/error-handling/#custom-error-reporting&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;At first glance, it looks like a typo. You're declaring a variable called &lt;CODE&gt; secondAPIresults&lt;/CODE&gt;with lowercase &lt;CODE&gt;r&lt;/CODE&gt;, but then using &lt;CODE&gt; secondAPIResults&lt;/CODE&gt; with uppercase &lt;CODE&gt;R&lt;/CODE&gt;.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Jul 2023 14:24:51 GMT</pubDate>
    <dc:creator>educampver</dc:creator>
    <dc:date>2023-07-13T14:24:51Z</dc:date>
    <item>
      <title>Is it possible to use ad-hoc functions to query endpoints by looping?</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Is-it-possible-to-use-ad-hoc-functions-to-query-endpoints-by/m-p/217950#M389</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hey guys,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;export default async function () {
  const environment = "{}/endpoint"
  const token = "{token}";
  const params = '/api/v2/apiTokens?pageSize=600&amp;amp;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) =&amp;gt; {
    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;
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2023 14:25:32 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Is-it-possible-to-use-ad-hoc-functions-to-query-endpoints-by/m-p/217950#M389</guid>
      <dc:creator>MarcioKaue</dc:creator>
      <dc:date>2023-07-13T14:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use ad-hoc functions to query endpoints by looping?</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Is-it-possible-to-use-ad-hoc-functions-to-query-endpoints-by/m-p/217956#M390</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/55571"&gt;@MarcioKaue&lt;/a&gt;, 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&amp;nbsp;&lt;A href="https://developer.dynatrace.com/develop/functions/error-handling/#custom-error-reporting" target="_blank"&gt;https://developer.dynatrace.com/develop/functions/error-handling/#custom-error-reporting&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;At first glance, it looks like a typo. You're declaring a variable called &lt;CODE&gt; secondAPIresults&lt;/CODE&gt;with lowercase &lt;CODE&gt;r&lt;/CODE&gt;, but then using &lt;CODE&gt; secondAPIResults&lt;/CODE&gt; with uppercase &lt;CODE&gt;R&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2023 14:24:51 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Is-it-possible-to-use-ad-hoc-functions-to-query-endpoints-by/m-p/217956#M390</guid>
      <dc:creator>educampver</dc:creator>
      <dc:date>2023-07-13T14:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use ad-hoc functions to query endpoints by looping?</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Is-it-possible-to-use-ad-hoc-functions-to-query-endpoints-by/m-p/217967#M391</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/47555"&gt;@educampver&lt;/a&gt;&amp;nbsp;, the variable actually had this incorrect character, but the code does not work with the suggested adjustment.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2023 15:09:05 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Is-it-possible-to-use-ad-hoc-functions-to-query-endpoints-by/m-p/217967#M391</guid>
      <dc:creator>MarcioKaue</dc:creator>
      <dc:date>2023-07-13T15:09:05Z</dc:date>
    </item>
  </channel>
</rss>

