You can use the fetch from herehttps://www.dynatrace.com/support/help/how-to-use-dynatrace/synthetic-monitoring/browser-monitors/browser-clickpath-events?_ga=2.7450162.1463168231.1647250461-719377197.1594986249#expand–example-2-get-a-random-first-name-last-name-from-an-api-endpoint-and-set-it-during-a-sign-up-process–4 to get your token. If you need to add headers, you could do it like this:
api.startAsyncSyntheticEvent();
fetch('<yoururl>', {
method: 'POST',
headers: {
'content-type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'X-Requested-With'
}
}).then(function(response) {
if (!response.ok) {
throw Error(response.status + ":" + response.statusText);
}
return response;
}).then(response => response.text()).then(text => {
try {
api.info('Resp length: ' + text.length);
if (text.indexOf('code') >= 0) {
<your code to retrieve token>
api.setValue("token", token);
api.finish();
} else {
api.fail("Invalid Response");
}
} catch (err) {
api.fail("Failed to Execute");
}
}).catch(function(error) {
api.fail(error);
});
You can then use the variable token later, either by calling api.getValue(token) in a javaScript event or {token} in a field. More info here