Adventures with Azure API Management: Shared Headers and Postman

API Management

I use Postman for testing my API calls to Azure API Management.

In each of my requests I need to pass a Ocp-Apim-Subscription-Key header. In this header I provide my subscription key for my API provided by Azure API Management.

Normally I would do this for each request.

Postman Request Headers

What if I need to change the subscription key? I would have to change it in each and every request.

This would become quite tedious for an Api with a lot of operations.

One thing I could do would be to store the Ocp-Apim-Subscription-Key in an environment variable.

Environment and Variables

I can assign the environment variable as the value for the Ocp-Apim-Subscription-Key header.

Now if I need to change I can do it in one spot.

Better.

When I need to request a new request for a different operation I usually duplicate a previous operation to I don’t have to keep adding the headers for Ocp-Api-Subscription-Key and Ocp-Apim-Trace.

This does not feel right.

Seems like a lot of duplication.

Be nice if I could just apply global headers to all request within a folder, as opposed to each request.

Collection Folders

To do this, click the ellipses next to the folder you want to share headers for contained requests, and select Edit, in my case, I clicked the ellipses next to the Azure folder.

Click the Pre-request Scripts tab.

Paste the following code into the Pre-request scripts.

Note, you can still use the environmental variable we created in the previous step.

Folder Pre-request Scripts

Click Update.

For any requests executed in the folder, the headers for Ocp-Apim-Subscription-Key and Ocp-Apim-Trace will be added.

Leave a Reply

Your email address will not be published. Required fields are marked *