How can I provide and set initial values for the collection variables from test and pre-request scripts so they are configured during run time? I want to do this at the collection level, and change the initial values during runtime not their current values. Because when I export a collection the current values are not exported.
As you have found out already, the .set() will only update the current value. This is to prevent inadvertently syncing sensitive data like api keys or tokens.
Hi Danny,
I will be triggering the postman API every 3 hours from azure by exporting Postman collection. Using Postman API would be most suitable for me in this case.
How can I update the collection using PostmanAPI? Any blogs or examples on this? There are postman blogs on updating the environment and using that to persist values. Guide on How to Persist Postman Variables | Postman Blog
Are these the same things?
Depending on the plan that you’re on, there are limits placed on how many calls that can be made to the Postman API within a month. Worth checking to see if that will cover your use case first.
You can get your full Collection JSON using this GET Collection endpoint and the response will be required to update the Collection with the new initial variable values.
Using the PUT Collection endpoint, you can use the Collection JSON as the request body and amend the variable value in the structure to set the initial state.
You will need to ensure that the full Collection JSON is passed in the request when updating or this will replace the whole Collection with what it sent.
After talking to the team, I realised I gave you the wrong method of doing this.
Using the PATCH /collections/id endpoint is the correct way of doing this and you would only need to pass in the variable information and not the whole collection.
the values of the collection variables ID and alertIDnow are in the current values. I am trying to get them into the initial value. I got the above response from running the first script.
I have taken the above steps as recommended and my collection is working on postman as expected.
But how can I confirm that initial values are being set? I cannot see the values being updated to the initial value column for collection variables ID and alertIDnow. The initial value is still empty and i believe that even after taking the recommended steps my Postman collection is still running only on current values, as previously.
The Patch request is working. All the scripts and everything is working as per the recommendations above yet the initial value is not being updated for collection variables.
I am doing this as I am importing the Postman collection onto Azure logic app. I have been told that Azure picks on the initial values for collection variables hence i need initial values to show up. And with the present configurations azure is still not getting collection variable values.