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

# Rotate an API key

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

Generates a new secret for the API key in the `id` property. The key keeps its ID, name, and owner. Rotation clears the key's revoked state and resets its `expiresAt` property.

You can rotate:

- `user-key` — Your own keys. Not allowed if your team admin disabled API key creation.
- `scim-key` — Your team's SCIM keys, if you can manage SCIM keys.
- `service-account-key` — Keys of service accounts in your team, if you can manage service accounts. A Super Admin service account's keys require a Super Admin.
- `service-account-scim-key` — SCIM keys of service accounts in your team. Requires the service account requirements above and the permission to manage SCIM keys.

**The existing secret keeps working for 6 hours after rotation**, so you can roll out the new key. To make the existing secret stop working immediately, set `revokeExisting` to `true`. You must set it to `true` to rotate a revoked key.

On success, this returns an HTTP `201 Created` response that includes the new full key value. This is the only time the API returns it, so store it securely.


Reference: https://learning.postman.com/api-docs/api-reference/api-keys/rotate-api-key

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

- `id` (string, required) — The ID of the API key to rotate.
- `revokeExisting` (boolean, optional, default: false) — If true, the existing secret stops working immediately instead of after 6 hours. You must set this to `true` to rotate a revoked key.

## Response

### 201

Created. The response includes the rotated API key's new full value, which you cannot retrieve again.

- `id` (string, required) — The API key's ID.
- `name` (string, required) — The API key's name.
- `type` (enum, required) — The API key's type.
  - Allowed values: `user-key`, `scim-key`, `service-account-key`, `service-account-scim-key`
- `version` (enum, required) — The API key's version. Both SCIM key types use `scim`.
  - Allowed values: `v1`, `v2`, `scim`
- `owner` (apiKeyUser, required) — A user. By default, only the `id` property is returned. If you set `populateUsers` to `true`, the `name`, `username`, `email`, and `profilePic` properties are also returned. These properties are `null` if the user cannot be found.
- `createdBy` (apiKeyUser, required, nullable) — The user who created the key. For `user-key` and `scim-key` keys, this is the same as `owner`. For the service account key types, this is the admin who created the key. This value is `null` if the system did not record who created it.
- `enabled` (boolean, required) — If true, the key is enabled.
- `revoked` (boolean, required) — If true, the key is revoked. The API returns an expired key as revoked.
- `revocation` (ApiKeyRevocation, required, nullable) — Why the key was revoked. This value is `null` unless `revoked` is `true`.
- `createdAt` (datetime, required) — The date and time at which the key was created.
- `accessedAt` (datetime, required, nullable) — The date and time at which the key was last used. This value is `null` if the key has never been used.
- `expiresAt` (datetime, required, nullable) — The date and time after which the key expires. This value is `null` if the key does not expire.
- `key` (string, required) — The full API key. The API only returns this value in the create and rotate responses. You cannot retrieve it again.

## Errors

### 400 Bad Request Error

Bad Request. The request is invalid, you rotated a revoked key without setting `revokeExisting` to `true`, API key creation is disabled for the team, or the service accounts feature is unavailable.

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

### 401 Unauthorized Error

Unauthorized

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

### 403 Forbidden Error

Forbidden. You do not have permission to rotate this API key.

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

### 404 Not Found Error

Not Found. The API key does not exist, is not yours (for `user-key` keys), or is not in your team (for SCIM keys).

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

### 429 Too Many Requests Error

Too Many Requests. You exceeded your request limit, or another key is being created for the same owner.

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

### 500 Internal Server Error

Internal Server Error

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

### 503 Service Unavailable Error

Service Unavailable. API keys are temporarily unavailable.

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

## Types

### apiKeyUser

A user. By default, only the `id` property is returned. If you set `populateUsers` to `true`, the `name`, `username`, `email`, and `profilePic` properties are also returned. These properties are `null` if the user cannot be found.

- `id` (integer, required) — The user's ID.
- `name` (string, optional, nullable) — The user's name. Only returned if `populateUsers` is `true`.
- `username` (string, optional, nullable) — The user's username. Only returned if `populateUsers` is `true`.
- `email` (string, optional, nullable) — The user's email address. Only returned if `populateUsers` is `true`.
- `profilePic` (string, optional, nullable) — The URL of the user's profile picture. Only returned if `populateUsers` is `true`.

### ApiKeyRevocation

Why the key was revoked. This value is `null` unless `revoked` is `true`.

- `reason` (string, required) — The reason code. For example, `inactivity`, `lifetime_reached`, `security`, or `revoked_by_admin`.
- `message` (string, required) — A readable description of the reason.

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

### CommonErrorTypeTitleDetailStatusType

The type of error.

- string
- string

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

### Rotated Key

**Response**

```json
{
  "id": "e5f6a1b2c3d4e5f6a1b2c3d4",
  "name": "CI pipeline key",
  "type": "user-key",
  "version": "v2",
  "owner": {
    "id": 12345678
  },
  "createdBy": {
    "id": 12345678
  },
  "enabled": true,
  "revoked": false,
  "revocation": null,
  "createdAt": "2026-10-08T09:12:44.000Z",
  "accessedAt": "2026-11-09T18:22:41.000Z",
  "expiresAt": "2027-02-08T09:20:00.000Z",
  "key": "PMAK-XXXX-XXXX"
}
```

**SDK Code**

```python Rotated Key
import requests

url = "https://api.postman.com/rotate-api-keys"

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

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

print(response.json())
```

```javascript Rotated Key
const url = 'https://api.postman.com/rotate-api-keys';
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 Rotated Key
package main

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

func main() {

	url := "https://api.postman.com/rotate-api-keys"

	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 Rotated Key
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/rotate-api-keys")

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

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

```php Rotated Key
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

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

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

```csharp Rotated Key
using RestSharp;

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

```swift Rotated Key
import Foundation

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

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

### Keep the Existing Secret for 6 Hours

**Request**

```json
{
  "id": "e5f6a1b2c3d4e5f6a1b2c3d4"
}
```

**Response**

```json
{
  "id": "e5f6a1b2c3d4e5f6a1b2c3d4",
  "name": "CI pipeline key",
  "type": "user-key",
  "version": "v2",
  "owner": {
    "id": 12345678
  },
  "createdBy": {
    "id": 12345678
  },
  "enabled": true,
  "revoked": false,
  "revocation": null,
  "createdAt": "2026-10-08T09:12:44.000Z",
  "accessedAt": "2026-11-09T18:22:41.000Z",
  "expiresAt": "2027-02-08T09:20:00.000Z",
  "key": "PMAK-XXXX-XXXX"
}
```

**SDK Code**

```python Keep the Existing Secret for 6 Hours
import requests

url = "https://api.postman.com/rotate-api-keys"

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

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

print(response.json())
```

```javascript Keep the Existing Secret for 6 Hours
const url = 'https://api.postman.com/rotate-api-keys';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"id":"e5f6a1b2c3d4e5f6a1b2c3d4"}'
};

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

```go Keep the Existing Secret for 6 Hours
package main

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

func main() {

	url := "https://api.postman.com/rotate-api-keys"

	payload := strings.NewReader("{\n  \"id\": \"e5f6a1b2c3d4e5f6a1b2c3d4\"\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 Keep the Existing Secret for 6 Hours
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/rotate-api-keys")

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  \"id\": \"e5f6a1b2c3d4e5f6a1b2c3d4\"\n}"

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

```java Keep the Existing Secret for 6 Hours
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.postman.com/rotate-api-keys")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"id\": \"e5f6a1b2c3d4e5f6a1b2c3d4\"\n}")
  .asString();
```

```php Keep the Existing Secret for 6 Hours
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/rotate-api-keys', [
  'body' => '{
  "id": "e5f6a1b2c3d4e5f6a1b2c3d4"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Keep the Existing Secret for 6 Hours
using RestSharp;

var client = new RestClient("https://api.postman.com/rotate-api-keys");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"id\": \"e5f6a1b2c3d4e5f6a1b2c3d4\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Keep the Existing Secret for 6 Hours
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["id": "e5f6a1b2c3d4e5f6a1b2c3d4"] as [String : Any]

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

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

### Revoke the Existing Secret Immediately

**Request**

```json
{
  "id": "e5f6a1b2c3d4e5f6a1b2c3d4",
  "revokeExisting": true
}
```

**Response**

```json
{
  "id": "e5f6a1b2c3d4e5f6a1b2c3d4",
  "name": "CI pipeline key",
  "type": "user-key",
  "version": "v2",
  "owner": {
    "id": 12345678
  },
  "createdBy": {
    "id": 12345678
  },
  "enabled": true,
  "revoked": false,
  "revocation": null,
  "createdAt": "2026-10-08T09:12:44.000Z",
  "accessedAt": "2026-11-09T18:22:41.000Z",
  "expiresAt": "2027-02-08T09:20:00.000Z",
  "key": "PMAK-XXXX-XXXX"
}
```

**SDK Code**

```python Revoke the Existing Secret Immediately
import requests

url = "https://api.postman.com/rotate-api-keys"

payload = {
    "id": "e5f6a1b2c3d4e5f6a1b2c3d4",
    "revokeExisting": True
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Revoke the Existing Secret Immediately
const url = 'https://api.postman.com/rotate-api-keys';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"id":"e5f6a1b2c3d4e5f6a1b2c3d4","revokeExisting":true}'
};

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

```go Revoke the Existing Secret Immediately
package main

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

func main() {

	url := "https://api.postman.com/rotate-api-keys"

	payload := strings.NewReader("{\n  \"id\": \"e5f6a1b2c3d4e5f6a1b2c3d4\",\n  \"revokeExisting\": 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 Revoke the Existing Secret Immediately
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/rotate-api-keys")

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  \"id\": \"e5f6a1b2c3d4e5f6a1b2c3d4\",\n  \"revokeExisting\": true\n}"

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

```java Revoke the Existing Secret Immediately
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.postman.com/rotate-api-keys")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"id\": \"e5f6a1b2c3d4e5f6a1b2c3d4\",\n  \"revokeExisting\": true\n}")
  .asString();
```

```php Revoke the Existing Secret Immediately
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/rotate-api-keys', [
  'body' => '{
  "id": "e5f6a1b2c3d4e5f6a1b2c3d4",
  "revokeExisting": true
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Revoke the Existing Secret Immediately
using RestSharp;

var client = new RestClient("https://api.postman.com/rotate-api-keys");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"id\": \"e5f6a1b2c3d4e5f6a1b2c3d4\",\n  \"revokeExisting\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Revoke the Existing Secret Immediately
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "id": "e5f6a1b2c3d4e5f6a1b2c3d4",
  "revokeExisting": true
] as [String : Any]

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

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