> 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.

# Create a component

POST https://api.postman.com/components
Content-Type: application/json

Creates a new component. The component is created in an active state with an initial draft. Use the POST `/components/{componentId}/versions` endpoint to publish a version.

Reference: https://learning.postman.com/api-docs/api-reference/components/create-component

## 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

### Body (application/json)

This endpoint expects a createComponent.

- `name` (string, required) — The component's name. This must be unique within the team and can only contain letters, digits, hyphens, underscores, and periods and can't exceed 60 characters.
- `type` (enum, required) — The component's type. Corresponds to the specification that the component's content adheres to.
  - Allowed values: `OAS2`, `OAS3`, `OAS3_1`
- `content` (string, required) — The component's content, up to a maximum of 500 KB (UTF-8).
- `format` (enum, optional, default: YAML) — The component's content format. Defaults to YAML.
  - Allowed values: `JSON`, `YAML`

## Response

### 201

Component Created

- `id` (string, optional) — The component's ID.

## Errors

### 400 Bad Request Error

Bad Request

- `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.

### 401 Unauthorized Error

Unauthorized

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

### 403 Forbidden Error

Forbidden

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

### 409 Conflict Error

Conflict

- `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

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

## Types

### 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.

### commonErrorNameMessage

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

### commonErrorTypeTitleDetail

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

### CommonErrorNameMessageError

Information about the error.

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

### CommonErrorTypeTitleDetailDetail

Information about the error.

- string
- map from string to any

## Examples

### Component Created

**Response**

```json
{
  "id": "01KT964C30J3DPJQKEACZH39N8"
}
```

**SDK Code**

```python Component Created
import requests

url = "https://api.postman.com/components"

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

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

print(response.json())
```

```javascript Component Created
const url = 'https://api.postman.com/components';
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 Component Created
package main

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

func main() {

	url := "https://api.postman.com/components"

	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 Component Created
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/components")

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 Component Created
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.postman.com/components")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Component Created
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/components', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Component Created
using RestSharp;

var client = new RestClient("https://api.postman.com/components");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Component Created
import Foundation

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/components")! 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()
```

### Create Component

**Request**

```json
{
  "name": "example-component",
  "type": "OAS3",
  "content": "openapi: 3.0.0\ninfo:\n  title: Example API\n  version: 1.0.0",
  "format": "YAML"
}
```

**Response**

```json
{
  "id": "01KT964C30J3DPJQKEACZH39N8"
}
```

**SDK Code**

```python Create Component
import requests

url = "https://api.postman.com/components"

payload = {
    "name": "example-component",
    "type": "OAS3",
    "content": "openapi: 3.0.0
info:
  title: Example API
  version: 1.0.0",
    "format": "YAML"
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Create Component
const url = 'https://api.postman.com/components';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"name":"example-component","type":"OAS3","content":"openapi: 3.0.0\ninfo:\n  title: Example API\n  version: 1.0.0","format":"YAML"}'
};

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

```go Create Component
package main

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

func main() {

	url := "https://api.postman.com/components"

	payload := strings.NewReader("{\n  \"name\": \"example-component\",\n  \"type\": \"OAS3\",\n  \"content\": \"openapi: 3.0.0\\ninfo:\\n  title: Example API\\n  version: 1.0.0\",\n  \"format\": \"YAML\"\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 Create Component
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/components")

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\": \"example-component\",\n  \"type\": \"OAS3\",\n  \"content\": \"openapi: 3.0.0\\ninfo:\\n  title: Example API\\n  version: 1.0.0\",\n  \"format\": \"YAML\"\n}"

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

```java Create Component
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.postman.com/components")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"example-component\",\n  \"type\": \"OAS3\",\n  \"content\": \"openapi: 3.0.0\\ninfo:\\n  title: Example API\\n  version: 1.0.0\",\n  \"format\": \"YAML\"\n}")
  .asString();
```

```php Create Component
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/components', [
  'body' => '{
  "name": "example-component",
  "type": "OAS3",
  "content": "openapi: 3.0.0\\ninfo:\\n  title: Example API\\n  version: 1.0.0",
  "format": "YAML"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Create Component
using RestSharp;

var client = new RestClient("https://api.postman.com/components");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"example-component\",\n  \"type\": \"OAS3\",\n  \"content\": \"openapi: 3.0.0\\ninfo:\\n  title: Example API\\n  version: 1.0.0\",\n  \"format\": \"YAML\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create Component
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "example-component",
  "type": "OAS3",
  "content": "openapi: 3.0.0
info:
  title: Example API
  version: 1.0.0",
  "format": "YAML"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/components")! 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()
```