Create webhook definition - Fabric
Create webhook definition
cURL
curl --request POST \
--url https://prod01.oms.fabric.inc/api/v2/webhook/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-site-context: <x-site-context>' \
--data '
{
"target": "http://www.test.com",
"protocol": "HTTP",
"source": "OMS",
"events": "[ORDER_CREATED]",
"tenantId": "<string>",
"targetApiKey": "adfasdWdsaQFSsdf",
"apiVersion": "<string>",
"format": "application/json",
"callbackUrl": "<string>",
"createdDate": "2023-11-07T05:31:56Z",
"updatedDate": "2023-11-07T05:31:56Z"
}
'
Python
import requests
url = "https://prod01.oms.fabric.inc/api/v2/webhook/"
payload = {
"target": "http://www.test.com",
"protocol": "HTTP",
"source": "OMS",
"events": "[ORDER_CREATED]",
"tenantId": "<string>",
"targetApiKey": "adfasdWdsaQFSsdf",
"apiVersion": "<string>",
"format": "application/json",
"callbackUrl": "<string>",
"createdDate": "2023-11-07T05:31:56Z",
"updatedDate": "2023-11-07T05:31:56Z"
}
headers = {
"x-site-context": "<x-site-context>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
JavaScript (Fetch)
const options = {
method: 'POST',
headers: {
'x-site-context': '<x-site-context>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
target: 'http://www.test.com',
protocol: 'HTTP',
source: 'OMS',
events: '[ORDER_CREATED]',
tenantId: '<string>',
targetApiKey: 'adfasdWdsaQFSsdf',
apiVersion: '<string>',
format: 'application/json',
callbackUrl: '<string>',
createdDate: '2023-11-07T05:31:56Z',
updatedDate: '2023-11-07T05:31:56Z'
})
};
fetch('https://prod01.oms.fabric.inc/api/v2/webhook/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://prod01.oms.fabric.inc/api/v2/webhook/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'target' => 'http://www.test.com',
'protocol' => 'HTTP',
'source' => 'OMS',
'events' => '[ORDER_CREATED]',
'tenantId' => '<string>',
'targetApiKey' => 'adfasdWdsaQFSsdf',
'apiVersion' => '<string>',
'format' => 'application/json',
'callbackUrl' => '<string>',
'createdDate' => '2023-11-07T05:31:56Z',
'updatedDate' => '2023-11-07T05:31:56Z'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"x-site-context: <x-site-context>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Go
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://prod01.oms.fabric.inc/api/v2/webhook/"
payload := strings.NewReader("{\n \"target\": \"http://www.test.com\",\n \"protocol\": \"HTTP\",\n \"source\": \"OMS\",\n \"events\": \"[ORDER_CREATED]\",\n \"tenantId\": \"<string>\",\n \"targetApiKey\": \"adfasdWdsaQFSsdf\",\n \"apiVersion\": \"<string>\",\n \"format\": \"application/json\",\n \"callbackUrl\": \"<string>\",\n \"createdDate\": \"2023-11-07T05:31:56Z\",\n \"updatedDate\": \"2023-11-07T05:31:56Z\"}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-site-context", "<x-site-context>")
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(string(body))
}
Java
HttpResponse<String> response = Unirest.post("https://prod01.oms.fabric.inc/api/v2/webhook/")
.header("x-site-context", "<x-site-context>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"target\": \"http://www.test.com\",\n \"protocol\": \"HTTP\",\n \"source\": \"OMS\",\n \"events\": \"[ORDER_CREATED]\",\n \"tenantId\": \"<string>\",\n \"targetApiKey\": \"adfasdWdsaQFSsdf\",\n \"apiVersion\": \"<string>\",\n \"format\": \"application/json\",\n \"callbackUrl\": \"<string>\",\n \"createdDate\": \"2023-11-07T05:31:56Z\",\n \"updatedDate\": \"2023-11-07T05:31:56Z\"}")
.asString();
Ruby
require 'uri'
require 'net/http'
url = URI("https://prod01.oms.fabric.inc/api/v2/webhook/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-site-context"] = '<x-site-context>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"target\": \"http://www.test.com\",\n \"protocol\": \"HTTP\",\n \"source\": \"OMS\",\n \"events\": \"[ORDER_CREATED]\",\n \"tenantId\": \"<string>\",\n \"targetApiKey\": \"adfasdWdsaQFSsdf\",\n \"apiVersion\": \"<string>\",\n \"format\": \"application/json\",\n \"callbackUrl\": \"<string>\",\n \"createdDate\": \"2023-11-07T05:31:56Z\",\n \"updatedDate\": \"2023-11-07T05:31:56Z\"}"
response = http.request(request)
puts response.read_body
Responses
Successful Response
{
"target": "http://www.test.com",
"protocol": "HTTP",
"source": "OMS",
"events": "[ORDER_CREATED]",
"webhookId": "<string>",
"tenantId": "<string>",
"targetApiKey": "adfasdWdsaQFSsdf",
"apiVersion": "<string>",
"format": "application/json",
"callbackUrl": "<string>",
"createdDate": "2023-11-07T05:31:56Z",
"updatedDate": "2023-11-07T05:31:56Z"
}
Error Responses
{
"message": "Webhook Definition with target, tenantId, protocol, source, apiVersion already exists!"
}
{
"message": "Internal Server Error"
}
Authorizations
AuthorizationBearer <token>
Headers
- x-site-context: Required context header.