Best practice to get pm variable value through cURL

Your question may already have an answer on the Postman Community Forum. Please search for related topics to avoid duplication. :pray:

Please read through these guidelines before creating a new topic.

Here’s some information to include when creating your question:

  • Descriptive Title: Write a title that summarizes the specific problem, this shouldn’t be the same as the full question.
  • Introduce The Question: Explain how you encountered the problem you’re trying to solve and the steps you’ve taken to resolve the issue.
  • Additional Data: Include additional data that might help someone reproduce your issue - for example, code, collections, data dumps, console errors, screenshots or gifs. Ensure all code snippets are placed within a code block.
  • Platform Details: Which Postman App, Web Platform, and Operating System version you are using. You can see this in under Settings → About.
  • Tags: Add up to 5 tags so people can search for answers to similar questions.

:no_entry: Do NOT include sensitive information like auth tokens or passwords.

Is Postman API or Postman Echo (or another API) the way to get the value of a Postman variable through PHP cURL? I need to share a token that refreshes 3 times a day among many Web apps. Tried Postman API and Postman Echo but the cURL response is parsing as {{variable}} instead of its value. Works in Postman but not in Web apps.

Postman Echo just echoes back what you sent it, so pretty sure you can rule that out of the equation.

You haven’t mentioned how the variable is stored in Postman.

If its in the current values, then you can’t access this via the Postman Collection API, as only initial value are available through that method.

If you want to share a token, then you really need another mechanism for this as Postman isn’t designed to store confidential information that needs to be shared between hosts\clients\users. (Hence the reason that the current values are not synced to the Postman Cloud or included when you export Environments).

You need a central location, something like a key vault to store the information, and then pull from that location.

The mechanism to refresh the token, will need to update that central location.

As it refreshes three times a day, it sounds like you want to automate this process as much as possible.

Most Key vaults will have an API of some sort, so you can pull the information into Postman that way.

This can either be a full request or a pre-request script to retrieve the value and then store it as an environment variable to be used in subsequent requests.

If the refresh windows wasn’t 3 times a day, the usual advice would be to just copy and paste the values from the key vault when needed locally. You would only automate it in your continuous integration pipelines, where one of the first tasks in the pipeline would be to retrieve the current value and then send this in the Newman command line. It would be automated at that point.

You still need the mechanism outside of the pipeline to refresh the token (or create a pipeline to do the refresh).

Your web apps would need their own mechanism (like cURL).

The only problem I have with the above concept is if you use the Azure Key Vault. To access to Key Vault via the API, it has its own application secrets which is confidential information that should be stored in a Key Vault. So its a bit Chicken and Egg. Where do you store the application secrets to access the Key Vault. (Answers on a Postcard please, as this sort of defeats the purpose of the Key Vault).

When you access the Key Vault through the pipeline, it uses the Service Principal instead (and because we use Azure Pipelines with Azure Keyvaults, that part is fairly seamless).

Thanks Mike!

Great response. I was afraid this was the case. But, appreciate the thorough feedback just the same.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.