question

Antonio S. avatar image
Antonio S. asked ·

How to do a POST event in Synthetic Browser monitoring?

I'm trying to do a simple synthetic browser monitoring script, that does a POST request with some data. I have been struggling for more than an hour to find how to do such basic functionality, but seems it's better to seek some help here... Any clue?

synthetic monitoring
10 |2000000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 50.0 MiB each and 250.0 MiB total.

Hannah M. avatar image
Hannah M. answered ·

How are you doing this? I've seen it work in Browser Clickpaths using fetch.

The first event has to be a Navigate in Clickpaths though, so you can only do this as a later event.

8 comments Share
10 |2000000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 50.0 MiB each and 250.0 MiB total.

Not sure what "fetch" you are referring to?

Yes, the Navigate is the first. After that I have the following options:

Navigate seems the only option that could support a POST, but it is very limited in what we can do:

0 Likes 0 · ·
1596464600805.png (25.5 KiB)
1596464737140.png (20.1 KiB)
Chad T. avatar image Chad T. Antonio S. ·

Why are you adding it manually? its much easier if you add the chrome extension, then record your click path via the new browser window and access your www.<ApiEndPoint>.com and post the json payload.

1 Like 1 · ·

Yes, I normally use the Chrome extension, but in this specific case, it can't be done :-(

Now I understand how you did it :-)

BTW, this is not a POST to an API. It is a specific POST in a login situation...

I'll probably have to go the Javascript route...

0 Likes 0 · ·
Chad T. avatar image Chad T. Antonio S. ·

ahh okay, id be interested if you can still be able to get it working via the click path set up - keep us in the loop how it goes.! you can always also create the Synthetic via in a Json then pass it into Dynatrace and have it create it.

1 Like 1 · ·
Hannah M. avatar image Hannah M. ♦ Antonio S. ·

Apologies, I should have mentioned that it's a 'fetch' in JavaScript event that is required to do this.

1 Like 1 · ·
Hannah M. avatar image Hannah M. ♦ Hannah M. ♦ ·

You'll want something like this:

api.startAsyncSyntheticEvent(); 
fetch('<yourRequest>', {
    method: 'POST',
    headers: {
        'content-type': 'application/json'},
    body: '<yourBody>'
}).then(response => response.text()).then(text => {
    try {
        api.info('Success');
        api.finish();
        } else {
            api.fail("Invalid Response");
        }
    } catch (err) {
        api.fail("Failed to Execute");
    } }); 
2 Likes 2 · ·
Antonio S. avatar image Antonio S. Hannah M. ♦ ·

Thanks Hannah,

I'm finally done, but didn't use the POST after all, because there were Javascript tricks, so I had to reverse engineer the HTML/Javascript code, and in the ending it was quite easier than I would have thought.

What seems could be a limitation around the few options available in Dynatrace, is easily worked around with Javascript :-)

2 Likes 2 · ·
Chad T. avatar image Chad T. Antonio S. ·

Great Team Work!

1 Like 1 · ·
Chad T. avatar image
Chad T. answered ·

@Antonio S. i was just able to create a synthetic monitor click path that goes to the Dynatrace Config API and creates a managment zone, and then deletes it. Where are you running into a snag?

3 comments Share
10 |2000000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 50.0 MiB each and 250.0 MiB total.

It must be because it's late Friday night here ;-)

I have looked at the available browser clickpath events,

https://www.dynatrace.com/support/help/how-to-use-dynatrace/synthetic-monitoring/browser-monitors/browser-clickpath-events/

but there seems to be no way of making a POST, namely with the "navigate" event.

It does seem to be possible to do it with the HTTP monitors, but not with the browser monitors, which was the one I referenced...

1 Like 1 · ·

@Chad T.,

Can you confirm please what type of synthetic monitor you used? Just to be sure it was not the browser clickpath?

0 Likes 0 · ·
Chad T. avatar image Chad T. Antonio S. ·

I did use the click path to do the post - I did not run into any issues with that - I dont think you can do it via the basic browser monitor as how would you input the Json payload.

0 Likes 0 · ·