Chilkat Online Tools

unicodeC / ShipEngine Walkthrough / List your webhooks

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonArrayW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonArrayW jarrResp;
    int respStatusCode;
    HCkJsonObjectW json;
    const wchar_t *webhook_id;
    const wchar_t *url;
    const wchar_t *v_event;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    CkHttpW_SetRequestHeader(http,L"API-Key",L"{{API_KEY}}");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://api.shipengine.com/v1/environment/webhooks",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jarrResp = CkJsonArrayW_Create();
    CkJsonArrayW_LoadSb(jarrResp,sbResponseBody);
    CkJsonArrayW_putEmitCompact(jarrResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonArrayW_emit(jarrResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonArrayW_Dispose(jarrResp);
        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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    i = 0;
    count_i = CkJsonArrayW_getSize(jarrResp);
    while (i < count_i) {
        json = CkJsonArrayW_ObjectAt(jarrResp,i);
        webhook_id = CkJsonObjectW_stringOf(json,L"webhook_id");
        url = CkJsonObjectW_stringOf(json,L"url");
        v_event = CkJsonObjectW_stringOf(json,L"event");
        CkJsonObjectW_Dispose(json);
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonArrayW_Dispose(jarrResp);

    }

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]"
    }
  ]
}