> This page is for Postman API Docs.

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt.

# Generate a collection from spec

POST https://api.postman.com/specs/{specId}/generations/{elementType}
Content-Type: application/json

Creates a collection from the given OpenAPI 2.0, 3.0, or 3.1 specification or Smithy specification. The response contains a polling link to the task status.

Reference: https://learning.postman.com/api-docs/api-reference/specs/generate-collection

## Authentication

- `x-api-key` header (required) — API Key authentication via header

## Servers

- `https://api.postman.com` (https://api.postman.com, default)
- `https://api.eu.postman.com` (https://api.eu.postman.com)

## Request

### Path parameters

- `specId` (string, required) — The spec's ID.
- `elementType` (enum, required) — The `collection` element type.
  - Allowed values: `collection`

### Body (application/json)

This endpoint expects a generateCollection.

- `name` (string, required) — The generated collection's name.
- `options` (generateCollectionOptions, required) — The advanced creation options and their values. For more details, see Postman's [OpenAPI to Postman Collection Converter OPTIONS documentation](https://github.com/postmanlabs/openapi-to-postman/blob/develop/OPTIONS.md). These properties are case-sensitive.

## Response

### 202

Successful Response

- `taskId` (string, optional) — The created task ID. You can use this ID to track the status of the task.
- `url` (string, optional) — The URL to get or poll the status of a generated spec task.

## Errors

### 401 Unauthorized Error

Unauthorized

- `type` (CommonErrorTypeTitleDetailStatusType, optional) — The type of error.
- `title` (string, optional) — A short summary of the problem.
- `detail` (string, optional) — Information about the error.
- `status` (integer, optional) — The error's HTTP status code.

### 403 Forbidden Error

Forbidden

- `GenerateCollectionRequestForbiddenError`
  - Error (Type, Title, Detail, Status): commonErrorTypeTitleDetailStatus
  - Error (Type, Title, Detail, Status, Instance): commonErrorTypeTitleDetailStatusInstance

### 404 Not Found Error

Not Found

- `type` (CommonErrorTypeTitleDetailStatusType, optional) — The type of error.
- `title` (string, optional) — A short summary of the problem.
- `detail` (string, optional) — Information about the error.
- `status` (integer, optional) — The error's HTTP status code.

### 423 Locked Error

Locked

- `type` (CommonErrorTypeTitleDetailStatusType, optional) — The type of error.
- `title` (string, optional) — A short summary of the problem.
- `detail` (string, optional) — Information about the error.
- `status` (integer, optional) — The error's HTTP status code.

### 500 Internal Server Error

Internal Server Error

- `GenerateCollectionRequestInternalServerError`
  - Error (Type, Title, Detail): commonErrorTypeTitleDetail
  - Error (Type, Title, Detail, Status): commonErrorTypeTitleDetailStatus
  - Error (Name, Message): commonErrorNameMessage

## Types

### generateCollectionOptions

The advanced creation options and their values. For more details, see Postman's [OpenAPI to Postman Collection Converter OPTIONS documentation](https://github.com/postmanlabs/openapi-to-postman/blob/develop/OPTIONS.md). These properties are case-sensitive.

- `requestNameSource` (enum, optional, default: Fallback) — Determines how the generated collection's requests are named. If the `Fallback` value is passed, then the request is named after one of the following values in the schema: - `summary` - `operationId` - `description` - `url`
  - Allowed values: `Fallback`, `URL`
- `indentCharacter` (enum, optional, default: Space) — The option for setting the indentation character type.
  - Allowed values: `Tab`, `Space`
- `folderStrategy` (enum, optional, default: Paths) — Whether to create folders based on the specification's `paths` or `tags` properties.
  - Allowed values: `Paths`, `Tags`
- `includeAuthInfoInExample` (boolean, optional, default: true) — If true, include the authentication parameters in the example request.
- `enableOptionalParameters` (boolean, optional, default: true) — If true, enables optional parameters in the collection and its requests.
- `keepImplicitHeaders` (boolean, optional, default: false) — If true, keep the implicit headers from the OpenAPI specification, which are removed by default.
- `includeDeprecated` (boolean, optional, default: true) — If true, includes all deprecated operations, parameters, and properties in generated collection.
- `alwaysInheritAuthentication` (boolean, optional, default: false) — Whether authentication details should be included in all requests, or always inherited from the collection.
- `nestedFolderHierarchy` (boolean, optional, default: false) — If true, creates subfolders in the generated collection based on the order of the endpoints' tags.
- `parametersResolution` (string, optional, default: Schema, deprecated) — Generated collections use examples for parameter generation by default. Any existing collections generated using the schema parameter generation will continue to sync using their existing strategy.

### CommonErrorTypeTitleDetailStatusType

The type of error.

- string
- string

### commonErrorTypeTitleDetailStatus

- `type` (CommonErrorTypeTitleDetailStatusType, optional) — The type of error.
- `title` (string, optional) — A short summary of the problem.
- `detail` (string, optional) — Information about the error.
- `status` (integer, optional) — The error's HTTP status code.

### commonErrorTypeTitleDetailStatusInstance

- `type` (string, optional) — The [URI reference](https://www.rfc-editor.org/rfc/rfc3986) that identifies the type of problem.
- `title` (string, optional) — A short summary of the problem.
- `detail` (string, optional) — An explanation about the problem.
- `status` (integer, optional) — The HTTP status code generated by the origin server.
- `instance` (string, optional) — The URI reference that identifies the specific occurrence of the problem.

### commonErrorTypeTitleDetail

- `type` (string, optional) — The type of error.
- `title` (string, optional) — A short summary of the problem.
- `detail` (CommonErrorTypeTitleDetailDetail, optional) — Information about the error.

### commonErrorNameMessage

- `error` (CommonErrorNameMessageError, optional) — Information about the error.

### CommonErrorTypeTitleDetailDetail

Information about the error.

- string
- map from string to any

### CommonErrorNameMessageError

Information about the error.

- `name` (string, optional) — The error name.
- `message` (string, optional) — The error message.

## Examples

### Generate Spec Task

**Response**

```json
{
  "taskId": "66ae9950-0869-4e65-96b0-1e0e47e771af",
  "url": "/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/tasks/66ae9950-0869-4e65-96b0-1e0e47e771af"
}
```

**SDK Code**

```python Generate Spec Task
import requests

url = "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Generate Spec Task
const url = 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Generate Spec Task
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Generate Spec Task
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Generate Spec Task
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Generate Spec Task
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Generate Spec Task
using RestSharp;

var client = new RestClient("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Generate Spec Task
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Generate Collection Task

**Response**

```json
{
  "taskId": "66ae9950-0869-4e65-96b0-1e0e47e771af",
  "url": "/collections/12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2/tasks/66ae9950-0869-4e65-96b0-1e0e47e771af"
}
```

**SDK Code**

```python Generate Collection Task
import requests

url = "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Generate Collection Task
const url = 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Generate Collection Task
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Generate Collection Task
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Generate Collection Task
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Generate Collection Task
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Generate Collection Task
using RestSharp;

var client = new RestClient("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Generate Collection Task
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Generate a Collection

**Request**

```json
{
  "name": "Sample API",
  "options": {
    "folderStrategy": "Tags",
    "enableOptionalParameters": true
  }
}
```

**Response**

```json
{
  "taskId": "66ae9950-0869-4e65-96b0-1e0e47e771af",
  "url": "/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/tasks/66ae9950-0869-4e65-96b0-1e0e47e771af"
}
```

**SDK Code**

```python Generate a Collection
import requests

url = "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection"

payload = {
    "name": "Sample API",
    "options": {
        "folderStrategy": "Tags",
        "enableOptionalParameters": True
    }
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Generate a Collection
const url = 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"name":"Sample API","options":{"folderStrategy":"Tags","enableOptionalParameters":true}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Generate a Collection
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection"

	payload := strings.NewReader("{\n  \"name\": \"Sample API\",\n  \"options\": {\n    \"folderStrategy\": \"Tags\",\n    \"enableOptionalParameters\": true\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Generate a Collection
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Sample API\",\n  \"options\": {\n    \"folderStrategy\": \"Tags\",\n    \"enableOptionalParameters\": true\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Generate a Collection
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Sample API\",\n  \"options\": {\n    \"folderStrategy\": \"Tags\",\n    \"enableOptionalParameters\": true\n  }\n}")
  .asString();
```

```php Generate a Collection
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection', [
  'body' => '{
  "name": "Sample API",
  "options": {
    "folderStrategy": "Tags",
    "enableOptionalParameters": true
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Generate a Collection
using RestSharp;

var client = new RestClient("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Sample API\",\n  \"options\": {\n    \"folderStrategy\": \"Tags\",\n    \"enableOptionalParameters\": true\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Generate a Collection
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Sample API",
  "options": [
    "folderStrategy": "Tags",
    "enableOptionalParameters": true
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/generations/collection")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```