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

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

Creates a new ruleset for the team.

Reference: https://learning.postman.com/api-docs/api-reference/api-governance/create-ruleset

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

- `name` (string, required) — The ruleset's name. Must be unique within the team and only contain letters, numbers, hyphens, underscores, and periods.
- `description` (string, required) — The ruleset's description.
- `engine` (enum, required) — The governance engine that runs the ruleset.
  - Allowed values: `spectral`
- `format` (enum, required) — The type of resource the ruleset governs.
  - Allowed values: `spectral`, `workspace`
- `content` (string, required) — The ruleset's content, up to a maximum of 500 KB (UTF-8).

## Response

### 201

Ruleset Created

- `id` (string, required) — The resource's ID.

## Errors

### 400 Bad Request Error

Bad Request

- `CreateRulesetRequestBadRequestError`

### 401 Unauthorized Error

Unauthorized

- `CreateRulesetRequestUnauthorizedError`

### 403 Forbidden Error

Forbidden

- `CreateRulesetRequestForbiddenError`

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

- `CreateRulesetRequestInternalServerError`

## Types

### commonErrorTypeTitleDetail

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

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

### commonErrorNameMessageDetails

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

### commonErrorNameMessage

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

### CommonErrorTypeTitleDetailStatusType

The type of error.

### CommonErrorTypeTitleDetailDetail

Information about the error.

### CommonErrorNameMessageDetailsError

Information about the error.

- `name` (string, optional) — The error name.
- `message` (string, optional) — The error message.
- `details` (CommonErrorNameMessageDetailsErrorDetails, optional) — Information about the error.

### CommonErrorNameMessageError

Information about the error.

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

### CommonErrorNameMessageDetailsErrorDetails

Information about the error.

## Examples

### Ruleset Created

**Request**

```json
undefined
```

**Response**

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

**SDK Code**

```python Ruleset Created
import requests

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

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

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

print(response.json())
```

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

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

func main() {

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

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

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

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

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

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

$client = new \GuzzleHttp\Client();

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

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

```csharp Ruleset Created
using RestSharp;

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

```swift Ruleset Created
import Foundation

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

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

**Request**

```json
{
  "name": "api-style-guide",
  "description": "Company-wide rules for API specifications.",
  "engine": "spectral",
  "format": "spectral",
  "content": "formats:\n  - oas2\n  - oas3\n  - aas2\n  - aas3\nrules:\n  operation-operationId: true"
}
```

**Response**

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

**SDK Code**

```python Create Ruleset
import requests

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

payload = {
    "name": "api-style-guide",
    "description": "Company-wide rules for API specifications.",
    "engine": "spectral",
    "format": "spectral",
    "content": "formats:
  - oas2
  - oas3
  - aas2
  - aas3
rules:
  operation-operationId: true"
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Create Ruleset
const url = 'https://api.postman.com/rulesets';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"name":"api-style-guide","description":"Company-wide rules for API specifications.","engine":"spectral","format":"spectral","content":"formats:\n  - oas2\n  - oas3\n  - aas2\n  - aas3\nrules:\n  operation-operationId: true"}'
};

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

```go Create Ruleset
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"name\": \"api-style-guide\",\n  \"description\": \"Company-wide rules for API specifications.\",\n  \"engine\": \"spectral\",\n  \"format\": \"spectral\",\n  \"content\": \"formats:\\n  - oas2\\n  - oas3\\n  - aas2\\n  - aas3\\nrules:\\n  operation-operationId: true\"\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 Ruleset
require 'uri'
require 'net/http'

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

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\": \"api-style-guide\",\n  \"description\": \"Company-wide rules for API specifications.\",\n  \"engine\": \"spectral\",\n  \"format\": \"spectral\",\n  \"content\": \"formats:\\n  - oas2\\n  - oas3\\n  - aas2\\n  - aas3\\nrules:\\n  operation-operationId: true\"\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.postman.com/rulesets")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"api-style-guide\",\n  \"description\": \"Company-wide rules for API specifications.\",\n  \"engine\": \"spectral\",\n  \"format\": \"spectral\",\n  \"content\": \"formats:\\n  - oas2\\n  - oas3\\n  - aas2\\n  - aas3\\nrules:\\n  operation-operationId: true\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/rulesets', [
  'body' => '{
  "name": "api-style-guide",
  "description": "Company-wide rules for API specifications.",
  "engine": "spectral",
  "format": "spectral",
  "content": "formats:\\n  - oas2\\n  - oas3\\n  - aas2\\n  - aas3\\nrules:\\n  operation-operationId: true"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Create Ruleset
using RestSharp;

var client = new RestClient("https://api.postman.com/rulesets");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"api-style-guide\",\n  \"description\": \"Company-wide rules for API specifications.\",\n  \"engine\": \"spectral\",\n  \"format\": \"spectral\",\n  \"content\": \"formats:\\n  - oas2\\n  - oas3\\n  - aas2\\n  - aas3\\nrules:\\n  operation-operationId: true\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create Ruleset
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "api-style-guide",
  "description": "Company-wide rules for API specifications.",
  "engine": "spectral",
  "format": "spectral",
  "content": "formats:
  - oas2
  - oas3
  - aas2
  - aas3
rules:
  operation-operationId: true"
] as [String : Any]

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

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