Chilkat Online Tools

C# / Sunshine Conversations API / Update Webhook

Back to Collection Items

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

Chilkat.Http http = new Chilkat.Http();
bool success;

http.BasicAuth = true;
http.Login = "username";
http.Password = "password";

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "target": "http://example.com/callback",
//   "triggers": [
//     "conversation:read",
//     "conversation:message"
//   ],
//   "includeFullUser": false,
//   "includeFullSource": false
// }

Chilkat.JsonObject json = new Chilkat.JsonObject();
json.UpdateString("target","http://example.com/callback");
json.UpdateString("triggers[0]","conversation:read");
json.UpdateString("triggers[1]","conversation:message");
json.UpdateBool("includeFullUser",false);
json.UpdateBool("includeFullSource",false);

http.SetRequestHeader("Content-Type","application/json");

Chilkat.StringBuilder sbRequestBody = new Chilkat.StringBuilder();
json.EmitSb(sbRequestBody);

Chilkat.HttpResponse resp = http.PTextSb("PATCH","https://domain.com/v2/apps/{{appId}}/integrations/:integrationId/webhooks/:webhookId",sbRequestBody,"utf-8","application/json",false,false);
if (http.LastMethodSuccess == false) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);

Chilkat.JsonObject jResp = new Chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;

Debug.WriteLine("Response Body:");
Debug.WriteLine(jResp.Emit());

int respStatusCode = resp.StatusCode;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(resp.Header);
    Debug.WriteLine("Failed.");

    return;
}

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

// {
//   "webhook": {
//     "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 strVal;

string Target = jResp.StringOf("webhook.target");
string Id = jResp.StringOf("webhook.id");
string Version = jResp.StringOf("webhook.version");
string Secret = jResp.StringOf("webhook.secret");
bool IncludeFullUser = jResp.BoolOf("webhook.includeFullUser");
bool IncludeFullSource = jResp.BoolOf("webhook.includeFullSource");
int i = 0;
int count_i = jResp.SizeOfArray("webhook.triggers");
while (i < count_i) {
    jResp.I = i;
    strVal = jResp.StringOf("webhook.triggers[i]");
    i = i + 1;
}

Curl Command

curl -X PATCH
	-u 'username:password'
	-H "Content-Type: application/json"
	-d '{
    "target": "http://example.com/callback",
    "triggers": [
        "conversation:read",
        "conversation:message"
    ],
    "includeFullUser": false,
    "includeFullSource": false
}'
https://domain.com/v2/apps/{{appId}}/integrations/:integrationId/webhooks/:webhookId

Postman Collection Item JSON

{
  "name": "Update Webhook",
  "_postman_id": "d32b1f08-8cc7-44be-b53f-4bc850509011",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"target\": \"http://example.com/callback\",\n    \"triggers\": [\n        \"conversation:read\",\n        \"conversation:message\"\n    ],\n    \"includeFullUser\": false,\n    \"includeFullSource\": false\n}"
    },
    "url": {
      "raw": "{{url}}/v2/apps/{{appId}}/integrations/:integrationId/webhooks/:webhookId",
      "host": [
        "{{url}}"
      ],
      "path": [
        "v2",
        "apps",
        "{{appId}}",
        "integrations",
        ":integrationId",
        "webhooks",
        ":webhookId"
      ],
      "variable": [
        {
          "key": "integrationId"
        },
        {
          "key": "webhookId"
        }
      ]
    },
    "description": "Updates the specified webhook associated with a Sunshine Conversations Connect integration or a custom integration."
  },
  "response": [
    {
      "id": "6655db9e-65db-4d6b-9fe0-1cdf14ba0f71",
      "name": "Not Found",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"target\": \"http://example.com/callback\",\n    \"triggers\": [\n        \"conversation:read\",\n        \"conversation:message\"\n    ],\n    \"includeFullUser\": false,\n    \"includeFullSource\": false\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/integrations/:integrationId/webhooks/:webhookId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "integrations",
            ":integrationId",
            "webhooks",
            ":webhookId"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "integrationId"
            },
            {
              "key": "webhookId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "id": "e026a537-ee30-4dee-8b19-20d16233ef80",
      "name": "Ok",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"target\": \"http://example.com/callback\",\n    \"triggers\": [\n        \"conversation:read\",\n        \"conversation:message\"\n    ],\n    \"includeFullUser\": false,\n    \"includeFullSource\": false\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/integrations/:integrationId/webhooks/:webhookId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "integrations",
            ":integrationId",
            "webhooks",
            ":webhookId"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "integrationId"
            },
            {
              "key": "webhookId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"webhook\": {\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}"
    },
    {
      "id": "e0bc5d65-e439-43b3-adc5-9afecf5cbc3a",
      "name": "Bad Request",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"target\": \"http://example.com/callback\",\n    \"triggers\": [\n        \"conversation:read\",\n        \"conversation:message\"\n    ],\n    \"includeFullUser\": false,\n    \"includeFullSource\": false\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/integrations/:integrationId/webhooks/:webhookId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "integrations",
            ":integrationId",
            "webhooks",
            ":webhookId"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "integrationId"
            },
            {
              "key": "webhookId"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}