<?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>article How to get a OTP from an API and use it in a Browser Monitor in Troubleshooting</title>
    <link>https://community.dynatrace.com/t5/Troubleshooting/How-to-get-a-OTP-from-an-API-and-use-it-in-a-Browser-Monitor/ta-p/239746</link>
    <description>&lt;DIV class="lia-message-template-content-zone"&gt;
&lt;P&gt;&lt;EM&gt;Summary:&amp;nbsp;Many applications now require an OTP for authentication. The following steps and snippet can be used to get the OTP from an API and populate it in a page.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;How to get an OTP from an API and use it in a Browser Monitor&lt;/H2&gt;
&lt;P&gt;&lt;SPAN&gt;1.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Create synthetic monitor events up to the point where the one-time password (OTP) is needed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL dir="auto"&gt;
&lt;LI&gt;Navigate to the URL.&lt;/LI&gt;
&lt;LI&gt;login with credentials&lt;/LI&gt;
&lt;LI&gt;The OTP page appears.&lt;/LI&gt;
&lt;LI&gt;Open a page on the same domain as the API URL in a new tab if the original navigation and API domains are different. This step is only necessary if you see a CORS error when making the fetch in the next event.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN&gt;2. Add a JavaScript event, using&amp;nbsp;&lt;STRONG class="sc-bf977b27-0 hNpJEd"&gt;&lt;A href="https://docs.dynatrace.com/docs/platform-modules/digital-experience/synthetic-monitoring/browser-monitors/configure-browser-monitors#recorded-clickpath" target="_self"&gt;Add synthetic event&lt;/A&gt;,&amp;nbsp;&lt;/STRONG&gt;to fetch the OTP value and save the value. Something like the below, which stores the value in a variable called token.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;api.startAsyncSyntheticEvent();&lt;BR /&gt;fetch('&amp;lt;yoururl&amp;gt;', {&lt;BR /&gt;    method: 'POST',&lt;BR /&gt;    headers: {&lt;BR /&gt;        'content-type': 'application/json',&lt;BR /&gt;        'Access-Control-Allow-Origin': '*',&lt;BR /&gt;        'Access-Control-Allow-Headers': 'X-Requested-With'&lt;BR /&gt;    }&lt;BR /&gt;}).then(function(response) {&lt;BR /&gt;        if (!response.ok) {&lt;BR /&gt;            throw Error(response.status + ":" + response.statusText);&lt;BR /&gt;        }&lt;BR /&gt;        return response;&lt;BR /&gt;   }).then(response =&amp;gt; response.text()).then(text =&amp;gt; {&lt;BR /&gt;        try {&lt;BR /&gt;            api.info('Resp length:  ' + text.length);&lt;BR /&gt;            if (text.indexOf('code') &amp;gt;= 0) {&lt;BR /&gt;                &amp;lt;your code to retrieve token&amp;gt;&lt;BR /&gt;                api.setValue("token", token);&lt;BR /&gt;                api.finish();&lt;BR /&gt;            } else {&lt;BR /&gt;                api.fail("Invalid Response");&lt;BR /&gt;            }&lt;BR /&gt;        } catch (err) {&lt;BR /&gt;            api.fail("Failed to Execute");&lt;BR /&gt;        }&lt;BR /&gt;   }).catch(function(error) {&lt;BR /&gt;        api.fail(error); &lt;BR /&gt;   });&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;3. Add a second JavaScript event to pass the value to the OTP generation page&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;var pin = api.getValue("token");&lt;BR /&gt;document.querySelector("#PIN").value = pin;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;4. Complete any other steps needed.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;What's Next&lt;/H2&gt;
&lt;P&gt;If these steps don't help, then open a chat and provide the following:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;a link to affected monitor&lt;/LI&gt;
&lt;LI&gt;the troubleshooting steps you have already completed&lt;/LI&gt;
&lt;LI&gt;a link to this article&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN data-contrast="auto"&gt;What to read next:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN data-ccp-props="{&amp;quot;134233117&amp;quot;:false,&amp;quot;134233118&amp;quot;:false,&amp;quot;335559738&amp;quot;:299,&amp;quot;335559739&amp;quot;:299}"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_0-1768383852504.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31587i53F06683622BF948/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_0-1768383852504.png" alt="HannahM_0-1768383852504.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://community.dynatrace.com/t5/Troubleshooting/Synthetic-Troubleshooting-Map/ta-p/250426" target="_blank" rel="noopener"&gt;Synthetic Troubleshooting Map&lt;/A&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_1-1768383852506.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31588i0CB56DA43C581262/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_1-1768383852506.png" alt="HannahM_1-1768383852506.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://community.dynatrace.com/t5/Troubleshooting/Synthetic-Browser-Monitor-Error-Codes/ta-p/198177" target="_blank" rel="noopener"&gt;Synthetic Browser Monitor Error Codes&lt;BR /&gt;&lt;/A&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_2-1768383967645.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31590iD1E6BC838362E1E8/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_2-1768383967645.png" alt="HannahM_2-1768383967645.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/configure-browser-monitors" target="_blank" rel="noopener"&gt;Configure Browser Monitors&lt;/A&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_3-1768383967646.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31589i8C305760E09675C6/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_3-1768383967646.png" alt="HannahM_3-1768383967646.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/browser-clickpath-events#javascript" target="_blank" rel="noopener"&gt;JavaScript events&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV class="lia-message-template-content-zone"&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_3-1768383967646.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31589i8C305760E09675C6/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_3-1768383967646.png" alt="HannahM_3-1768383967646.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://docs.dynatrace.com/docs/shortlink/synthetic-monitors" target="_blank" rel="noopener"&gt;Dynatrace Synthetic app&lt;/A&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 14 Jan 2026 09:50:39 GMT</pubDate>
    <dc:creator>HannahM</dc:creator>
    <dc:date>2026-01-14T09:50:39Z</dc:date>
    <item>
      <title>How to get a OTP from an API and use it in a Browser Monitor</title>
      <link>https://community.dynatrace.com/t5/Troubleshooting/How-to-get-a-OTP-from-an-API-and-use-it-in-a-Browser-Monitor/ta-p/239746</link>
      <description>&lt;DIV class="lia-message-template-content-zone"&gt;
&lt;P&gt;&lt;EM&gt;Summary:&amp;nbsp;Many applications now require an OTP for authentication. The following steps and snippet can be used to get the OTP from an API and populate it in a page.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;How to get an OTP from an API and use it in a Browser Monitor&lt;/H2&gt;
&lt;P&gt;&lt;SPAN&gt;1.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Create synthetic monitor events up to the point where the one-time password (OTP) is needed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL dir="auto"&gt;
&lt;LI&gt;Navigate to the URL.&lt;/LI&gt;
&lt;LI&gt;login with credentials&lt;/LI&gt;
&lt;LI&gt;The OTP page appears.&lt;/LI&gt;
&lt;LI&gt;Open a page on the same domain as the API URL in a new tab if the original navigation and API domains are different. This step is only necessary if you see a CORS error when making the fetch in the next event.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN&gt;2. Add a JavaScript event, using&amp;nbsp;&lt;STRONG class="sc-bf977b27-0 hNpJEd"&gt;&lt;A href="https://docs.dynatrace.com/docs/platform-modules/digital-experience/synthetic-monitoring/browser-monitors/configure-browser-monitors#recorded-clickpath" target="_self"&gt;Add synthetic event&lt;/A&gt;,&amp;nbsp;&lt;/STRONG&gt;to fetch the OTP value and save the value. Something like the below, which stores the value in a variable called token.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;api.startAsyncSyntheticEvent();&lt;BR /&gt;fetch('&amp;lt;yoururl&amp;gt;', {&lt;BR /&gt;    method: 'POST',&lt;BR /&gt;    headers: {&lt;BR /&gt;        'content-type': 'application/json',&lt;BR /&gt;        'Access-Control-Allow-Origin': '*',&lt;BR /&gt;        'Access-Control-Allow-Headers': 'X-Requested-With'&lt;BR /&gt;    }&lt;BR /&gt;}).then(function(response) {&lt;BR /&gt;        if (!response.ok) {&lt;BR /&gt;            throw Error(response.status + ":" + response.statusText);&lt;BR /&gt;        }&lt;BR /&gt;        return response;&lt;BR /&gt;   }).then(response =&amp;gt; response.text()).then(text =&amp;gt; {&lt;BR /&gt;        try {&lt;BR /&gt;            api.info('Resp length:  ' + text.length);&lt;BR /&gt;            if (text.indexOf('code') &amp;gt;= 0) {&lt;BR /&gt;                &amp;lt;your code to retrieve token&amp;gt;&lt;BR /&gt;                api.setValue("token", token);&lt;BR /&gt;                api.finish();&lt;BR /&gt;            } else {&lt;BR /&gt;                api.fail("Invalid Response");&lt;BR /&gt;            }&lt;BR /&gt;        } catch (err) {&lt;BR /&gt;            api.fail("Failed to Execute");&lt;BR /&gt;        }&lt;BR /&gt;   }).catch(function(error) {&lt;BR /&gt;        api.fail(error); &lt;BR /&gt;   });&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;3. Add a second JavaScript event to pass the value to the OTP generation page&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;var pin = api.getValue("token");&lt;BR /&gt;document.querySelector("#PIN").value = pin;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;4. Complete any other steps needed.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;What's Next&lt;/H2&gt;
&lt;P&gt;If these steps don't help, then open a chat and provide the following:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;a link to affected monitor&lt;/LI&gt;
&lt;LI&gt;the troubleshooting steps you have already completed&lt;/LI&gt;
&lt;LI&gt;a link to this article&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN data-contrast="auto"&gt;What to read next:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN data-ccp-props="{&amp;quot;134233117&amp;quot;:false,&amp;quot;134233118&amp;quot;:false,&amp;quot;335559738&amp;quot;:299,&amp;quot;335559739&amp;quot;:299}"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_0-1768383852504.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31587i53F06683622BF948/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_0-1768383852504.png" alt="HannahM_0-1768383852504.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://community.dynatrace.com/t5/Troubleshooting/Synthetic-Troubleshooting-Map/ta-p/250426" target="_blank" rel="noopener"&gt;Synthetic Troubleshooting Map&lt;/A&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_1-1768383852506.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31588i0CB56DA43C581262/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_1-1768383852506.png" alt="HannahM_1-1768383852506.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://community.dynatrace.com/t5/Troubleshooting/Synthetic-Browser-Monitor-Error-Codes/ta-p/198177" target="_blank" rel="noopener"&gt;Synthetic Browser Monitor Error Codes&lt;BR /&gt;&lt;/A&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_2-1768383967645.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31590iD1E6BC838362E1E8/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_2-1768383967645.png" alt="HannahM_2-1768383967645.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/configure-browser-monitors" target="_blank" rel="noopener"&gt;Configure Browser Monitors&lt;/A&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_3-1768383967646.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31589i8C305760E09675C6/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_3-1768383967646.png" alt="HannahM_3-1768383967646.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/browser-clickpath-events#javascript" target="_blank" rel="noopener"&gt;JavaScript events&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV class="lia-message-template-content-zone"&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HannahM_3-1768383967646.png" style="width: 25px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31589i8C305760E09675C6/image-dimensions/25x25?v=v2" width="25" height="25" role="button" title="HannahM_3-1768383967646.png" alt="HannahM_3-1768383967646.png" /&gt;&lt;/span&gt;&lt;A id="link_6" class="page-link lia-link-navigation lia-custom-event" style="font-family: inherit; background-color: #ffffff;" href="https://docs.dynatrace.com/docs/shortlink/synthetic-monitors" target="_blank" rel="noopener"&gt;Dynatrace Synthetic app&lt;/A&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 14 Jan 2026 09:50:39 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Troubleshooting/How-to-get-a-OTP-from-an-API-and-use-it-in-a-Browser-Monitor/ta-p/239746</guid>
      <dc:creator>HannahM</dc:creator>
      <dc:date>2026-01-14T09:50:39Z</dc:date>
    </item>
  </channel>
</rss>

