Chilkat Online Tools

Android / Sunshine Conversations API / List Webhooks

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 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.put_BasicAuth(true);
    http.put_Login("username");
    http.put_Password("password");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = http.QuickGetSb("https://domain.com/v2/apps/{{appId}}/integrations/:integrationId/webhooks",sbResponseBody);
    if (success == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    Log.i(TAG, "Response Body:");
    Log.i(TAG, jResp.emit());

    int respStatusCode = http.get_LastStatus();
    Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, http.lastHeader());
        Log.i(TAG, "Failed.");
        return;
        }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "webhooks": [
    //     {
    //       "target": "http://example.com/callback",
    //       "triggers": [
    //         "conversation:read",
    //         "conversation:message"
    //       ],
    //       "id": "5e554d2cac66fb73a3c01871",
    //       "version": "v2",
    //       "secret": "8564b3e6a8b20a4bdb68b05ce9bc5936",
    //       "includeFullUser": false,
    //       "includeFullSource": false
    //     },
    //     {
    //       "target": "http://example.com/callback",
    //       "triggers": [
    //         "conversation:read",
    //         "conversation:message"
    //       ],
    //       "id": "5e554d2cac66fb73a3c01871",
    //       "version": "v2",
    //       "secret": "8564b3e6a8b20a4bdb68b05ce9bc5936",
    //       "includeFullUser": false,
    //       "includeFullSource": false
    //     }
    //   ]
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    String target;
    String id;
    String version;
    String secret;
    boolean includeFullUser;
    boolean includeFullSource;
    int j;
    int count_j;
    String strVal;

    int i = 0;
    int count_i = jResp.SizeOfArray("webhooks");
    while (i < count_i) {
        jResp.put_I(i);
        target = jResp.stringOf("webhooks[i].target");
        id = jResp.stringOf("webhooks[i].id");
        version = jResp.stringOf("webhooks[i].version");
        secret = jResp.stringOf("webhooks[i].secret");
        includeFullUser = jResp.BoolOf("webhooks[i].includeFullUser");
        includeFullSource = jResp.BoolOf("webhooks[i].includeFullSource");
        j = 0;
        count_j = jResp.SizeOfArray("webhooks[i].triggers");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("webhooks[i].triggers[j]");
            j = j + 1;
            }

        i = i + 1;
        }


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Curl Command

curl -X GET
	-u 'username:password'
https://domain.com/v2/apps/{{appId}}/integrations/:integrationId/webhooks

Postman Collection Item JSON

{
  "name": "List Webhooks",
  "_postman_id": "e26b4273-eac6-45b0-b422-94a66032e924",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{url}}/v2/apps/{{appId}}/integrations/:integrationId/webhooks",
      "host": [
        "{{url}}"
      ],
      "path": [
        "v2",
        "apps",
        "{{appId}}",
        "integrations",
        ":integrationId",
        "webhooks"
      ],
      "variable": [
        {
          "key": "integrationId"
        }
      ]
    },
    "description": "Lists all webhooks for a given Sunshine Conversations Connect integration or custom integration."
  },
  "response": [
    {
      "id": "07913ccc-e1de-4d52-8a75-1996f5ee1106",
      "name": "Not Found",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/integrations/:integrationId/webhooks",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "integrations",
            ":integrationId",
            "webhooks"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "integrationId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "id": "9b583b6f-3cf6-4262-bcf0-35f341f3be42",
      "name": "Ok",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/integrations/:integrationId/webhooks",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "integrations",
            ":integrationId",
            "webhooks"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "integrationId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"webhooks\": [\n  {\n   \"target\": \"http://example.com/callback\",\n   \"triggers\": [\n    \"conversation:read\",\n    \"conversation:message\"\n   ],\n   \"id\": \"5e554d2cac66fb73a3c01871\",\n   \"version\": \"v2\",\n   \"secret\": \"8564b3e6a8b20a4bdb68b05ce9bc5936\",\n   \"includeFullUser\": false,\n   \"includeFullSource\": false\n  },\n  {\n   \"target\": \"http://example.com/callback\",\n   \"triggers\": [\n    \"conversation:read\",\n    \"conversation:message\"\n   ],\n   \"id\": \"5e554d2cac66fb73a3c01871\",\n   \"version\": \"v2\",\n   \"secret\": \"8564b3e6a8b20a4bdb68b05ce9bc5936\",\n   \"includeFullUser\": false,\n   \"includeFullSource\": false\n  }\n ]\n}"
    },
    {
      "id": "b879b53a-38da-4d6c-b0ad-7a230406ee86",
      "name": "Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/integrations/:integrationId/webhooks",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "integrations",
            ":integrationId",
            "webhooks"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "integrationId"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}