For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see https://developer.shipbob.com/v2.0/api/webhooks/llms.txt. For full documentation content, see https://developer.shipbob.com/v2.0/api/webhooks/llms-full.txt.

# Create a new webhook subscription


POST https://api.shipbob.com/2.0/webhook
Content-Type: application/json

Reference: https://developer.shipbob.com/v2.0/api/webhooks/create-a-new-webhook-subscription

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: api-2.0
  version: 1.0.0
paths:
  /2.0/webhook:
    post:
      operationId: create-a-new-webhook-subscription
      summary: |
        Create a new webhook subscription
      tags:
        - subpackage_webhooks
      parameters:
        - name: Authorization
          in: header
          description: Authentication using Personal Access Token (PAT) token
          required: true
          schema:
            type: string
        - name: shipbob_channel_id
          in: header
          description: ''
          required: false
          schema:
            type: string
            format: int32
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Webhooks.Create.WebhookViewModel'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/Webhooks.Post.1.0.Webhook.Bad.Request.Object
        '401':
          description: No access right at this time
          content:
            application/json:
              schema:
                description: Any type
        '403':
          description: No access
          content:
            application/json:
              schema:
                description: Any type
        '422':
          description: Client Error
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/Webhooks.Post.1.0.Webhook.Unprocessable.Entity.Object
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Webhooks.CreateWebhookSubscriptionModel'
servers:
  - url: https://api.shipbob.com
  - url: https://sandbox-api.shipbob.com
components:
  schemas:
    Webhooks.Topics:
      type: string
      enum:
        - order_shipped
        - shipment_delivered
        - shipment_exception
        - shipment_onhold
        - shipment_cancelled
      title: Webhooks.Topics
    Webhooks.CreateWebhookSubscriptionModel:
      type: object
      properties:
        subscription_url:
          type: string
          format: uri
          description: >-
            URL we will call when an event matching the subscription topic is
            raised. Must have ssl enabled (https) and accept POST requests with
            content type of application/json
        topic:
          $ref: '#/components/schemas/Webhooks.Topics'
      required:
        - subscription_url
        - topic
      title: Webhooks.CreateWebhookSubscriptionModel
    Webhooks.Create.WebhookViewModel:
      type: object
      properties:
        created_at:
          type: string
          format: date-time
          description: Timestamp the webhook subscription was created
        id:
          type: integer
          description: ID of the webhook subscription
        subscription_url:
          type:
            - string
            - 'null'
          format: uri
          description: URL subscription events will be posted to
        topic:
          $ref: '#/components/schemas/Webhooks.Topics'
      title: Webhooks.Create.WebhookViewModel
    Webhooks.Post.1.0.Webhook.Bad.Request.Object:
      type: object
      additionalProperties:
        type: array
        items:
          type: string
      title: Webhooks.Post.1.0.Webhook.Bad.Request.Object
    Webhooks.Post.1.0.Webhook.Unprocessable.Entity.Object:
      type: object
      additionalProperties:
        type: array
        items:
          type: string
      title: Webhooks.Post.1.0.Webhook.Unprocessable.Entity.Object
  securitySchemes:
    PAT:
      type: http
      scheme: bearer
      description: Authentication using Personal Access Token (PAT) token
    OAuth2:
      type: http
      scheme: bearer
      description: OAuth2 authentication using JWT tokens

```

## SDK Code Examples

```python Webhooks_createANewWebhookSubscription_example
import requests

url = "https://api.shipbob.com/2.0/webhook"

payload = {
    "subscription_url": "https://mywebsite.com/shipbob/handler",
    "topic": "order_shipped"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Webhooks_createANewWebhookSubscription_example
const url = 'https://api.shipbob.com/2.0/webhook';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"subscription_url":"https://mywebsite.com/shipbob/handler","topic":"order_shipped"}'
};

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

```go Webhooks_createANewWebhookSubscription_example
package main

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

func main() {

	url := "https://api.shipbob.com/2.0/webhook"

	payload := strings.NewReader("{\n  \"subscription_url\": \"https://mywebsite.com/shipbob/handler\",\n  \"topic\": \"order_shipped\"\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	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 Webhooks_createANewWebhookSubscription_example
require 'uri'
require 'net/http'

url = URI("https://api.shipbob.com/2.0/webhook")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"subscription_url\": \"https://mywebsite.com/shipbob/handler\",\n  \"topic\": \"order_shipped\"\n}"

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

```java Webhooks_createANewWebhookSubscription_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.shipbob.com/2.0/webhook")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"subscription_url\": \"https://mywebsite.com/shipbob/handler\",\n  \"topic\": \"order_shipped\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.shipbob.com/2.0/webhook', [
  'body' => '{
  "subscription_url": "https://mywebsite.com/shipbob/handler",
  "topic": "order_shipped"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Webhooks_createANewWebhookSubscription_example
using RestSharp;

var client = new RestClient("https://api.shipbob.com/2.0/webhook");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"subscription_url\": \"https://mywebsite.com/shipbob/handler\",\n  \"topic\": \"order_shipped\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Webhooks_createANewWebhookSubscription_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "subscription_url": "https://mywebsite.com/shipbob/handler",
  "topic": "order_shipped"
] as [String : Any]

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

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