<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dias on Medium]]></title>
        <description><![CDATA[Stories by Dias on Medium]]></description>
        <link>https://medium.com/@diastaufik?source=rss-9f7582d393c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*eEfhqXAYW4piejnkOUJkwg.png</url>
            <title>Stories by Dias on Medium</title>
            <link>https://medium.com/@diastaufik?source=rss-9f7582d393c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:55:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@diastaufik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Automate Authorization Token Header for Postman Request]]></title>
            <link>https://medium.com/@diastaufik/how-to-automate-authorization-token-header-for-postman-request-69b2ce78b075?source=rss-9f7582d393c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/69b2ce78b075</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[postman]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Dias]]></dc:creator>
            <pubDate>Sun, 29 Mar 2020 10:54:15 GMT</pubDate>
            <atom:updated>2020-06-23T05:31:12.404Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*53q7m0OSYSaCZd0Q" /><figcaption>Photo by <a href="https://unsplash.com/@grohsfabian?utm_source=medium&amp;utm_medium=referral">Fabian Grohs</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hi guys.. this is my first story on Medium, pardon for my bad English, i’ll always improve my english skills xD</p><p>I always use Postman for testing an API if it’s works as expected or not. But sometimes it’s painful when you forgot to refresh Authorization token and get message like ‘<strong><em>Expired token</em></strong>’ from API response and need to switch between postman tabs to generate new Authorization token and back to current tab for paste new token, not efficient, right ?</p><p>So.. i’m start digging to Postman documentation and search about how to create event that fired before request send, and i found <strong>Pre-Request Scripts</strong> feature on Postman.</p><blockquote>Pre-request scripts are snippets of code associated with a collection request that are executed before the request is sent. This is perfect for use-cases like including the timestamp in the request headers or sending a random alphanumeric string in the URL parameters.<br>[Pre-request scripts] (<a href="https://learning.postman.com/docs/postman/scripts/pre-request-scripts/">https://learning.postman.com/docs/postman/scripts/pre-request-scripts/</a>)</blockquote><p>Yipeee!!! We can set headers automatically before sending request, <strong>FYI</strong><br>pre-request scripts are written in Javascript and it’s not a big deal since it’s not hard to write simple http request on Javascript.<br>Before we start, i will use Postman variables feature to store value on collection scope, so here we go..</p><h3>Step 1 — Create global variable</h3><p>We need to ‘save’ token information so we can use it from anywhere.<br>Create 2 variables : <br>1. <strong>expiryTime</strong><br>2. <strong>activeToken</strong><br>I’m create my variable on collection scope</p><ul><li>Click three dots on your collection</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*YQDo26F2uKSxy59KI0EToQ.png" /><figcaption>Click three dots to show advanced collection menus</figcaption></figure><ul><li>Click <strong>Variables</strong> tab and fill the form</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*vdsRHMnVA31J18LY2FOE7Q.png" /><figcaption>Postman variable form</figcaption></figure><h3>Step 2 — Create simple pre-request scripts</h3><p>Open Pre-Request Scripts tabs and write this codes</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b71e79676b66c2711b58ed6e37547fd9/href">https://medium.com/media/b71e79676b66c2711b58ed6e37547fd9/href</a></iframe><p>A few notes :<br>- Postman have built in function, on example you’ll find function <strong>pm.environment.set </strong>and <strong>pm.environment.get</strong>, if you need more information, you can check to official Postman documentation. You can modify body payload to fit your API needs.</p><h3>Step 3 — Use auto generated token for authorization</h3><p>After we create pre-request scripts, we need to implement token for whole collection.<br>Open <strong>Authorization </strong>tab and fill empty token field with <strong>{{activeToken}} </strong>it means we use variable that previously have been filled with token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*99aHBvGeFve29uYlb8L14A.png" /><figcaption>Authorization tab</figcaption></figure><h3>Step 4 — Implement token</h3><p>In previous step we’ve done for setting up auto generate token, and this is final step to implement it. Open your Request under same collection as we setup before and go to <strong>Authorization </strong>tab, on <strong>Type</strong> field select <strong>Inherit Auth From Parent</strong>, congrats you’re done!</p><p>For now, every request you made, it will fire pre-request scripts. If you want to see where <strong>console.log</strong> command print the content, it will printed on Postman Console. Click terminal icon on bottom bar Postman</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*n530itywO5u4dOxEV8wKxQ.png" /><figcaption>Postman Console</figcaption></figure><p>Console form will showed up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*Z3YU_0l-F9h0-N0ASzrcag.png" /><figcaption>Postman Console</figcaption></figure><p>I hope it will boost your workflow to be more efficient.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69b2ce78b075" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>