Back to Collection Items
var os = require('os');
if (os.platform() == 'win32') {
if (os.arch() == 'ia32') {
var chilkat = require('@chilkat/ck-node21-win-ia32');
} else {
var chilkat = require('@chilkat/ck-node21-win64');
}
} else if (os.platform() == 'linux') {
if (os.arch() == 'arm') {
var chilkat = require('@chilkat/ck-node21-arm');
} else if (os.arch() == 'x86') {
var chilkat = require('@chilkat/ck-node21-linux32');
} else {
var chilkat = require('@chilkat/ck-node21-linux64');
}
} else if (os.platform() == 'darwin') {
if (os.arch() == 'arm64') {
var chilkat = require('@chilkat/ck-node21-mac-m1');
} else {
var chilkat = require('@chilkat/ck-node21-macosx');
}
}
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new chilkat.Http();
var success;
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "event": "track",
// "url": "https://your-domain-here.com/some/path"
// }
var json = new chilkat.JsonObject();
json.UpdateString("event","track");
json.UpdateString("url","https://your-domain-here.com/some/path");
http.SetRequestHeader("API-Key","{{API_KEY}}");
http.SetRequestHeader("Content-Type","application/json");
// resp: HttpResponse
var resp = http.PostJson3("https://api.shipengine.com/v1/environment/webhooks","application/json",json);
if (http.LastMethodSuccess == false) {
console.log(http.LastErrorText);
return;
}
var sbResponseBody = new chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);
var jResp = new chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;
console.log("Response Body:");
console.log(jResp.Emit());
var respStatusCode = resp.StatusCode;
console.log("Response Status Code = " + respStatusCode);
if (respStatusCode >= 400) {
console.log("Response Header:");
console.log(resp.Header);
console.log("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "webhook_id": "102349",
// "url": "https://your-domain-here.com/some/path",
// "event": "track"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
var webhook_id = jResp.StringOf("webhook_id");
var url = jResp.StringOf("url");
var v_event = jResp.StringOf("event");
}
chilkatExample();
Curl Command
curl -X POST
-H "API-Key: {{API_KEY}}"
-H "Content-Type: application/json"
-d '{
"event": "track",
"url": "https://your-domain-here.com/some/path"
}'
https://api.shipengine.com/v1/environment/webhooks
Postman Collection Item JSON
{
"name": "Setup a tracking webhook",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"event\": \"track\",\n\t\"url\": \"https://your-domain-here.com/some/path\"\n}"
},
"url": {
"raw": "https://api.shipengine.com/v1/environment/webhooks",
"protocol": "https",
"host": [
"api",
"shipengine",
"com"
],
"path": [
"v1",
"environment",
"webhooks"
]
},
"description": "To subscribe to real-time tracking updates from ShipEngine, the first step is to setup a webhook. This is a **one-time step** that can be performed via the API or manually in the ShipEngine dashboard."
},
"response": [
{
"name": "Setup a tracking webhook",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n\t\"event\": \"track\",\n\t\"url\": \"https://your-domain-here.com/some/path\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.shipengine.com/v1/environment/webhooks",
"protocol": "https",
"host": [
"api",
"shipengine",
"com"
],
"path": [
"v1",
"environment",
"webhooks"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Wed, 18 Sep 2019 19:00:13 GMT"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Content-Length",
"value": "103"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Access-Control-Allow-Origin",
"value": "https://www.shipengine.com"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "server",
"value": "Microsoft-IIS/8.0"
},
{
"key": "x-newrelic-app-data",
"value": "PxQGVFZXCgITVVZbAwMCV1YGFB9AMQYAZBBZDEtZV0ZaCldOZgRRIzR/GCQIFVFBXwoMB1lFGCUWVFdHBzEGAFgNVwkaFAQcA1UIUQJTB05UGAdSVVcABBxTUE4VBHFfVgVzBSdTIloIVnpSCxoYVFIJSgRs"
},
{
"key": "x-powered-by",
"value": "ASP.NET"
},
{
"key": "x-shipengine-environment",
"value": "j"
},
{
"key": "x-shipengine-requestid",
"value": "629d0a69-ee0a-44f3-8911-b48b0da70985"
},
{
"key": "x-shipengine-server",
"value": "SS-J-WEB03"
}
],
"cookie": [
],
"body": "{\n \"webhook_id\": \"102349\",\n \"url\": \"https://your-domain-here.com/some/path\",\n \"event\": \"track\"\n}"
}
]
}