Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *name;
const wchar_t *url;
const wchar_t *custom_headers;
const wchar_t *encode_as;
const wchar_t *payload;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "name": "WEBHOOK_NAME",
// "url": "https://example.com/webhook",
// "custom_headers": "id veniam consectetur ullamco",
// "encode_as": "json",
// "payload": "do offi"
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"name",L"WEBHOOK_NAME");
CkJsonObjectW_UpdateString(json,L"url",L"https://example.com/webhook");
CkJsonObjectW_UpdateString(json,L"custom_headers",L"id veniam consectetur ullamco");
CkJsonObjectW_UpdateString(json,L"encode_as",L"json");
CkJsonObjectW_UpdateString(json,L"payload",L"do offi");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
resp = CkHttpW_PostJson3(http,L"https://api.app.ddog-gov.com/api/v1/integration/webhooks/configuration/webhooks",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
return;
}
sbResponseBody = CkStringBuilderW_Create();
CkHttpResponseW_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpResponseW_getStatusCode(resp);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpResponseW_header(resp));
wprintf(L"Failed.\n");
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
CkHttpResponseW_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "name": "WEBHOOK_NAME",
// "url": "https://example.com/webhook",
// "custom_headers": "id veniam consectetur ullamco",
// "encode_as": "json",
// "payload": "do offi"
// }
// 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.
name = CkJsonObjectW_stringOf(jResp,L"name");
url = CkJsonObjectW_stringOf(jResp,L"url");
custom_headers = CkJsonObjectW_stringOf(jResp,L"custom_headers");
encode_as = CkJsonObjectW_stringOf(jResp,L"encode_as");
payload = CkJsonObjectW_stringOf(jResp,L"payload");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"name": "WEBHOOK_NAME",
"url": "https://example.com/webhook",
"custom_headers": "id veniam consectetur ullamco",
"encode_as": "json",
"payload": "do offi"
}'
https://api.app.ddog-gov.com/api/v1/integration/webhooks/configuration/webhooks
Postman Collection Item JSON
{
"name": "Create a webhooks integration",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"WEBHOOK_NAME\",\n \"url\": \"https://example.com/webhook\",\n \"custom_headers\": \"id veniam consectetur ullamco\",\n \"encode_as\": \"json\",\n \"payload\": \"do offi\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/integration/webhooks/configuration/webhooks",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"integration",
"webhooks",
"configuration",
"webhooks"
]
},
"description": "Creates an endpoint with the name `<WEBHOOK_NAME>`."
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"WEBHOOK_NAME\",\n \"url\": \"https://example.com/webhook\",\n \"custom_headers\": \"id veniam consectetur ullamco\",\n \"encode_as\": \"json\",\n \"payload\": \"do offi\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/integration/webhooks/configuration/webhooks",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"integration",
"webhooks",
"configuration",
"webhooks"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"name\": \"WEBHOOK_NAME\",\n \"url\": \"https://example.com/webhook\",\n \"custom_headers\": \"id veniam consectetur ullamco\",\n \"encode_as\": \"json\",\n \"payload\": \"do offi\"\n}"
},
{
"name": "Bad Request",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"WEBHOOK_NAME\",\n \"url\": \"https://example.com/webhook\",\n \"custom_headers\": \"id veniam consectetur ullamco\",\n \"encode_as\": \"json\",\n \"payload\": \"do offi\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/integration/webhooks/configuration/webhooks",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"integration",
"webhooks",
"configuration",
"webhooks"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Authentication error",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"WEBHOOK_NAME\",\n \"url\": \"https://example.com/webhook\",\n \"custom_headers\": \"id veniam consectetur ullamco\",\n \"encode_as\": \"json\",\n \"payload\": \"do offi\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/integration/webhooks/configuration/webhooks",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"integration",
"webhooks",
"configuration",
"webhooks"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Too many requests",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"WEBHOOK_NAME\",\n \"url\": \"https://example.com/webhook\",\n \"custom_headers\": \"id veniam consectetur ullamco\",\n \"encode_as\": \"json\",\n \"payload\": \"do offi\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/integration/webhooks/configuration/webhooks",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"integration",
"webhooks",
"configuration",
"webhooks"
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
}
]
}