<?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: Test workflow started by API in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/259916#M1123</link>
    <description>&lt;P&gt;Thanks for sharing it with the Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Oct 2024 09:04:03 GMT</pubDate>
    <dc:creator>imsingh</dc:creator>
    <dc:date>2024-10-21T09:04:03Z</dc:date>
    <item>
      <title>Test workflow started by API</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/258777#M1114</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I needed a way to test my workflow that can be started by the API. Not wanting to make use one of the existing tools for triggering the workflow, I just created a simple Dashboard with variables&amp;nbsp; that fetches the OAUTH token for me, kicks off the workflow and shows the execution log!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="henk_stobbe_0-1728508728011.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/23494i601A02D0629BEECB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="henk_stobbe_0-1728508728011.png" alt="henk_stobbe_0-1728508728011.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Any var change, refreshes the dashboard. So simple but look so nice (-;&lt;/P&gt;
&lt;P&gt;(want to look at the source, just contact me)&lt;/P&gt;
&lt;P&gt;Have fun,&lt;/P&gt;
&lt;P&gt;Henk&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 09:03:42 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/258777#M1114</guid>
      <dc:creator>henk_stobbe</dc:creator>
      <dc:date>2024-10-21T09:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Test workflow started by API</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/259916#M1123</link>
      <description>&lt;P&gt;Thanks for sharing it with the Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 09:04:03 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/259916#M1123</guid>
      <dc:creator>imsingh</dc:creator>
      <dc:date>2024-10-21T09:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Test workflow started by API</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/262222#M1157</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/11427"&gt;@henk_stobbe&lt;/a&gt;&amp;nbsp;- would you mind sharing this dashboard with me?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 15:49:25 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/262222#M1157</guid>
      <dc:creator>andreas_grabner</dc:creator>
      <dc:date>2024-11-12T15:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Test workflow started by API</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/265137#M1209</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Forgot about this post, but while catching up found:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.youtube.com/watch?v=IVFc0-Iil8w&amp;amp;t=879s" target="_blank"&gt;https://www.youtube.com/watch?v=IVFc0-Iil8w&amp;amp;t=879s&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Not my original idea, but yeah you can look at it as a kind of poor man's app.&amp;nbsp;&lt;/P&gt;&lt;P&gt;KR Henk&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 18:23:16 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/265137#M1209</guid>
      <dc:creator>henk_stobbe</dc:creator>
      <dc:date>2024-12-12T18:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Test workflow started by API</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/265138#M1210</link>
      <description>&lt;H3&gt;&amp;nbsp;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":christmas_tree:"&gt;🎄&lt;/span&gt;&lt;/SPAN&gt;Weihnachtsgeschenk&lt;STRONG&gt; (-;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":christmas_tree:"&gt;🎄&lt;/span&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;Grüße Henk&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2024 10:13:22 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/265138#M1210</guid>
      <dc:creator>henk_stobbe</dc:creator>
      <dc:date>2024-12-15T10:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Test workflow started by API</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/265294#M1216</link>
      <description>&lt;P&gt;export default async function () {&lt;BR /&gt;const sleep = (delay) =&amp;gt; new Promise((resolve) =&amp;gt; setTimeout(resolve, delay));&lt;/P&gt;&lt;P&gt;// Token request URL&lt;BR /&gt;const token_url = '&lt;A href="https://sso.dynatrace.com/sso/oauth2/token" target="_blank"&gt;https://sso.dynatrace.com/sso/oauth2/token&lt;/A&gt;';&lt;/P&gt;&lt;P&gt;// First token credentials&lt;BR /&gt;const params1 = new URLSearchParams({&lt;BR /&gt;grant_type: 'client_credentials',&lt;BR /&gt;client_id: 'dt0s02.???',&lt;BR /&gt;client_secret: 'dt0s02.???',&lt;BR /&gt;resource: 'urn:dtaccount:???',&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;// Second token credentials&lt;BR /&gt;const params2 = new URLSearchParams({&lt;BR /&gt;grant_type: 'client_credentials',&lt;BR /&gt;client_id: 'dt0s02.???',&lt;BR /&gt;client_secret: 'dt0s02.???',&lt;BR /&gt;resource: 'urn:dtaccount:???',&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;// Common headers for token requests&lt;BR /&gt;const tokenHeaders = {&lt;BR /&gt;'Content-Type': 'application/x-www-form-urlencoded',&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt;// First token request&lt;BR /&gt;const response1 = await fetch(token_url, {&lt;BR /&gt;method: 'POST',&lt;BR /&gt;headers: tokenHeaders,&lt;BR /&gt;body: params1.toString(), // URL-encoded parameters&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;if (!response1.ok) {&lt;BR /&gt;const errorBody = await response1.text();&lt;BR /&gt;throw new Error(`Error fetching first token: ${response1.status} - ${errorBody}`);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;const responseData1 = await response1.json();&lt;BR /&gt;const accessToken1 = responseData1.access_token;&lt;BR /&gt;console.log('First token received:', accessToken1);&lt;/P&gt;&lt;P&gt;// Use first token to call workflow API&lt;BR /&gt;const workflowUrl = 'https://???.apps.dynatrace.com/platform/automation/v1/workflows/???/run';&lt;BR /&gt;const workflowHeaders = {&lt;BR /&gt;Authorization: `Bearer ${accessToken1}`,&lt;BR /&gt;'Content-Type': 'application/json',&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;const body = {&lt;BR /&gt;input: {&lt;BR /&gt;request: $request,&lt;BR /&gt;endpoint: $endpoint,&lt;BR /&gt;cloudprovider: $cloudprovider,&lt;BR /&gt;environment: $environment,&lt;BR /&gt;body: $body,&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;const workflowResponse = await fetch(workflowUrl, {&lt;BR /&gt;method: 'POST',&lt;BR /&gt;headers: workflowHeaders,&lt;BR /&gt;body: JSON.stringify(body),&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;if (!workflowResponse.ok) {&lt;BR /&gt;const wfErrorBody = await workflowResponse.text();&lt;BR /&gt;throw new Error(`Error in Workflow API call: ${workflowResponse.status} - ${wfErrorBody}`);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;const workflowData = await workflowResponse.json();&lt;BR /&gt;console.log('Workflow response:', workflowData);&lt;/P&gt;&lt;P&gt;// Second token request&lt;BR /&gt;const response2 = await fetch(token_url, {&lt;BR /&gt;method: 'POST',&lt;BR /&gt;headers: tokenHeaders,&lt;BR /&gt;body: params2.toString(), // URL-encoded parameters&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;if (!response2.ok) {&lt;BR /&gt;const errorBody = await response2.text();&lt;BR /&gt;throw new Error(`Error fetching second token: ${response2.status} - ${errorBody}`);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;const responseData2 = await response2.json();&lt;BR /&gt;const accessToken2 = responseData2.access_token;&lt;BR /&gt;console.log('Second token received:', accessToken2);&lt;/P&gt;&lt;P&gt;// Log request URL&lt;BR /&gt;const logUrl = `https://???.apps.dynatrace.com/platform/automation/v1/executions/${workflowData.id}/tasks`;&lt;/P&gt;&lt;P&gt;// Sleep before fetching logs&lt;BR /&gt;await sleep(10000);&lt;/P&gt;&lt;P&gt;// Make the log request with the second token&lt;BR /&gt;const logHeaders = {&lt;BR /&gt;Authorization: `Bearer ${accessToken2}`,&lt;BR /&gt;'Content-Type': 'application/json',&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;const logResponse = await fetch(logUrl, {&lt;BR /&gt;method: 'GET',&lt;BR /&gt;headers: logHeaders,&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;if (!logResponse.ok) {&lt;BR /&gt;const logErrorBody = await logResponse.text();&lt;BR /&gt;throw new Error(`Error in Workflow LOG call: ${logResponse.status} - ${logErrorBody}`);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;const logData = await logResponse.json();&lt;BR /&gt;console.log('Workflow log response:', logData);&lt;/P&gt;&lt;P&gt;return logData;&lt;/P&gt;&lt;P&gt;} catch (error) {&lt;BR /&gt;console.error(`Error occurred: ${error.message}`);&lt;BR /&gt;throw error;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2024 07:33:50 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Test-workflow-started-by-API/m-p/265294#M1216</guid>
      <dc:creator>henk_stobbe</dc:creator>
      <dc:date>2024-12-14T07:33:50Z</dc:date>
    </item>
  </channel>
</rss>

