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

POST https://api.getpostman.com/collections
Content-Type: application/json

Creates a collection using the [Postman Collection v2.1.0 schema format](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).

**Note:**

If you do not include the `workspace` query parameter, the system creates the collection in the oldest personal Internal workspace you own.


Reference: https://learning.postman.com/api-docs/api-reference/collections/create-collection

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Postman API
  version: 1.0.0
paths:
  /collections:
    post:
      operationId: createCollection
      summary: Create a collection
      description: >
        Creates a collection using the [Postman Collection v2.1.0 schema
        format](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).


        **Note:**


        If you do not include the `workspace` query parameter, the system
        creates the collection in the oldest personal Internal workspace you
        own.
      tags:
        - collections
      parameters:
        - name: workspace
          in: query
          description: The workspace's ID.
          required: true
          schema:
            $ref: '#/components/schemas/workspaceId'
        - name: x-api-key
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/collectionCreated'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/commonErrorNameMessageDetails'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateCollectionRequestUnauthorizedError'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/CreateCollectionRequestInternalServerError
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/createCollection'
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:
    workspaceId:
      type: string
      title: workspaceId
    InfoSchema:
      type: string
      enum:
        - https://schema.getpostman.com/json/collection/v2.1.0/collection.json
      description: >-
        The
        "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
        Postman Collection Format v2.1.0 schema.
      title: InfoSchema
    info:
      type: object
      properties:
        name:
          type: string
          description: The collection's name.
        description:
          type: string
          description: The collection's description.
        schema:
          $ref: '#/components/schemas/InfoSchema'
          description: >-
            The
            "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
            Postman Collection Format v2.1.0 schema.
      required:
        - name
        - schema
      description: Information about the collection.
      title: info
    VariableValue:
      oneOf:
        - type: string
        - type: boolean
        - type: integer
      description: The key's value.
      title: VariableValue
    variable:
      type: object
      properties:
        key:
          type: string
          description: The variable's key (name).
        value:
          $ref: '#/components/schemas/VariableValue'
          description: The key's value.
        description:
          type: string
          description: The variable's description.
        disabled:
          type: boolean
          default: false
          description: >-
            If true, the variable is not enabled. Doesn't apply to path
            parameter variables.
      description: Information about the variable.
      title: variable
    variable-list:
      type: array
      items:
        $ref: '#/components/schemas/variable'
      description: >-
        A list of the collection's
        [variables](https://learning.postman.com/docs/sending-requests/variables/variables/).
        Make certain not to include sensitive information in variables.
      title: variable-list
    EventListen:
      type: string
      enum:
        - test
        - prerequest
      description: >-
        Can be set to `test` or `prerequest` for test scripts or pre-request
        scripts respectively.
      title: EventListen
    script:
      type: object
      properties:
        type:
          type: string
          description: The type of script. For example, `text/javascript`.
        exec:
          type: array
          items:
            type: string
          description: >-
            A list of script strings, where each line represents a line of code.
            Separate lines makes it easy to track script changes.
      description: >-
        Information about the Javascript code that can be used to to perform
        setup or teardown operations in a response.
      title: script
    event:
      type: object
      properties:
        listen:
          $ref: '#/components/schemas/EventListen'
          description: >-
            Can be set to `test` or `prerequest` for test scripts or pre-request
            scripts respectively.
        script:
          $ref: '#/components/schemas/script'
      required:
        - listen
      description: Information about the collection's events.
      title: event
    event-list:
      type: array
      items:
        $ref: '#/components/schemas/event'
      description: A list of scripts configured to run when specific events occur.
      title: event-list
    UrlOneOf1QueryItems:
      type: object
      properties:
        key:
          type:
            - string
            - 'null'
          description: The query parameter's key.
        value:
          type:
            - string
            - 'null'
          description: The key's value.
        disabled:
          type: boolean
          default: false
          description: If true, the query parameter isn't sent with the request.
        description:
          type:
            - string
            - 'null'
          description: The query parameter's description.
      title: UrlOneOf1QueryItems
    Url1:
      type: object
      properties:
        raw:
          type: string
          description: The request's raw URL.
        protocol:
          type: string
          description: The request protocol.
        host:
          type: array
          items:
            type: string
          description: The host's URL.
        path:
          type: array
          items:
            type: string
          description: A list of the URL's path components.
        port:
          type: string
          description: >-
            The URL's port number. An empty value indicates port `80` (http) or
            `443` (https).
        query:
          type: array
          items:
            $ref: '#/components/schemas/UrlOneOf1QueryItems'
          description: >-
            A list of query parameters. These are the query string parts of the
            URL, parsed as separate variables.
      title: Url1
    url:
      oneOf:
        - type: string
          format: url
        - $ref: '#/components/schemas/Url1'
      description: Information about the URL.
      title: url
    AuthType:
      type: string
      enum:
        - noauth
        - basic
        - bearer
        - apikey
        - digest
        - oauth1
        - oauth2
        - hawk
        - awsv4
        - ntlm
        - edgegrid
      description: The authorization type.
      title: AuthType
    AuthAttributeValueOneOf1Items:
      type: object
      properties: {}
      title: AuthAttributeValueOneOf1Items
    AuthAttributeValue1:
      type: array
      items:
        $ref: '#/components/schemas/AuthAttributeValueOneOf1Items'
      title: AuthAttributeValue1
    AuthAttributeValue:
      oneOf:
        - type: string
        - $ref: '#/components/schemas/AuthAttributeValue1'
      description: The key's value.
      title: AuthAttributeValue
    AuthAttributeType:
      type: string
      enum:
        - string
        - boolean
        - number
        - array
        - object
        - any
      description: The value's type.
      title: AuthAttributeType
    auth-attribute:
      type: object
      properties:
        key:
          type: string
          description: The auth method's key value.
        value:
          $ref: '#/components/schemas/AuthAttributeValue'
          description: The key's value.
        type:
          $ref: '#/components/schemas/AuthAttributeType'
          description: The value's type.
      required:
        - key
      description: >-
        Information about the supported Postman [authorization
        type](https://learning.postman.com/docs/sending-requests/authorization/authorization-types/).
      title: auth-attribute
    auth:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/AuthType'
          description: The authorization type.
        noauth:
          description: Any type
        apikey:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: The API key's authentication information.
        awsv4:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: >-
            The attributes for [AWS
            Signature](https://learning.postman.com/docs/sending-requests/authorization/aws-signature/)
            authentication.
        basic:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: >-
            The attributes for [Basic
            Auth](https://learning.postman.com/docs/sending-requests/authorization/authorization-types/#basic-auth).
        bearer:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: >-
            The attributes for [Bearer
            Token](https://learning.postman.com/docs/sending-requests/authorization/authorization-types/#bearer-token)
            authentication.
        digest:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: >-
            The attributes for
            [Digest](https://learning.postman.com/docs/sending-requests/authorization/digest-auth/)
            access authentication.
        edgegrid:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: >-
            The attributes for [Akamai
            Edgegrid](https://learning.postman.com/docs/sending-requests/authorization/akamai-edgegrid/)
            authentication.
        hawk:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: >-
            The attributes for
            [Hawk](https://learning.postman.com/docs/sending-requests/authorization/hawk-authentication/)
            authentication.
        ntlm:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: >-
            The attributes for
            [NTLM](https://learning.postman.com/docs/sending-requests/authorization/ntlm-authentication/)
            authentication.
        oauth1:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: >-
            The attributes for
            [OAuth1](https://learning.postman.com/docs/sending-requests/authorization/oauth-10/)
            authentication.
        oauth2:
          type: array
          items:
            $ref: '#/components/schemas/auth-attribute'
          description: >-
            The attributes for
            [OAuth2](https://learning.postman.com/docs/sending-requests/authorization/oauth-20/)
            authentication.
      required:
        - type
      description: >-
        The [authorization type supported by
        Postman](https://learning.postman.com/docs/sending-requests/authorization/authorization-types/).
      title: auth
    header:
      type: object
      properties:
        key:
          type: string
          description: The header's key, such as `Content-Type` or `X-Custom-Header`.
        value:
          type: string
          description: The header key's value.
        disabled:
          type: boolean
          default: false
          description: If true, the current header isn't sent with requests.
        description:
          type:
            - string
            - 'null'
          description: The header's description.
      required:
        - key
        - value
      description: Information about the header.
      title: header
    header-list:
      type: array
      items:
        $ref: '#/components/schemas/header'
      description: A list of headers.
      title: header-list
    RequestBodyMode:
      type: string
      enum:
        - raw
        - urlencoded
        - formdata
        - file
        - graphql
      description: The data associated with the request.
      title: RequestBodyMode
    RequestBodyUrlencodedItems:
      type: object
      properties:
        key:
          type: string
          description: The key value.
        value:
          type: string
          description: The key's value.
        description:
          type:
            - string
            - 'null'
          description: The key's description.
      required:
        - key
      title: RequestBodyUrlencodedItems
    RequestBodyFormdataItemsOneOf0Type:
      type: string
      enum:
        - text
      description: The `text` value.
      title: RequestBodyFormdataItemsOneOf0Type
    RequestBodyFormdataItems0:
      type: object
      properties:
        key:
          type: string
          description: The key value.
        value:
          type: string
          description: The key's value.
        type:
          $ref: '#/components/schemas/RequestBodyFormdataItemsOneOf0Type'
          description: The `text` value.
        contentType:
          type: string
          description: The form-data Content-Type header.
        description:
          type:
            - string
            - 'null'
          description: The key's description.
      title: RequestBodyFormdataItems0
    RequestBodyFormdataItemsOneOf1Src:
      oneOf:
        - type: string
        - type: array
          items:
            type: string
      title: RequestBodyFormdataItemsOneOf1Src
    RequestBodyFormdataItemsOneOf1Type:
      type: string
      enum:
        - file
      description: The `file` value.
      title: RequestBodyFormdataItemsOneOf1Type
    RequestBodyFormdataItems1:
      type: object
      properties:
        key:
          type: string
          description: The key value.
        src:
          $ref: '#/components/schemas/RequestBodyFormdataItemsOneOf1Src'
        type:
          $ref: '#/components/schemas/RequestBodyFormdataItemsOneOf1Type'
          description: The `file` value.
        contentType:
          type: string
          description: The form-data Content-Type header.
        description:
          type:
            - string
            - 'null'
          description: The key's description.
      title: RequestBodyFormdataItems1
    RequestBodyFormdataItems:
      oneOf:
        - $ref: '#/components/schemas/RequestBodyFormdataItems0'
        - $ref: '#/components/schemas/RequestBodyFormdataItems1'
      title: RequestBodyFormdataItems
    RequestBodyFile:
      type: object
      properties:
        src:
          type:
            - string
            - 'null'
          description: >-
            The name of the file to upload (not its path). A null value
            indicates that no file is selected as a part of the request body.
      description: >-
        If the `mode` value is `file`, an object containing the file request
        information.
      title: RequestBodyFile
    RequestBodyGraphql:
      type: object
      properties:
        query:
          type: string
          description: The GraphQL query.
        variables:
          type:
            - string
            - 'null'
          description: The GraphQL query variables, in JSON format.
      description: >-
        If the `mode` value is `graphql`, an object containing the GraphQL
        request information.
      title: RequestBodyGraphql
    RequestBodyOptions:
      type: object
      properties: {}
      description: Additional configurations and options set for various modes.
      title: RequestBodyOptions
    RequestBody:
      type: object
      properties:
        mode:
          $ref: '#/components/schemas/RequestBodyMode'
          description: The data associated with the request.
        raw:
          type: string
          description: If the `mode` value is `raw`, the raw content of the request body.
        urlencoded:
          type: array
          items:
            $ref: '#/components/schemas/RequestBodyUrlencodedItems'
          description: A list of x-www-form-encoded key/value pairs.
        formdata:
          type: array
          items:
            $ref: '#/components/schemas/RequestBodyFormdataItems'
          description: >-
            If the `mode` value is `formdata`, then a list of form-data key/pair
            values.
        file:
          $ref: '#/components/schemas/RequestBodyFile'
          description: >-
            If the `mode` value is `file`, an object containing the file request
            information.
        graphql:
          $ref: '#/components/schemas/RequestBodyGraphql'
          description: >-
            If the `mode` value is `graphql`, an object containing the GraphQL
            request information.
        options:
          $ref: '#/components/schemas/RequestBodyOptions'
          description: Additional configurations and options set for various modes.
      description: >-
        Information about the collection's request body. To set this to "none",
        pass an empty object.
      title: RequestBody
    request:
      type: object
      properties:
        url:
          $ref: '#/components/schemas/url'
        auth:
          $ref: '#/components/schemas/auth'
        method:
          type: string
          description: The request's standard HTTP method.
        description:
          type:
            - string
            - 'null'
          description: The request's description.
        header:
          $ref: '#/components/schemas/header-list'
        body:
          $ref: '#/components/schemas/RequestBody'
          description: >-
            Information about the collection's request body. To set this to
            "none", pass an empty object.
      description: Information about the collection request.
      title: request
    ResponseHeader1:
      type: array
      items:
        $ref: '#/components/schemas/header'
      description: A list of the request's headers.
      title: ResponseHeader1
    ResponseHeader:
      oneOf:
        - type: string
        - $ref: '#/components/schemas/ResponseHeader1'
      title: ResponseHeader
    response:
      type: object
      properties:
        originalRequest:
          $ref: '#/components/schemas/request'
        responseTime:
          type:
            - number
            - 'null'
          format: double
          description: >-
            The time taken by the request to complete. If a number, the unit is
            milliseconds. If the response is manually created, this can be set
            as null.
        header:
          $ref: '#/components/schemas/ResponseHeader'
        body:
          type:
            - string
            - 'null'
          description: The raw text of the response.
        status:
          type: string
          description: The response's status.
        code:
          type: integer
          description: The response status code.
      description: Information about the request's response.
      title: response
    ProtocolProfileBehaviorDisabledSystemHeaders:
      type: object
      properties:
        cache-control:
          type: boolean
        postman-token:
          type: boolean
        content-type:
          type: boolean
        content-length:
          type: boolean
        accept-encoding:
          type: boolean
        connection:
          type: boolean
        host:
          type: boolean
      description: Disable the system headers which are added implicitly.
      title: ProtocolProfileBehaviorDisabledSystemHeaders
    ProtocolProfileBehaviorProtocolVersion:
      type: string
      enum:
        - http1
        - http2
        - auto
      description: >-
        The HTTP protocol version to use. Supports the `http1`, `http2`, and
        `auto` values.
      title: ProtocolProfileBehaviorProtocolVersion
    protocol-profile-behavior:
      type: object
      properties:
        strictSSL:
          type: boolean
          description: If true, enables certificate verification.
        followRedirects:
          type: boolean
          description: If true, follow HTTP 3xx responses as redirects.
        maxRedirects:
          type: number
          format: double
          description: The maximum number of redirects to follow.
        disableBodyPruning:
          type: boolean
          description: >-
            If true, disables request body pruning for the GET, COPY, HEAD,
            PURGE, and UNLOCK methods.
        disableUrlEncoding:
          type: boolean
          description: >-
            If true, disables the percent encoding of auth, path, query, and
            fragment URL segments.
        disabledSystemHeaders:
          $ref: '#/components/schemas/ProtocolProfileBehaviorDisabledSystemHeaders'
          description: Disable the system headers which are added implicitly.
        insecureHTTPParser:
          type: boolean
          description: >-
            If true, uses an insecure HTTP parser that accepts invalid HTTP
            headers.
        followOriginalHttpMethod:
          type: boolean
          description: >-
            If true, redirects with the original HTTP method. Redirects with the
            GET HTTP method by default.
        followAuthorizationHeader:
          type: boolean
          description: >-
            If true, retains the `authorization` header when a redirect happens
            to a different hostname.
        protocolVersion:
          $ref: '#/components/schemas/ProtocolProfileBehaviorProtocolVersion'
          description: >-
            The HTTP protocol version to use. Supports the `http1`, `http2`, and
            `auto` values.
        removeRefererHeaderOnRedirect:
          type: boolean
          description: If true, removes the `referer` header when a redirect happens.
        tlsPreferServerCiphers:
          type: boolean
          description: >-
            If true, uses the server's cipher suite order instead of the
            client's during negotiation.
        tlsDisabledProtocols:
          type: array
          items:
            type: string
          description: The SSL and TLS protocol versions to disable during negotiation.
        tlsCipherSelection:
          type: array
          items:
            type: string
          description: >-
            The order of cipher suites that the SSL server profile uses to
            establish a secure connection.
      description: >-
        The
        [settings](https://learning.postman.com/docs/sending-requests/create-requests/request-settings/)
        used to alter the [Protocol Profile
        Behavior](https://github.com/postmanlabs/postman-runtime/blob/develop/docs/protocol-profile-behavior.md)
        of sending a request.
      title: protocol-profile-behavior
    item:
      type: object
      properties:
        name:
          type: string
          description: The item's name.
        description:
          type:
            - string
            - 'null'
          description: The item's description.
        variable:
          $ref: '#/components/schemas/variable-list'
        event:
          $ref: '#/components/schemas/event-list'
        request:
          $ref: '#/components/schemas/request'
        response:
          type: array
          items:
            $ref: '#/components/schemas/response'
          description: A list of the collection's responses.
        protocolProfileBehavior:
          $ref: '#/components/schemas/protocol-profile-behavior'
      description: Information about the collection request or folder.
      title: item
    createCollectionSchema:
      type: object
      properties:
        info:
          $ref: '#/components/schemas/info'
        item:
          type: array
          items:
            $ref: '#/components/schemas/item'
        event:
          $ref: '#/components/schemas/event-list'
        variable:
          $ref: '#/components/schemas/variable-list'
        auth:
          $ref: '#/components/schemas/auth'
        protocolProfileBehavior:
          $ref: '#/components/schemas/protocol-profile-behavior'
      required:
        - info
        - item
      title: createCollectionSchema
    createCollection:
      type: object
      properties:
        collection:
          $ref: '#/components/schemas/createCollectionSchema'
      title: createCollection
    CollectionCreatedCollection:
      type: object
      properties:
        id:
          type: string
          description: The collection's ID.
        name:
          type: string
          description: The collection's name.
        uid:
          type: string
          format: uid
          description: The collection's unique ID.
      title: CollectionCreatedCollection
    collectionCreated:
      type: object
      properties:
        collection:
          $ref: '#/components/schemas/CollectionCreatedCollection'
      title: collectionCreated
    CommonErrorNameMessageDetailsErrorDetails:
      oneOf:
        - type: object
          additionalProperties:
            description: Any type
        - type: array
          items:
            type: string
      description: Information about the error.
      title: CommonErrorNameMessageDetailsErrorDetails
    CommonErrorNameMessageDetailsError:
      type: object
      properties:
        name:
          type: string
          description: The error name.
        message:
          type: string
          description: The error message.
        details:
          $ref: '#/components/schemas/CommonErrorNameMessageDetailsErrorDetails'
          description: Information about the error.
      title: CommonErrorNameMessageDetailsError
    commonErrorNameMessageDetails:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/CommonErrorNameMessageDetailsError'
      title: commonErrorNameMessageDetails
    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
    CreateCollectionRequestUnauthorizedError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: CreateCollectionRequestUnauthorizedError
    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
    CreateCollectionRequestInternalServerError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetail'
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: CreateCollectionRequestInternalServerError
  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

### Collection Created



**Request**

```json
undefined
```

**Response**

```json
{
  "collection": {
    "id": "12ece9e1-2abf-4edc-8e34-de66e74114d2",
    "name": "Test Collection",
    "uid": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2"
  }
}
```

**SDK Code**

```python Collection Created
import requests

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

querystring = {"workspace":"1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"}

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

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

print(response.json())
```

```javascript Collection Created
const url = 'https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9';
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 Collection Created
package main

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

func main() {

	url := "https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"

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

url = URI("https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")

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

HttpResponse<String> response = Unirest.post("https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9', [
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Collection Created
using RestSharp;

var client = new RestClient("https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
```

```swift Collection Created
import Foundation

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")! 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 Collection



**Request**

```json
{
  "collection": {
    "info": {
      "name": "Test Collection",
      "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
      "description": "This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client."
    },
    "item": [
      {
        "name": "Test GET Response",
        "event": [
          {
            "listen": "test",
            "script": {
              "type": "text/javascript",
              "exec": [
                "pm.test(\"Status code is 200\", function () {",
                "    pm.response.to.have.status(200);",
                "});"
              ],
              "id": "7d2334fc-a84a-4c3d-b26c-7529afa4c0ae"
            }
          }
        ],
        "request": {
          "url": "https://echo.getpostman.com/headers",
          "method": "GET",
          "header": [
            {
              "key": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      }
    ],
    "variable": [
      {
        "key": "userId",
        "value": "12345678",
        "description": "The user's ID.",
        "disabled": true
      }
    ]
  }
}
```

**Response**

```json
{
  "collection": {
    "id": "12ece9e1-2abf-4edc-8e34-de66e74114d2",
    "name": "Test Collection",
    "uid": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2"
  }
}
```

**SDK Code**

```python Create Collection
import requests

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

querystring = {"workspace":"1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"}

payload = { "collection": {
        "info": {
            "name": "Test Collection",
            "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
            "description": "This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client."
        },
        "item": [
            {
                "name": "Test GET Response",
                "event": [
                    {
                        "listen": "test",
                        "script": {
                            "type": "text/javascript",
                            "exec": ["pm.test(\"Status code is 200\", function () {", "    pm.response.to.have.status(200);", "});"],
                            "id": "7d2334fc-a84a-4c3d-b26c-7529afa4c0ae"
                        }
                    }
                ],
                "request": {
                    "url": "https://echo.getpostman.com/headers",
                    "method": "GET",
                    "header": [
                        {
                            "key": "Content-Type",
                            "value": "application/json"
                        }
                    ]
                }
            }
        ],
        "variable": [
            {
                "key": "userId",
                "value": "12345678",
                "description": "The user's ID.",
                "disabled": True
            }
        ]
    } }
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Create Collection
const url = 'https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"collection":{"info":{"name":"Test Collection","schema":"https://schema.getpostman.com/json/collection/v2.1.0/collection.json","description":"This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client."},"item":[{"name":"Test GET Response","event":[{"listen":"test","script":{"type":"text/javascript","exec":["pm.test(\"Status code is 200\", function () {","    pm.response.to.have.status(200);","});"],"id":"7d2334fc-a84a-4c3d-b26c-7529afa4c0ae"}}],"request":{"url":"https://echo.getpostman.com/headers","method":"GET","header":[{"key":"Content-Type","value":"application/json"}]}}],"variable":[{"key":"userId","value":"12345678","description":"The user\'s ID.","disabled":true}]}}'
};

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

```go Create Collection
package main

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

func main() {

	url := "https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"

	payload := strings.NewReader("{\n  \"collection\": {\n    \"info\": {\n      \"name\": \"Test Collection\",\n      \"schema\": \"https://schema.getpostman.com/json/collection/v2.1.0/collection.json\",\n      \"description\": \"This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client.\"\n    },\n    \"item\": [\n      {\n        \"name\": \"Test GET Response\",\n        \"event\": [\n          {\n            \"listen\": \"test\",\n            \"script\": {\n              \"type\": \"text/javascript\",\n              \"exec\": [\n                \"pm.test(\\\"Status code is 200\\\", function () {\",\n                \"    pm.response.to.have.status(200);\",\n                \"});\"\n              ],\n              \"id\": \"7d2334fc-a84a-4c3d-b26c-7529afa4c0ae\"\n            }\n          }\n        ],\n        \"request\": {\n          \"url\": \"https://echo.getpostman.com/headers\",\n          \"method\": \"GET\",\n          \"header\": [\n            {\n              \"key\": \"Content-Type\",\n              \"value\": \"application/json\"\n            }\n          ]\n        }\n      }\n    ],\n    \"variable\": [\n      {\n        \"key\": \"userId\",\n        \"value\": \"12345678\",\n        \"description\": \"The user's ID.\",\n        \"disabled\": true\n      }\n    ]\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 Create Collection
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")

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  \"collection\": {\n    \"info\": {\n      \"name\": \"Test Collection\",\n      \"schema\": \"https://schema.getpostman.com/json/collection/v2.1.0/collection.json\",\n      \"description\": \"This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client.\"\n    },\n    \"item\": [\n      {\n        \"name\": \"Test GET Response\",\n        \"event\": [\n          {\n            \"listen\": \"test\",\n            \"script\": {\n              \"type\": \"text/javascript\",\n              \"exec\": [\n                \"pm.test(\\\"Status code is 200\\\", function () {\",\n                \"    pm.response.to.have.status(200);\",\n                \"});\"\n              ],\n              \"id\": \"7d2334fc-a84a-4c3d-b26c-7529afa4c0ae\"\n            }\n          }\n        ],\n        \"request\": {\n          \"url\": \"https://echo.getpostman.com/headers\",\n          \"method\": \"GET\",\n          \"header\": [\n            {\n              \"key\": \"Content-Type\",\n              \"value\": \"application/json\"\n            }\n          ]\n        }\n      }\n    ],\n    \"variable\": [\n      {\n        \"key\": \"userId\",\n        \"value\": \"12345678\",\n        \"description\": \"The user's ID.\",\n        \"disabled\": true\n      }\n    ]\n  }\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"collection\": {\n    \"info\": {\n      \"name\": \"Test Collection\",\n      \"schema\": \"https://schema.getpostman.com/json/collection/v2.1.0/collection.json\",\n      \"description\": \"This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client.\"\n    },\n    \"item\": [\n      {\n        \"name\": \"Test GET Response\",\n        \"event\": [\n          {\n            \"listen\": \"test\",\n            \"script\": {\n              \"type\": \"text/javascript\",\n              \"exec\": [\n                \"pm.test(\\\"Status code is 200\\\", function () {\",\n                \"    pm.response.to.have.status(200);\",\n                \"});\"\n              ],\n              \"id\": \"7d2334fc-a84a-4c3d-b26c-7529afa4c0ae\"\n            }\n          }\n        ],\n        \"request\": {\n          \"url\": \"https://echo.getpostman.com/headers\",\n          \"method\": \"GET\",\n          \"header\": [\n            {\n              \"key\": \"Content-Type\",\n              \"value\": \"application/json\"\n            }\n          ]\n        }\n      }\n    ],\n    \"variable\": [\n      {\n        \"key\": \"userId\",\n        \"value\": \"12345678\",\n        \"description\": \"The user's ID.\",\n        \"disabled\": true\n      }\n    ]\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9', [
  'body' => '{
  "collection": {
    "info": {
      "name": "Test Collection",
      "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
      "description": "This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client."
    },
    "item": [
      {
        "name": "Test GET Response",
        "event": [
          {
            "listen": "test",
            "script": {
              "type": "text/javascript",
              "exec": [
                "pm.test(\\"Status code is 200\\", function () {",
                "    pm.response.to.have.status(200);",
                "});"
              ],
              "id": "7d2334fc-a84a-4c3d-b26c-7529afa4c0ae"
            }
          }
        ],
        "request": {
          "url": "https://echo.getpostman.com/headers",
          "method": "GET",
          "header": [
            {
              "key": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      }
    ],
    "variable": [
      {
        "key": "userId",
        "value": "12345678",
        "description": "The user\'s ID.",
        "disabled": true
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Create Collection
using RestSharp;

var client = new RestClient("https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"collection\": {\n    \"info\": {\n      \"name\": \"Test Collection\",\n      \"schema\": \"https://schema.getpostman.com/json/collection/v2.1.0/collection.json\",\n      \"description\": \"This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client.\"\n    },\n    \"item\": [\n      {\n        \"name\": \"Test GET Response\",\n        \"event\": [\n          {\n            \"listen\": \"test\",\n            \"script\": {\n              \"type\": \"text/javascript\",\n              \"exec\": [\n                \"pm.test(\\\"Status code is 200\\\", function () {\",\n                \"    pm.response.to.have.status(200);\",\n                \"});\"\n              ],\n              \"id\": \"7d2334fc-a84a-4c3d-b26c-7529afa4c0ae\"\n            }\n          }\n        ],\n        \"request\": {\n          \"url\": \"https://echo.getpostman.com/headers\",\n          \"method\": \"GET\",\n          \"header\": [\n            {\n              \"key\": \"Content-Type\",\n              \"value\": \"application/json\"\n            }\n          ]\n        }\n      }\n    ],\n    \"variable\": [\n      {\n        \"key\": \"userId\",\n        \"value\": \"12345678\",\n        \"description\": \"The user's ID.\",\n        \"disabled\": true\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create Collection
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["collection": [
    "info": [
      "name": "Test Collection",
      "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
      "description": "This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client."
    ],
    "item": [
      [
        "name": "Test GET Response",
        "event": [
          [
            "listen": "test",
            "script": [
              "type": "text/javascript",
              "exec": ["pm.test(\"Status code is 200\", function () {", "    pm.response.to.have.status(200);", "});"],
              "id": "7d2334fc-a84a-4c3d-b26c-7529afa4c0ae"
            ]
          ]
        ],
        "request": [
          "url": "https://echo.getpostman.com/headers",
          "method": "GET",
          "header": [
            [
              "key": "Content-Type",
              "value": "application/json"
            ]
          ]
        ]
      ]
    ],
    "variable": [
      [
        "key": "userId",
        "value": "12345678",
        "description": "The user's ID.",
        "disabled": true
      ]
    ]
  ]] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/collections?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")! 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()
```