# 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.1 info: title: | Create a new webhook subscription version: endpoint_webhooks.createANewWebhookSubscription 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: {} '401': description: No access right at this time content: {} '403': description: No access content: {} '422': description: Client Error content: {} requestBody: content: application/json: schema: $ref: '#/components/schemas/Webhooks.CreateWebhookSubscriptionModel' components: schemas: Webhooks.Topics: type: string enum: - value: order_shipped - value: shipment_delivered - value: shipment_exception - value: shipment_onhold - value: shipment_cancelled 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 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' ``` ## 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 ", "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 ', '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 ") 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 ' 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 response = Unirest.post("https://api.shipbob.com/2.0/webhook") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"subscription_url\": \"https://mywebsite.com/shipbob/handler\",\n \"topic\": \"order_shipped\"\n}") .asString(); ``` ```php Webhooks_createANewWebhookSubscription_example request('POST', 'https://api.shipbob.com/2.0/webhook', [ 'body' => '{ "subscription_url": "https://mywebsite.com/shipbob/handler", "topic": "order_shipped" }', 'headers' => [ 'Authorization' => 'Bearer ', '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 "); 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 ", "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() ```