Update webhook code examples
Bash:
# You can also use wget
curl -X PATCH https://app.staging.shippit.com/api/3/merchants/webhooks/twhs_abc123xyz \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: API_KEY' \
-d '{
"webhook_url": "https://new.example.com/hook",
"enabled_states": ["in_transit", "completed", "delivery_attempted"]
}'
HTTP:
PATCH https://app.staging.shippit.com/api/3/merchants/webhooks/twhs_abc123xyz HTTP/1.1
Host: app.staging.shippit.com
Content-Type: application/json
Accept: application/json
Authorization: API_KEY
{
"webhook_url": "https://new.example.com/hook",
"enabled_states": ["in_transit", "completed", "delivery_attempted"]
}
Javascript:
const inputBody = '{
"webhook_url": "https://new.example.com/hook",
"enabled_states": ["in_transit", "completed", "delivery_attempted"]
}';
const headers = {
'Content-Type':'application/json',
'Accept':'application/json',
'Authorization':'API_KEY'
};
fetch('https://app.staging.shippit.com/api/3/merchants/webhooks/twhs_abc123xyz',
{
method: 'PATCH',
body: inputBody,
headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});
Ruby:
require 'rest-client'
require 'json'
headers = {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'API_KEY'
}
body = {
webhook_url: 'https://new.example.com/hook',
enabled_states: ['in_transit', 'completed', 'delivery_attempted']
}
result = RestClient.patch 'https://app.staging.shippit.com/api/3/merchants/webhooks/twhs_abc123xyz',
body.to_json, headers
p JSON.parse(result)
Python:
import requests
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'API_KEY'
}
payload = {
'webhook_url': 'https://new.example.com/hook',
'enabled_states': ['in_transit', 'completed', 'delivery_attempted']
}
r = requests.patch('https://app.staging.shippit.com/api/3/merchants/webhooks/twhs_abc123xyz',
json=payload, headers=headers)
print(r.json())
PHP:
<?php
require 'vendor/autoload.php';
$headers = array(
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'API_KEY',
);
$client = new \GuzzleHttp\Client();
$request_body = array(
'webhook_url' => 'https://new.example.com/hook',
'enabled_states' => ['in_transit', 'completed', 'delivery_attempted'],
);
try {
$response = $client->request('PATCH','https://app.staging.shippit.com/api/3/merchants/webhooks/twhs_abc123xyz', array(
'headers' => $headers,
'json' => $request_body,
)
);
print_r($response->getBody()->getContents());
}
catch (\GuzzleHttp\Exception\BadResponseException $e) {
// handle exception or api errors.
print_r($e->getMessage());
}
// ...
Java:
URL obj = new URL("https://app.staging.shippit.com/api/3/merchants/webhooks/twhs_abc123xyz");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("PATCH");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
Golang:
package main
import (
"bytes"
"net/http"
)
func main() {
headers := map[string][]string{
"Content-Type": []string{"application/json"},
"Accept": []string{"application/json"},
"Authorization": []string{"API_KEY"},
}
jsonBody := []byte(`{
"webhook_url": "https://new.example.com/hook",
"enabled_states": ["in_transit", "completed", "delivery_attempted"]
}`)
data := bytes.NewBuffer(jsonBody)
req, err := http.NewRequest("PATCH", "https://app.staging.shippit.com/api/3/merchants/webhooks/twhs_abc123xyz", data)
req.Header = headers
client := &http.Client{}
resp, err := client.Do(req)
// ...
}