# Post Execution Script Question

**URL:** <https://community.dynatrace.com/t/post-execution-script-question/39699>\
**Category:** Dynatrace API\
**Tags:** dynatrace-api\
**Created:** [May 11, 2023, 3:40pm UTC](https://community.dynatrace.com/t/post-execution-script-question/39699 "2023-05-11T15:40:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GregOReilly](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gregoreilly/32/27713_2.png) [@GregOReilly](https://community.dynatrace.com/u/GregOReilly)\
**Post date:** [May 11, 2023, 3:40pm UTC](https://community.dynatrace.com/t/post-execution-script-question/39699/1 "2023-05-11T15:40:53Z")

</div>

Hello community,

I am needing to test an API and WITE Data to record. (Its a test record in our production env). Doing this is fine, however, the next time I run the same test, I get an error that the data exists.

Can I add a post execution script to validate that the data was correctly added (read the response) and then run a 2nd http api test to delete the data we just added. If the data was not written, I do not want to run the 2nd script, but send an alert instead. (want to avoid repearing failures over and over on a production record)

This proved that my API’s are available, working, writing, deleting etc.

There are 20-30 different scenarios we need this to take place as the majority of the services we interact with are SaaS and we have no records of logs/events to tell us when something breaks.

Your help is appreciated.

Greg

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [May 11, 2023, 5:24pm UTC](https://community.dynatrace.com/t/post-execution-script-question/39699/2 "2023-05-11T17:24:27Z")

</div>

In theory, yes, you can.

You can code a javascript to read the response from the POST (response.getResponseBody()) and work with conditions (if|else) to plan the next event as a Delete, or to skip it with [api.skipNextRequest()](https://www.dynatrace.com/support/help/platform-modules/digital-experience/synthetic-monitoring/http-monitors/pre-and-post-scripting-for-http-monitors#skip-http-requests%20). You can force an alert with api.fail().

Please try the [apis for HTTP Monitor](https://www.dynatrace.com/support/help/platform-modules/digital-experience/synthetic-monitoring/http-monitors/pre-and-post-scripting-for-http-monitors#methods), and let us know.

---

<div class="post-metadata">

**Author:** ![GregOReilly](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gregoreilly/32/27713_2.png) [@GregOReilly](https://community.dynatrace.com/u/GregOReilly)\
**Post date:** [May 11, 2023, 5:57pm UTC](https://community.dynatrace.com/t/post-execution-script-question/39699/3 "2023-05-11T17:57:33Z")

</div>

Thanks, I’ll try that and report back.
