# Generate Swagger from Postman Collection

**URL:** <https://community.postman.com/t/generate-swagger-from-postman-collection/63894>\
**Category:** Help Hub\
**Tags:** collections, json\
**Created:** [July 10, 2024, 7:48am UTC](https://community.postman.com/t/generate-swagger-from-postman-collection/63894 "2024-07-10T07:48:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![altimetry-astronaut](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@altimetry-astronaut](https://community.postman.com/u/altimetry-astronaut)\
**Post date:** [July 10, 2024, 7:48am UTC](https://community.postman.com/t/generate-swagger-from-postman-collection/63894/1 "2024-07-10T07:48:39Z")

</div>

I’m trying to generate a swagger json from a collection but everytime i try to “send” the following URL: [https://api.getpostman.com/collections/:collection\_id](https://api.getpostman.com/collections/:collection_id) , i have alway this response :

```auto
{
    "error": {
        "name": "forbiddenError",
        "message": "You are not permitted to perform the action."
    }
}

```

Someone know why ? i mean i have the collection id from a collection in my space , is a problem of visibility ?

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [July 10, 2024, 10:08am UTC](https://community.postman.com/t/generate-swagger-from-postman-collection/63894/2 "2024-07-10T10:08:55Z")

</div>

You need to include an API key when targeting the collections endpoint.

There are a couple of methods for doing this that are covered in day 4 (Authorization) in the 15 days of postman training.

[https://www.postman.com/postman/workspace/15-days-of-postman-for-testers/](https://www.postman.com/postman/workspace/15-days-of-postman-for-testers/)

---

<div class="post-metadata">

**Author:** ![altimetry-astronaut](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@altimetry-astronaut](https://community.postman.com/u/altimetry-astronaut)\
**Post date:** [July 10, 2024, 11:11am UTC](https://community.postman.com/t/generate-swagger-from-postman-collection/63894/3 "2024-07-10T11:11:39Z")

</div>

Hi @michaelderekjones ,

with API key you mean to add the X-API-Key ?  
i followed this guide [Postman](https://www.postman.com/postman/workspace/postman-public-workspace/documentation/23020434-a7823a90-2517-4d89-ad02-c37b9d4b4b4f) where i genereta the value for the API key X-API-Key

or you mean something else ?

Thanks

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [July 10, 2024, 11:59am UTC](https://community.postman.com/t/generate-swagger-from-postman-collection/63894/4 "2024-07-10T11:59:49Z")

</div>

Yes, the X-API-Key.

All that example does is get retrieve a collection and then has some post-response code that creates a visualization that you can copy and paste. (It uses sendRequest to hit another API for the conversion).

If you are getting a forbidden error, its because of the authorization on the request. What status code are you getting? A 401?

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/1/7/17e6991f193485e4530fd433193a0f8a68901321.png)

You just need an environment variables called postman\_api\_key with the current value set accordingly.

---

<div class="post-metadata">

**Author:** ![altimetry-astronaut](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@altimetry-astronaut](https://community.postman.com/u/altimetry-astronaut)\
**Post date:** [July 16, 2024, 7:06am UTC](https://community.postman.com/t/generate-swagger-from-postman-collection/63894/5 "2024-07-16T07:06:33Z")

</div>

Hi @michaelderekjones , thank for your patience i had very busy days.  
By the way i tried to set the X-API-Key in the collection like you suggest and i set also the value of {{postman\_api\_key}} in the Variables tab

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/6/4/6409ac3090676b96f7d120807a3b178d31a75aac.png)

then i create a GET request inside the collection in the pic with the API Key e the id of the collection that i want the swagger in output but i receive the same response like the foloowing pic:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/0/e06297711d88a9868bb94364e2b0c80dd269f47e.png)

this is the structure on postman, is correct ?

![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/4/b4519f5b16ec60491c3f1c662b36e0765f34656e.png)

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [July 16, 2024, 2:42pm UTC](https://community.postman.com/t/generate-swagger-from-postman-collection/63894/6 "2024-07-16T14:42:49Z")

</div>

What does your API key variable look like?

It should start with PMAK-.

You might want to try generating a new API key and see if that resolves your issue.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [August 15, 2024, 2:43pm UTC](https://community.postman.com/t/generate-swagger-from-postman-collection/63894/7 "2024-08-15T14:43:09Z")

</div>

Closed on August 15, 2024, 2:43pm UTC

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