{"id":786,"date":"2026-10-12T14:28:40","date_gmt":"2026-10-12T04:28:40","guid":{"rendered":"https:\/\/www.cloudproinc.com.au\/?p=786"},"modified":"2026-10-12T14:28:40","modified_gmt":"2026-10-12T04:28:40","slug":"auto-generate-azure-bearer-token-with-postman","status":"publish","type":"post","link":"https:\/\/www.cloudproinc.com.au\/index.php\/2026\/10\/12\/auto-generate-azure-bearer-token-with-postman\/","title":{"rendered":"Auto-Generate Azure Bearer Token with Postman"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In this Postman and Azure REST API, I will show you how to auto-generate a bearer token for each Azure REST API request with Postman.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-yoast-seo-estimated-reading-time yoast-reading-time__wrapper\"><span class=\"yoast-reading-time__icon\"><svg aria-hidden=\"true\" focusable=\"false\" data-icon=\"clock\" width=\"20\" height=\"20\" fill=\"none\" stroke=\"currentColor\" style=\"display:inline-block;vertical-align:-0.1em\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z\"><\/path><\/svg><\/span><span class=\"yoast-reading-time__spacer\" style=\"display:inline-block;width:1em\"><\/span><span class=\"yoast-reading-time__descriptive-text\">Estimated reading time: <\/span><span class=\"yoast-reading-time__reading-time\">3<\/span><span class=\"yoast-reading-time__time-unit\"> minutes<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Postman API client allows us to develop API requests to many cloud services using an intuitive interface.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When it comes to Azure, We can use the Azure REST API protocol to create and manage any service on Azure using API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In my previous post, I showed how to Create an App Registration for Microsoft Azure REST API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;re familiar with Azure REST API, one of the steps to create an API request is to generate a temporary access token. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Creating an access token is a manual process that must be repeated every hour when the token expires. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, I will show you how to use a Pre-Request script in Postman to auto-generate an access token before sending a request. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-auto-generate-azure-bearer-token-with-postman\">Auto-Generate Azure Bearer Token with Postman<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To auto-generate an access token, I have the following configuration. In my environment, I have the following variables.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"603\" height=\"323\" data-src=\"\/wp-content\/uploads\/2024\/10\/image-21.png\" alt=\"\" class=\"wp-image-787 lazyload\" data-srcset=\"\/wp-content\/uploads\/2024\/10\/image-21.png 603w, \/wp-content\/uploads\/2024\/10\/image-21-300x161.png 300w, \/wp-content\/uploads\/2024\/10\/image-21-480x257.png 480w\" data-sizes=\"(max-width: 603px) 100vw, 603px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 603px; --smush-placeholder-aspect-ratio: 603\/323;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The variable BearerToken needs to be left empty.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have the following JavaScript script on my collection page under the Pre-Request script. Please note that the values in the script need to match the values in the environment variables.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"641\" data-src=\"\/wp-content\/uploads\/2024\/10\/image-22.png\" alt=\"\" class=\"wp-image-788 lazyload\" data-srcset=\"\/wp-content\/uploads\/2024\/10\/image-22.png 1024w, \/wp-content\/uploads\/2024\/10\/image-22-300x188.png 300w, \/wp-content\/uploads\/2024\/10\/image-22-768x481.png 768w, \/wp-content\/uploads\/2024\/10\/image-22-400x250.png 400w, \/wp-content\/uploads\/2024\/10\/image-22-980x613.png 980w, \/wp-content\/uploads\/2024\/10\/image-22-480x300.png 480w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/641;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the script below.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-1\"><code>const tokenExpired = !pm.environment.get(\"bearerToken\") || Date.now() &gt; pm.environment.get(\"bearerTokenExpiresOn\") * 1000;\n\nif (tokenExpired) {\n    const tenantId = pm.environment.get(\"tenantId\");\n    const client_id = pm.environment.get(\"client_id\");\n    const client_secret = pm.environment.get(\"client_secret\");\n    const resource = pm.environment.get(\"resource\") || \"https:\/\/management.azure.com\/\";\n\n    pm.sendRequest({\n        url: `https:\/\/login.microsoftonline.com\/${tenantId}\/oauth2\/token`,\n        method: 'POST',\n        header: { 'Content-Type': 'application\/x-www-form-urlencoded' },\n        body: {\n            mode: 'urlencoded',\n            urlencoded: &#91;\n                { key: \"grant_type\", value: \"client_credentials\" },\n                { key: \"client_id\", value: client_id },\n                { key: \"client_secret\", value: client_secret },\n                { key: \"resource\", value: resource }\n            ]\n        }\n    }, (err, res) =&gt; {\n        if (err) {\n            console.log(err);\n        } else {\n            const { expires_on, access_token } = res.json();\n            pm.environment.set(\"bearerTokenExpiresOn\", expires_on);\n            pm.environment.set(\"bearerToken\", access_token);\n        }\n    });\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To use the auto-generated token in a REST request, set the Auth Type as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"600\" height=\"471\" data-src=\"\/wp-content\/uploads\/2024\/10\/image-23.png\" alt=\"\" class=\"wp-image-789 lazyload\" data-srcset=\"\/wp-content\/uploads\/2024\/10\/image-23.png 600w, \/wp-content\/uploads\/2024\/10\/image-23-300x236.png 300w, \/wp-content\/uploads\/2024\/10\/image-23-480x377.png 480w\" data-sizes=\"(max-width: 600px) 100vw, 600px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 600px; --smush-placeholder-aspect-ratio: 600\/471;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-related-articles\">Related Articles<\/h2>\n\n\n\n<ul class=\"wp-block-yoast-seo-related-links yoast-seo-related-links\">\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2024\/10\/07\/generate-images-with-azure-openai-dall-e-and-postman\/\">Generate Images with Azure OpenAI DALL-E and Postman<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2024\/03\/28\/how-to-add-a-registry-key-to-windows-11-using-microsoft-intune\/\">How to Add a Registry Key to Windows 11 Using Microsoft Intune<\/a><\/li>\n\n\n\n<li><a href=\"null\">Setting Up Azure AI Translator with REST API: Step-by-Step Guide<\/a><\/li>\n\n\n\n<li><a href=\"null\">How to Create an Azure AI Language Account Using REST API<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2024\/10\/07\/generate-dall-e-images-with-net-c-console-application\/\">Generate DALL-E Images with .NET C# Console Application<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Postman and Azure REST API, I will show you how to auto-generate a bearer token for each Azure REST API request with Postman.<\/p>\n","protected":false},"author":1,"featured_media":660,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[16,13,56],"tags":[],"class_list":["post-786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-azure","category-blog","category-postman"],"jetpack-related-posts":[{"id":753,"url":"https:\/\/www.cloudproinc.com.au\/index.php\/2026\/10\/12\/generate-images-with-azure-openai-dall-e-and-postman\/","url_meta":{"origin":786,"position":0},"title":"Generate Images with Azure OpenAI DALL-E and Postman","author":"CPI Staff","date":"October 12, 2026","format":false,"excerpt":"In this Azure OpenAI DALL-E article, we will show you how to generate images with Azure OpenAI DALL-E and Postman. Table of contentsDeploy Resource and AI ModelGenerate Images with Azure OpenAI DALL-E and PostmanRelated Articles Azure OpenAI DALL-E offers the latest text-to-image generation model, DALL-E 3. The model offers advanced\u2026","rel":"","context":"In &quot;Azure OpenAI&quot;","block_context":{"text":"Azure OpenAI","link":"https:\/\/www.cloudproinc.com.au\/index.php\/category\/azure-openai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 1x, \/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 1.5x, \/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 2x, \/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 3x, \/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 4x"},"classes":[]},{"id":791,"url":"https:\/\/www.cloudproinc.com.au\/index.php\/2026\/10\/12\/set-timezone-on-computers-with-microsoft-intune-and-graph-api\/","url_meta":{"origin":786,"position":1},"title":"Set TimeZone on Computers with Microsoft Intune and Graph API","author":"CPI Staff","date":"October 12, 2026","format":false,"excerpt":"In this Microsoft Intune and Graph API post, we will show how to Set TimeZone on computers with Microsoft Intune and Graph API. Estimated reading time: 3 minutes Table of contentsSet TimeZone on Computers with Microsoft Intune and Graph APIPostman POST RequestRequest Body (JSON)Related Articles Microsoft Graph API is a\u2026","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/www.cloudproinc.com.au\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2024\/07\/Deploy-Azure-OpenAI-GPT-4o-Resource-and-Model-using-Bicep.webp","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2024\/07\/Deploy-Azure-OpenAI-GPT-4o-Resource-and-Model-using-Bicep.webp 1x, \/wp-content\/uploads\/2024\/07\/Deploy-Azure-OpenAI-GPT-4o-Resource-and-Model-using-Bicep.webp 1.5x, \/wp-content\/uploads\/2024\/07\/Deploy-Azure-OpenAI-GPT-4o-Resource-and-Model-using-Bicep.webp 2x"},"classes":[]},{"id":417,"url":"https:\/\/www.cloudproinc.com.au\/index.php\/2026\/10\/12\/how-to-use-microsoft-graph-security-api\/","url_meta":{"origin":786,"position":2},"title":"How to Use Microsoft Graph Security API","author":"CPI Staff","date":"October 12, 2026","format":false,"excerpt":"In this Microsoft Defender XDR article, we will show how to use Microsoft Graph Security API using a REST API client and retrieve XDR alerts. Microsoft Defender Extended Detection and Response (XDR) is an enterprise end-to-end security solution that detects, prevents, investigates and responds to security threats from endpoints, users,\u2026","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/www.cloudproinc.com.au\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 1x, \/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 1.5x, \/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 2x, \/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 3x, \/wp-content\/uploads\/2024\/07\/How-to-Use-Microsoft-Graph-Security-API.webp 4x"},"classes":[]},{"id":231,"url":"https:\/\/www.cloudproinc.com.au\/index.php\/2026\/10\/12\/how-to-add-a-registry-key-to-windows-11-using-microsoft-intune\/","url_meta":{"origin":786,"position":3},"title":"How to Add a Registry Key to Windows 11 Using Microsoft Intune","author":"CPI Staff","date":"October 12, 2026","format":false,"excerpt":"In this article, we'll guide you through the process of adding a registry key to Windows 11 utilizing Microsoft Intune. Estimated reading time: 2 minutes Table of contentsListen to articlePowerShell Script:Adding Script to Intune:Related Articles Listen to article As businesses increasingly embrace cloud-based solutions, the necessity for streamlined and centralized\u2026","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/www.cloudproinc.com.au\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2024\/03\/WindowsReg.webp","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2024\/03\/WindowsReg.webp 1x, \/wp-content\/uploads\/2024\/03\/WindowsReg.webp 1.5x, \/wp-content\/uploads\/2024\/03\/WindowsReg.webp 2x"},"classes":[]},{"id":369,"url":"https:\/\/www.cloudproinc.com.au\/index.php\/2026\/10\/12\/list-classic-azure-administrators-using-powershell-and-azure-rest-api\/","url_meta":{"origin":786,"position":4},"title":"List Classic Azure Administrators Using PowerShell and Azure REST API","author":"CPI Staff","date":"October 12, 2026","format":false,"excerpt":"This Microsoft Azure article will show how to list classic Azure Administrators using PowerShell and Azure REST API. As an IT consultancy company that helps companies safeguard their Azure tenant, we perform many tenant assessments. As part of our identity and access review, we always check how many users have\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/www.cloudproinc.com.au\/index.php\/category\/microsoft-azure\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2024\/07\/AzureAdmins.webp","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2024\/07\/AzureAdmins.webp 1x, \/wp-content\/uploads\/2024\/07\/AzureAdmins.webp 1.5x, \/wp-content\/uploads\/2024\/07\/AzureAdmins.webp 2x, \/wp-content\/uploads\/2024\/07\/AzureAdmins.webp 3x, \/wp-content\/uploads\/2024\/07\/AzureAdmins.webp 4x"},"classes":[]},{"id":53555,"url":"https:\/\/www.cloudproinc.com.au\/index.php\/2026\/10\/12\/counting-tokens-using-the-openai-python-sdk\/","url_meta":{"origin":786,"position":5},"title":"Counting Tokens Using the OpenAI Python SDK","author":"CPI Staff","date":"October 12, 2026","format":false,"excerpt":"This post provides a comprehensive guide on counting tokens using the OpenAI Python SDK, covering Python virtual environments, managing your OpenAI API key securely, and the role of the requirements.txt file. In the world of Large Language Models (LLMs) and Artificial Intelligence (AI), the term \"token\" frequently arises. Tokens are\u2026","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/www.cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/07\/image-23.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/07\/image-23.png 1x, \/wp-content\/uploads\/2025\/07\/image-23.png 1.5x, \/wp-content\/uploads\/2025\/07\/image-23.png 2x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"\/wp-content\/uploads\/2024\/09\/Simplifying-Azure-Management-with-GitHub-Copilot-for-Azure.webp","_links":{"self":[{"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=786"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/786\/revisions"}],"predecessor-version":[{"id":790,"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/786\/revisions\/790"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/media\/660"}],"wp:attachment":[{"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}