Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Webhook_id
string ls_Url
string ls_V_event
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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"
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("event","track")
loo_Json.UpdateString("url","https://your-domain-here.com/some/path")
loo_Http.SetRequestHeader("API-Key","{{API_KEY}}")
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Resp = loo_Http.PostJson3("https://api.shipengine.com/v1/environment/webhooks","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// 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
ls_Webhook_id = loo_JResp.StringOf("webhook_id")
ls_Url = loo_JResp.StringOf("url")
ls_V_event = loo_JResp.StringOf("event")
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
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}"
}
]
}