<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saransh Dhingra</title>
    <description>The latest articles on DEV Community by Saransh Dhingra (@supernova13892).</description>
    <link>https://dev.to/supernova13892</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F492036%2F68efafe1-6f50-47b7-9d34-643ba4e2a58c.jpeg</url>
      <title>DEV Community: Saransh Dhingra</title>
      <link>https://dev.to/supernova13892</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/supernova13892"/>
    <language>en</language>
    <item>
      <title>Postman Monitors - Get a Slack message with the results of your run</title>
      <dc:creator>Saransh Dhingra</dc:creator>
      <pubDate>Sun, 10 Jan 2021 14:35:04 +0000</pubDate>
      <link>https://dev.to/supernova13892/postman-monitors-get-a-slack-message-with-the-results-of-your-run-dk7</link>
      <guid>https://dev.to/supernova13892/postman-monitors-get-a-slack-message-with-the-results-of-your-run-dk7</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;If you don't know how to create Postman Monitors, kindly follow &lt;a href="https://dev.to/supernova13892/postman-monitors-the-hidden-gem-373n"&gt;this post&lt;/a&gt; and continue here.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, last time we created a monitor that checks at regular intervals if our website is up or not.&lt;/p&gt;

&lt;p&gt;But, if you think about it, its usability is limited by the fact that we get to know about it only when we check the past results. I mean you do get emails when your test fails, but that's about it. It's limited and not a lot of customization room exists.&lt;/p&gt;

&lt;p&gt;In this post, we aim to do just that, we want to get a Slack message when our website goes down.&lt;/p&gt;

&lt;p&gt;There are 2 ways to this:&lt;/p&gt;

&lt;h2&gt;
  
  
  The easy way (Postman Integrations):
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Well, as it turns out the team at Postman anticipated that I would someday write this post and they went back in time to create an easy way to do this(&lt;em&gt;Trust me, I won't lie to you&lt;/em&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can use something called &lt;a href="https://learning.postman.com/docs/integrations/available-integrations/slack/"&gt;Integrations&lt;/a&gt; to get Monitor Run Results to your Slack Channel.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you can't find the 'Integrations' tab, then the url looks like this: &lt;code&gt;https://your-workspace-string.postman.co/integrations/browse&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But there are some drawbacks to it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Integrations are available on Postman &lt;strong&gt;Team&lt;/strong&gt;, &lt;strong&gt;Business&lt;/strong&gt;, and &lt;strong&gt;Enterprise&lt;/strong&gt; plans.&lt;/li&gt;
&lt;li&gt;You can't customize it, you'd get all results to your slack channel from now on. Suppose you want to send the Slack message conditionally (&lt;em&gt;say you want to send these details only on alternate days, you'd have to create different monitors&lt;/em&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The hard(&lt;em&gt;pronounced cooler&lt;/em&gt;) way:
&lt;/h2&gt;

&lt;p&gt;Basically, we're going to create a new request in your Postman Collection which will send information to your slack channel. So, just like in the previous method you do have to create a &lt;em&gt;SlackBot&lt;/em&gt; capable of sending messages to your slack channel. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://slack.com/intl/en-in/help/articles/115005265063-Incoming-webhooks-for-Slack"&gt;Check out this article&lt;/a&gt; to create a Slack Bot that has permissions to send a slack message to your channels using a custom webhook.&lt;/p&gt;

&lt;p&gt;Take a note of that webhook URL and save it in a new environment that we would be using for our monitors. Save the URL in a variable named &lt;code&gt;slackWebhook&lt;/code&gt; as seen below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--seZFb_2K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ryb9hd7lw38lj3x7a1vh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--seZFb_2K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ryb9hd7lw38lj3x7a1vh.gif" alt="Create an environment with a variable to store the slack webhook URL"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Create a new request in your collection which will handle sending messages to slack
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bLtSXZmt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/j8cfdfkxexyz18t2b1sj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bLtSXZmt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/j8cfdfkxexyz18t2b1sj.png" alt="Create a new request in your collection which will handle sending messages to slack"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Add details in the URL and body fields.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The request verb should be POST.&lt;/li&gt;
&lt;li&gt;The URL should contain your webhook URL. We use the environment variable which we created earlier.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;TIP: If your current environment is selected properly, your variable names should autocomplete.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1JlyUMFT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wt3sk8s43cvf6yk6ozgj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1JlyUMFT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wt3sk8s43cvf6yk6ozgj.png" alt="Step 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Put the body type as &lt;code&gt;Raw&lt;/code&gt; and select &lt;code&gt;JSON&lt;/code&gt; from the dropdown. Put the content as &lt;code&gt;{"text":"Any awesome text here"}&lt;/code&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--skxYJRth--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/euddnx6l1jr0kpbsxgh8.png" alt="Step 1"&gt;
&lt;/li&gt;
&lt;li&gt;Hit send&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you receive an &lt;code&gt;OK&lt;/code&gt; response, then your webhook URL is setup perfectly. If you receive an error, congrats, you have broken the way Slack/Postman works and you may be eligible for a bounty reward!&lt;br&gt;
JK! Check your environment variables, quotes and other details.&lt;/p&gt;
&lt;h4&gt;
  
  
  3. Make the Slack message contents dynamic.
&lt;/h4&gt;

&lt;p&gt;In the body contents instead of hardcoding the message like we did in the previous step, use something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"text":"{{slackMsg}}"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're basically instructing Postman to receive this value from the environment variables.&lt;/p&gt;

&lt;p&gt;You may be thinking, like my current manager:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Aha!&lt;/strong&gt; You haven't added the variable in the environment but you're using it! You are stupid! (&lt;em&gt;Yes he says that a lot! FML&lt;/em&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well, we aim to generate this text dynamically, so... Awkward!&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Set the Slack response based on the status code.
&lt;/h4&gt;

&lt;p&gt;Go to the &lt;code&gt;Tests&lt;/code&gt; tab of the request which we defined previously(the one that actually hits your URL to be inspected).&lt;/p&gt;

&lt;p&gt;Modify the content of the tab to contain this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Get the status code os the response
let statusCode=pm.response.code;

// Set the contents of the slack message dynamically
pm.environment.set('slackMsg',getSlackMsg(statusCode));

// If the status code was 200, don't send the Slack message
if(statusCode===200){
    postman.setNextRequest(null);
}

// Definition of what message to send on slack
function getSlackMsg(code){
    return code===200 ? 'Everything is awesome!' : 'Uh Oh! There is something fishy with your website!';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me explain what's happening here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First we get the status code and store it in a temp var.&lt;/li&gt;
&lt;li&gt;Now, we call the func &lt;code&gt;getSlackMsg&lt;/code&gt; and get the message to send. You can modify this func to return swear words for your IT admin(&lt;em&gt;Don't do that, that's rude&lt;/em&gt;)!&lt;/li&gt;
&lt;li&gt;In the same instruction, we set this dynamic content into an environment variable which we talked about earlier(&lt;em&gt;Smug Smile&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;In the end we use a trick to terminate the series of requests to be executed using &lt;code&gt;postman.setNextRequest(null);&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;postman.setNextRequest is very helpful in defining the flow of control between multiple requests. Read about it &lt;a href="https://learning.postman.com/docs/running-collections/building-workflows/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  5. Change the environment of your monitor.
&lt;/h4&gt;

&lt;p&gt;Previously, our monitor was using &lt;code&gt;No Environment&lt;/code&gt;, we need to change that, go to our defined monitor and edit it to use our newly created environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CRHfI5iU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yfr8datkzg1eud8z4dkg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CRHfI5iU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yfr8datkzg1eud8z4dkg.gif" alt="Edit monitor environment"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  6. Done. Let's test the heck out of this.
&lt;/h4&gt;

&lt;p&gt;Well, you don't have to wait for the Monitor Run to test this. Simply go to your collection and click &lt;code&gt;Run&lt;/code&gt;, this would emulate how a monitor runs your request(except for IP/machine differences etc).&lt;/p&gt;

&lt;p&gt;If your website is up, you should see only 1 request in the list of requests that ran(remember we only send slack message if something is wrong).&lt;/p&gt;

&lt;p&gt;To emulate that, simply remove that conditional check from the &lt;code&gt;Tests&lt;/code&gt; tab, save the request and re-run the Collection, you should see 2 requests which ran and should also receive a message in the defined slack channel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We got an introduction on how to make decisions in the &lt;code&gt;Tests&lt;/code&gt; tab of the Postman Request. We added dynamic data in our environment which we computed using the response from one of the executed requests. Then we use that dynamic content to send the information to our slack channel which we created for our Slack workspace.&lt;/p&gt;

&lt;p&gt;This was a good introduction to get used to creating custom workflows. We will get into details in this in another post.&lt;/p&gt;

</description>
      <category>postman</category>
      <category>monitoring</category>
      <category>automation</category>
      <category>slack</category>
    </item>
    <item>
      <title>Postman Monitors - The hidden gem</title>
      <dc:creator>Saransh Dhingra</dc:creator>
      <pubDate>Tue, 22 Dec 2020 20:52:53 +0000</pubDate>
      <link>https://dev.to/supernova13892/postman-monitors-the-hidden-gem-373n</link>
      <guid>https://dev.to/supernova13892/postman-monitors-the-hidden-gem-373n</guid>
      <description>&lt;p&gt;Postman is a great tool. I have been using it since it was just a browser extension and really loved the idea of testing my APIs before giving it to the frontend folks.&lt;/p&gt;

&lt;p&gt;It has been a great help while I was learning about APIs and how to create them.&lt;/p&gt;

&lt;p&gt;It has come a long way since then. Now, there are much more things like &lt;code&gt;Mocks&lt;/code&gt;, &lt;code&gt;Monitors&lt;/code&gt; etc (&lt;em&gt;Actually they have been around a while but not the most popular&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;In this post, I would specifically like to highlight how we can use Postman Monitors for some super cool things.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before I begin, I feel obligated to point out that I am a Postman employee, but its not in my job description, nor have I been asked by anyone to write such a post. I do so, with my own free will(&lt;em&gt;like Lucifer wanted us humans to have&lt;/em&gt; :P )&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What are Postman Monitors?
&lt;/h2&gt;

&lt;p&gt;So, monitors in the postman arsenal are in my opinion one of the most powerful weapons, one which we can choose to automate any kind of work(&lt;em&gt;well most of them anyway&lt;/em&gt;).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Want to make sure your website isn't down every few minutes?&lt;/li&gt;
&lt;li&gt;Want to run a series of tests on your APIs on regular intervals?&lt;/li&gt;
&lt;li&gt;Want to be notified when a product is available on Amazon?&lt;/li&gt;
&lt;li&gt;Want to set up a reminder when your favorite crypto reaches a benchmark(Go Litecoin).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It has got you covered!&lt;/p&gt;

&lt;p&gt;Think of monitors as your serverless cron job alternatives, where you can customize &lt;em&gt;what to do&lt;/em&gt;, &lt;em&gt;when to do it&lt;/em&gt;, and &lt;em&gt;what to do after it has been done&lt;/em&gt;!&lt;/p&gt;

&lt;p&gt;I hope you're with me on this weird chain of thought!&lt;/p&gt;

&lt;h2&gt;
  
  
  Enough talk, get to action already!
&lt;/h2&gt;

&lt;p&gt;In this post we'll check how to set up a monitor and do a very basic task of checking if your website is up or not at regular intervals and reporting via email if it is down.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don't worry, we'll cover more awesome things in a future post.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First things first, you need to sign in by visiting &lt;a href="https://www.postman.com/" rel="noopener noreferrer"&gt;https://www.postman.com&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Go to a workspace
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7ah03gqg75twkn2yn8m6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7ah03gqg75twkn2yn8m6.png" alt="Select a workspace"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, all things in Postman reside in a workspace. So, the monitor we will be creating will reside in one of the workspaces you are a part of. Everyone, is a part of &lt;em&gt;their own workspace&lt;/em&gt;(termed &lt;strong&gt;My Workspace&lt;/strong&gt;) or you can create a new Workspace if you want to group your work separately.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Side note: We recently launched Public Workspaces and it is pretty cool, check it out &lt;a href="https://blog.postman.com/public-workspaces-why-we-created-them-what-you-can-do/" rel="noopener noreferrer"&gt;in this blog post&lt;/a&gt; if you wanna know more.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 2: From the left sidebar, select collections and create one and add a request to it.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjcicdx4u219l4cmo6ke0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjcicdx4u219l4cmo6ke0.png" alt="Create a collection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fszlycrcr0l6hnra4jczs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fszlycrcr0l6hnra4jczs.png" alt="Add a request to your collection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Add details about your webpage.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fousqrbexrkchg4lln8du.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fousqrbexrkchg4lln8du.png" alt="Add request details to your request"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, I will be sending a &lt;code&gt;GET&lt;/code&gt; request to &lt;a href="https://saranshdhingra.dev" rel="noopener noreferrer"&gt;https://saranshdhingra.dev&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Yes, this is a shameless attempt to advertise my portfolio website. I feel terrible, so if you could just visit the website, leave awesome feedback and read the rest of the article, I'll be on my way :D&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In order to test it you can quickly send the request to see if everything works.&lt;/p&gt;

&lt;p&gt;You should get a &lt;code&gt;200&lt;/code&gt; status code response if your webpage is up and configured properly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that in order to run the request from the web and not the app, you may need to select the &lt;code&gt;Desktop Agent&lt;/code&gt; to avoid &lt;code&gt;CORS&lt;/code&gt; issues. If your website is configured to allow all &lt;code&gt;Cross Origin Requests&lt;/code&gt; then you may not need this. You can select the agent in the bottom right section of the page.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fon37cskpva9vx55sfvi1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fon37cskpva9vx55sfvi1.png" alt="Select the proper Postman Agent"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Add a testing mechanism
&lt;/h3&gt;

&lt;p&gt;We have set up how to send a request to our webpage, but how do we know if everything works perfectly. We want to automate the whole process after all!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Enter the &lt;strong&gt;Tests&lt;/strong&gt; tab.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just below the bar where you entered your webpage address you may see a lot of tabs, one of them will be the &lt;code&gt;Tests&lt;/code&gt; tab. When selected it looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4b5nj2mrrxv32hq87z3f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4b5nj2mrrxv32hq87z3f.png" alt="Postman Tests tab"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is another tool in the &lt;em&gt;Postman arsenal&lt;/em&gt; which I think is very powerful.&lt;/p&gt;

&lt;p&gt;Think of this tab as a hook that runs after the request runs. So you can do all sorts of things with this, things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Getting the response body and parsing content.&lt;/li&gt;
&lt;li&gt;Take some dynamic content and initiate another request based on that(&lt;em&gt;we'll do this sometime later&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;Check the status code of the response received(&lt;em&gt;Bingo!&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, in order to test if our website is working fine, every time we run our request, we'll be checking if the &lt;code&gt;response code is equal to 200&lt;/code&gt; or not.&lt;/p&gt;

&lt;p&gt;This is how we do that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pm.test("Check Status code of my website", function () {
    pm.response.to.have.status(200);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, put this in the &lt;code&gt;Tests&lt;/code&gt; tab and &lt;code&gt;Run&lt;/code&gt; the request. You should see that your test passed(check it in the &lt;code&gt;Test Results&lt;/code&gt; tab in the response section).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzpososgsnslo4xgcij1y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzpososgsnslo4xgcij1y.png" alt="Test Results in postman"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Try changing the status code in the test temporarily and running the request again to see how it behaves when the test fails.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Save the request, and now we can move to the monitors part of the tutorial&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Create a monitor for your collection
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F46jz8xhpo4ls7c1fhbcb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F46jz8xhpo4ls7c1fhbcb.png" alt="Create a monitor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the left sidebar, select &lt;code&gt;Monitors&lt;/code&gt; and &lt;code&gt;Create a Monitor&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter a meaningful name for your monitor.&lt;/li&gt;
&lt;li&gt;Select the collection that we created earlier.&lt;/li&gt;
&lt;li&gt;For now, you can keep the Version as &lt;code&gt;CURRENT&lt;/code&gt;, and Environment as &lt;code&gt;No Environment&lt;/code&gt;, we'll use them in future tutorials.&lt;/li&gt;
&lt;li&gt;Select the desired frequency. For a normal, portfolio-like website an hourly frequency should suffice.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Please note that if your monitoring calls have a quota, you get 1000 monitoring calls free every month. You can check your current usage by going into the &lt;code&gt;Resource Usage&lt;/code&gt; page.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuzq1j55tbo8yd5gdjznb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuzq1j55tbo8yd5gdjznb.png" alt="Monitoring usage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The options should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs2ht2men8grehvzlfyzz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs2ht2men8grehvzlfyzz.png" alt="Set monitoring options"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional Options:&lt;/strong&gt;&lt;br&gt;
You can set some additional options for more granular control over your requests.&lt;/p&gt;

&lt;p&gt;For example, you can send the requests from &lt;strong&gt;multiple regions&lt;/strong&gt; that ensures your website behaves similarly in different regions.&lt;/p&gt;

&lt;p&gt;A very important option is to have an email sent to you whenever a Test fails on your monitor run.&lt;/p&gt;

&lt;p&gt;So, if your website returns with a &lt;code&gt;non 200 status code&lt;/code&gt;, you can get an email for the same.&lt;/p&gt;

&lt;p&gt;We'll talk about cooler delivery methods in a future tutorial, but for now, let's select that.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frp61k1i474a1vizl4a7t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frp61k1i474a1vizl4a7t.png" alt="Additional options while creating a monitor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Run your monitor
&lt;/h3&gt;

&lt;p&gt;You can either wait for your monitors to run at their designated time or &lt;code&gt;Run&lt;/code&gt; them manually for testing. After running them, you see the records of individual instances when you had &lt;em&gt;requested/scheduled&lt;/em&gt; the monitor to run.&lt;/p&gt;

&lt;p&gt;By clicking on a specific bar, you can see more details about the requests and the test results.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftwk1aicz6isglstimgrd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftwk1aicz6isglstimgrd.png" alt="Postman monitor Run results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So, we created a collection, set up a test that checks for a deciding criteria to know whether the website is up or not, and then automated the whole process to run at scheduled intervals.&lt;/p&gt;

&lt;p&gt;I don't know about you, but I was very thrilled the first time I did this. I could imagine so many possibilities to achieve things that I needed to automate. Things that I knew how to achieve in code, but this was a whole other domain, no need to manage &lt;code&gt;crons&lt;/code&gt;, no need to manage servers, and all from a tool that I use to test my APIs already.&lt;/p&gt;

&lt;p&gt;Right now this is just a basic run through of a part of the product, but we'll get into more details, and we'll try to achieve something cool every time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stick with me, and you'll find Zen!&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Actually no, I'm finding that myself, send me a link when you find it :P&lt;/em&gt;&lt;/p&gt;

</description>
      <category>postman</category>
      <category>monitoring</category>
      <category>automation</category>
    </item>
  </channel>
</rss>
