Chilkat Online Tools

Java / ShipEngine Walkthrough / List your webhooks

Back to Collection Items

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    boolean success;

    http.SetRequestHeader("API-Key","{{API_KEY}}");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = http.QuickGetSb("https://api.shipengine.com/v1/environment/webhooks",sbResponseBody);
    if (success == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    CkJsonArray jarrResp = new CkJsonArray();
    jarrResp.LoadSb(sbResponseBody);
    jarrResp.put_EmitCompact(false);

    System.out.println("Response Body:");
    System.out.println(jarrResp.emit());

    int respStatusCode = http.get_LastStatus();
    System.out.println("Response Status Code = " + respStatusCode);
    if (respStatusCode >= 400) {
        System.out.println("Response Header:");
        System.out.println(http.lastHeader());
        System.out.println("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

    CkJsonObject json;
    String webhook_id;
    String url;
    String v_event;

    int i = 0;
    int count_i = jarrResp.get_Size();
    while (i < count_i) {
        json = jarrResp.ObjectAt(i);
        webhook_id = json.stringOf("webhook_id");
        url = json.stringOf("url");
        v_event = json.stringOf("event");

        i = i+1;
        }
  }
}

Curl Command

curl -X GET
	-H "API-Key: {{API_KEY}}"
https://api.shipengine.com/v1/environment/webhooks

Postman Collection Item JSON

{
  "name": "List your webhooks",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.shipengine.com/v1/environment/webhooks",
      "protocol": "https",
      "host": [
        "api",
        "shipengine",
        "com"
      ],
      "path": [
        "v1",
        "environment",
        "webhooks"
      ]
    },
    "description": "This request lists all of the webhooks that you've setup, either via the API or the ShipEngine web dashboard."
  },
  "response": [
    {
      "name": "List your webhooks",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "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:15:31 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json; charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "119"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "https://www.shipengine.com"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "x-shipengine-requestid",
          "value": "9a84eb30-c0bb-4942-bed9-fe9d051bd810"
        }
      ],
      "cookie": [
      ],
      "body": "[\n    {\n        \"webhook_id\": \"102349\",\n        \"url\": \"https://your-domain-here.com/some/path\",\n        \"event\": \"track\"\n    }\n]"
    }
  ]
}