> This page is for Postman API Docs.

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt.

# Create a webhook

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

Creates a webhook that triggers a collection with a custom payload. You can get the webhook's URL from the `webhookUrl` property in the endpoint's response.

**Note:**

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


Reference: https://learning.postman.com/api-docs/api-reference/webhooks/create-webhook

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

### Query parameters

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

### Body (application/json)

This endpoint expects a createWebhook.

- `webhook` (CreateWebhookWebhook, optional) — Information about the webhook to create.

## Response

### 200

Successful Response

- `webhook` (CreateWebhookResponseWebhook, optional) — Information about the created webhook.

## Errors

### 400 Bad Request Error

Missing Parameter

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

### 401 Unauthorized Error

Unauthorized

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

### 500 Internal Server Error

Internal Server Error

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

## Types

### CreateWebhookWebhook

Information about the webhook to create.

- `collection` (string, required) — The unique ID of the collection to trigger when calling this webhook.
- `name` (string, required) — The webhook's name. On success, the system creates a new monitor with this name in the **Monitors** tab.
- `environment` (string, optional) — The unique ID of the environment to trigger when calling this webhook.

### CreateWebhookResponseWebhook

Information about the created webhook.

- `id` (string, optional) — The webhook's ID.
- `name` (string, optional) — The webhook's name.
- `collection` (string, optional) — The unique ID of the collection that triggers when calling this webhook.
- `webhookUrl` (string, optional) — The webhook's URL.
- `uid` (string, optional) — The webhook's unique ID.

### CommonErrorNameMessageDetailsError

Information about the error.

- `name` (string, optional) — The error name.
- `message` (string, optional) — The error message.
- `details` (CommonErrorNameMessageDetailsErrorDetails, 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.

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

### CommonErrorNameMessageDetailsErrorDetails

Information about the error.

- map from string to any
- list of string

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

### Webhook Created

**Response**

```json
{
  "webhook": {
    "id": "1f0df51a-8658-4ee8-a2a1-d2567dfa09a9",
    "name": "Test Webhook",
    "collection": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
    "webhookUrl": "https://newman-api.postman.com/run/12345678/267a6e99-b6da-407c-a96f-03be2d6282fb",
    "uid": "12345678-1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"
  }
}
```

**SDK Code**

```python Webhook Created
import requests

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

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

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

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

print(response.json())
```

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

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

func main() {

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

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

url = URI("https://api.postman.com/webhooks?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>'

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

```java Webhook Created
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

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

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

$client = new \GuzzleHttp\Client();

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

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

```csharp Webhook Created
using RestSharp;

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

```swift Webhook Created
import Foundation

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/webhooks?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 Webhook

**Request**

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

**Response**

```json
{
  "webhook": {
    "id": "1f0df51a-8658-4ee8-a2a1-d2567dfa09a9",
    "name": "Test Webhook",
    "collection": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
    "webhookUrl": "https://newman-api.postman.com/run/12345678/267a6e99-b6da-407c-a96f-03be2d6282fb",
    "uid": "12345678-1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"
  }
}
```

**SDK Code**

```python Create Webhook
import requests

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

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

payload = { "webhook": {
        "collection": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
        "name": "Test Webhook"
    } }
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Create Webhook
const url = 'https://api.postman.com/webhooks?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"webhook":{"collection":"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2","name":"Test Webhook"}}'
};

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

```go Create Webhook
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"webhook\": {\n    \"collection\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n    \"name\": \"Test Webhook\"\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 Webhook
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/webhooks?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  \"webhook\": {\n    \"collection\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n    \"name\": \"Test Webhook\"\n  }\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.postman.com/webhooks?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"webhook\": {\n    \"collection\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n    \"name\": \"Test Webhook\"\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/webhooks?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9', [
  'body' => '{
  "webhook": {
    "collection": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
    "name": "Test Webhook"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Create Webhook
using RestSharp;

var client = new RestClient("https://api.postman.com/webhooks?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  \"webhook\": {\n    \"collection\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n    \"name\": \"Test Webhook\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create Webhook
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["webhook": [
    "collection": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
    "name": "Test Webhook"
  ]] as [String : Any]

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

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