Collection sharing in Postman - Build an Automation Script
import requests # Set variables postman_api_key = 'YOUR_POSTMAN_API_KEY' collection_uid = 'YOUR_COLLECTION_UID' team_member_email = 'teammember@example.com' headers = { 'X-Api-Key': postman_api_key, 'Content-Type': 'application/json' } # Step 1: Get current collection details collection_url = f'https://api.getpostman.com/collections/{collection_uid}' response = requests.get(collection_url, headers=headers) response.raise_for_status() collection_data = response.json() # Step 2: Share collection with team member share_url = f'https://api.getpostman.com/collections/{collection_uid}/share' payload = { "sharedWith": [ { "email": team_member_email, "permission": "edit" } ] } share_response = requests.post(share_url, headers=headers, json=payload) share_response.raise_for_status() # Step 3: Verify sharing verify_response = requests.get(collection_url, headers=headers) verify_response.raise_for_status() shared_with = verify_response.json().get('collection', {}).get('sharedWith', []) assert any(user.get('email') == team_member_email and user.get('permission') == 'edit' for user in shared_with), "Collection not shared correctly" print('Test Passed: Collection shared with team member with edit permission.')
This script uses the Postman API to automate sharing a collection.
First, it fetches the collection details to confirm the collection exists.
Then, it sends a POST request to share the collection with the specified team member email and sets permission to 'edit'.
Finally, it verifies by fetching the collection details again and checking if the team member is listed with the correct permission.
Assertions ensure the sharing was successful. Using environment variables for keys and IDs keeps the script flexible and secure.
Now add data-driven testing to share the collection with 3 different team member emails and permissions
Practice
What is the main purpose of Collection sharing in Postman?
Solution
Step 1: Understand the concept of collection sharing
Collection sharing is designed to help teams collaborate by giving access to the same set of API requests.Step 2: Identify the main purpose
The main goal is to let team members work together easily on the same collection.Final Answer:
To allow team members to access and work on the same API requests easily -> Option AQuick Check:
Collection sharing = team collaboration [OK]
- Thinking sharing creates new APIs
- Confusing sharing with deleting collections
- Believing sharing only runs tests locally
Which of the following is a valid way to share a Postman collection?
Solution
Step 1: Review sharing methods in Postman
Postman allows sharing collections by exporting files, sharing in workspaces, or using public links.Step 2: Confirm all methods are valid
Each method suits different collaboration needs, so all are valid ways.Final Answer:
All of the above methods are valid -> Option BQuick Check:
Export + workspace + link = all valid [OK]
- Choosing only one sharing method
- Ignoring public link sharing
- Confusing export with import
What will happen if you share a collection via a workspace in Postman?
Solution
Step 1: Understand workspace sharing in Postman
Sharing a collection in a workspace allows all workspace members to access and collaborate on it.Step 2: Identify access rights
Members can view and edit the collection, enabling teamwork.Final Answer:
Team members in the workspace can access and edit the collection -> Option AQuick Check:
Workspace sharing = team access and edit [OK]
- Thinking only owner can access
- Believing collection is deleted after sharing
- Assuming collection is read-only
You tried to share a collection via a public link, but your teammates cannot access it. What is the most likely reason?
Solution
Step 1: Check the sharing method used
If teammates cannot access via public link, the link might be wrong or missing.Step 2: Rule out other causes
Public link sharing is supported, and workspace sharing is different. Deletion would prevent all access.Final Answer:
The link was not generated or copied correctly -> Option CQuick Check:
Wrong or missing link = access denied [OK]
- Assuming public link sharing is unsupported
- Confusing workspace sharing with link sharing
- Ignoring link copy errors
You want to share a collection with a team that has mixed access needs: some should edit, others only view. Which sharing method best fits this requirement?
Solution
Step 1: Analyze sharing needs
Mixed access means some users can edit, others only view.Step 2: Identify sharing method supporting roles
Workspaces in Postman support role-based access control, allowing this setup.Step 3: Rule out other methods
Public links usually have uniform access; exporting or manual copying lacks access control.Final Answer:
Share the collection in a workspace with role-based access -> Option DQuick Check:
Workspace + roles = mixed access control [OK]
- Using public links without access control
- Emailing exports causes version mismatch
- Copying requests manually is inefficient
Ready to prove it?
Pass the test and this pattern moves unknown
