Import Swagger file in a shared workspace with API

Hi everyone,

I want to subscribe to the pro version of Postman but somethings is getting on the way.

With my application, I generate a swagger file in json that I can successfully import with the API (https://docs.api.getpostman.com/?version=latest#09886971-e1e2-4a62-8f59-f7abfd79ff5e) in my personnal workspace, but I want to share the new import collection in a shared workspace using the API. It is important that everything will be done with the API, because I want the operation to be automatic in the CI.

I try to put the url parameter ?workspace={workspace_id} but without success.

Do you have any idea?

Thank you in advance.

Adrien

HI @adrien,

Great question! So using the URL parameter won’t work, because their API specification doesn’t seem to allow it.

However, I just did some research and thought of this.

To share the the newly imported collection, get the collection ID, do a PUT on the workspace, and insert that collection ID into the body of the PUT call, and that may then share the collection with that team/shared workspace.

https://docs.api.getpostman.com/?_ga=2.40496162.122951159.1572644688-77696017.1572375204&version=latest#34edebd3-8a53-4927-8ed6-4874a298c2e3

curl --location --request PUT "https://api.getpostman.com/workspaces/{{SHARED_workspace_id}}" \
  --header "x-api-key: " \
  --header "Content-Type: application/json" \
  --data "{
\"workspace\": {
    \"name\": \"New Workspace updated\",
    \"type\": \"personal\",
    \"description\": \"Some description\",
    \"collections\": [
        {
            \"id\": \"{{YOUR_NEW_COLLECTION_ID}}",
            \"name\": \"COLLECTION NAME\",
            \"uid\": \"{{USER_ID}}-{{YOUR_NEW_COLLECTION_ID}}"
        }
    ],
    \"environments\": [
        {
            \"id\": \"83a1aaa2-a204-4bd8-9b92-4d486918906b\",
            \"name\": \"env\",
            \"uid\": \"8154-83a1aaa2-a204-4bd8-9b92-4d486918906b\"
        }
    ],
    \"mocks\": [
        {
            \"id\": \"cda672ef-1375-40e9-baee-e20ece8d7b65\"
        }
    ],
    \"monitors\": [
        {
            \"id\": \"1e889bd2-3862-4be0-b2c2-9b1fe9673aec\"
        }
    ]
}
}"

I have not tried this and do not know if it would work, but feel free to give it a shot.

I hope it works!

Regards,
Orest

This is even better than creating a new collection each time I import a swagger file, because I can keep all by the collection preferences that are only available manually, like publishing.

Thank you very much.

1 Like

Hi @adrien,

You’re welcome! I’m glad this helps and gives you the functionality you need, and then some.

All the best,
Orest