> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt. For full content including API reference and SDK examples, see https://learning.postman.com/llms-full.txt.

# Create a component

POST https://api.getpostman.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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Postman API
  version: 1.0.0
paths:
  /components:
    post:
      operationId: createComponent
      summary: Create a component
      description: >-
        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.
      tags:
        - components
      parameters:
        - name: x-api-key
          in: header
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Component Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/createComponentResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateComponentRequestUnauthorizedError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateComponentRequestForbiddenError'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateComponentRequestInternalServerError'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/createComponent'
servers:
  - url: https://api.getpostman.com
    description: https://api.getpostman.com
  - url: https://api.eu.postman.com
    description: https://api.eu.postman.com
components:
  schemas:
    componentType:
      type: string
      enum:
        - OAS2
        - OAS3
        - OAS3_1
      description: >-
        The component's type. Corresponds to the specification that the
        component's content adheres to.
      title: componentType
    componentContentFormatData:
      type: string
      enum:
        - JSON
        - YAML
      description: The component's content format.
      title: componentContentFormatData
    createComponent:
      type: object
      properties:
        name:
          type: string
          description: >-
            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:
          $ref: '#/components/schemas/componentType'
        content:
          type: string
          description: The component's content, up to a maximum of 500 KB (UTF-8).
        format:
          $ref: '#/components/schemas/componentContentFormatData'
          default: YAML
          description: The component's content format. Defaults to YAML.
      required:
        - name
        - type
        - content
      title: createComponent
    componentId:
      type: string
      description: The component's ID.
      title: componentId
    createComponentResponse:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/componentId'
      description: Information about the component.
      title: createComponentResponse
    CommonErrorTypeTitleDetailStatusType:
      oneOf:
        - type: string
          format: uri-reference
        - type: string
      title: CommonErrorTypeTitleDetailStatusType
    commonErrorTypeTitleDetailStatus:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/CommonErrorTypeTitleDetailStatusType'
        title:
          type: string
          description: A short summary of the problem.
        detail:
          type: string
          description: Information about the error.
        status:
          type: integer
          description: The error's HTTP status code.
      title: commonErrorTypeTitleDetailStatus
    CommonErrorNameMessageError:
      type: object
      properties:
        name:
          type: string
          description: The error name.
        message:
          type: string
          description: The error message.
      description: Information about the error.
      title: CommonErrorNameMessageError
    commonErrorNameMessage:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/CommonErrorNameMessageError'
          description: Information about the error.
      title: commonErrorNameMessage
    CreateComponentRequestUnauthorizedError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: CreateComponentRequestUnauthorizedError
    CreateComponentRequestForbiddenError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: CreateComponentRequestForbiddenError
    CommonErrorTypeTitleDetailDetail:
      oneOf:
        - type: string
        - type: object
          additionalProperties:
            description: Any type
      description: Information about the error.
      title: CommonErrorTypeTitleDetailDetail
    commonErrorTypeTitleDetail:
      type: object
      properties:
        type:
          type: string
          description: The type of error.
        title:
          type: string
          description: A short summary of the problem.
        detail:
          $ref: '#/components/schemas/CommonErrorTypeTitleDetailDetail'
          description: Information about the error.
      title: commonErrorTypeTitleDetail
    CreateComponentRequestInternalServerError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetail'
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: CreateComponentRequestInternalServerError
  securitySchemes:
    PostmanApiKey:
      type: apiKey
      in: header
      name: x-api-key
    scimApiKey:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        A valid [SCIM API
        key](https://learning.postman.com/docs/administration/scim-provisioning/scim-provisioning-overview/#generating-scim-api-key)
        for calls to SCIM endpoints.
    basicAuth:
      type: http
      scheme: basic

```

## Examples

### Component Created



**Request**

```json
undefined
```

**Response**

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

**SDK Code**

```python Component Created
import requests

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

headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Component Created
const url = 'https://api.getpostman.com/components';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: undefined
};

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.getpostman.com/components"

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

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

url = URI("https://api.getpostman.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'

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.getpostman.com/components")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

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

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

```csharp Component Created
using RestSharp;

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

```swift Component Created
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]

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