Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkHttpResponseW resp;
// 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": "Platform API Postman Test 001",
// "severity": "INFO",
// "actions": [
// {
// "type": "email",
// "content": "Hello,\nYou are receiving this alert because:\nThe application ${resource} is now in an ${state} state, based on the condition 'memory ${operator} ${value}%'.",
// "subject": "${severity}: memory usage ${state}",
// "userIds": [
// "2909a63d-c57a-47b0-90f1-7ddfb815efba"
// ]
// }
// ],
// "condition": {
// "operator": "GREATER_THAN",
// "periodCount": 20,
// "value": 80,
// "resourceType": "cloudhub-application",
// "type": "memory",
// "periodMins": 1,
// "resources": [
// "*"
// ]
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"name",L"Platform API Postman Test 001");
CkJsonObjectW_UpdateString(json,L"severity",L"INFO");
CkJsonObjectW_UpdateString(json,L"actions[0].type",L"email");
CkJsonObjectW_UpdateString(json,L"actions[0].content",L"Hello,\nYou are receiving this alert because:\nThe application ${resource} is now in an ${state} state, based on the condition 'memory ${operator} ${value}%'.");
CkJsonObjectW_UpdateString(json,L"actions[0].subject",L"${severity}: memory usage ${state}");
CkJsonObjectW_UpdateString(json,L"actions[0].userIds[0]",L"2909a63d-c57a-47b0-90f1-7ddfb815efba");
CkJsonObjectW_UpdateString(json,L"condition.operator",L"GREATER_THAN");
CkJsonObjectW_UpdateInt(json,L"condition.periodCount",20);
CkJsonObjectW_UpdateInt(json,L"condition.value",80);
CkJsonObjectW_UpdateString(json,L"condition.resourceType",L"cloudhub-application");
CkJsonObjectW_UpdateString(json,L"condition.type",L"memory");
CkJsonObjectW_UpdateInt(json,L"condition.periodMins",1);
CkJsonObjectW_UpdateString(json,L"condition.resources[0]",L"*");
CkHttpW_SetRequestHeader(http,L"X-ANYPNT-ENV-ID",L"{{environment_id}}");
// Adds the "Authorization: Bearer {{token}}" header.
CkHttpW_putAuthToken(http,L"{{token}}");
CkHttpW_SetRequestHeader(http,L"X-ANYPNT-ORG-ID",L"{{organization_id}}");
resp = CkHttpW_PostJson3(http,L"https://domain.com/armui/api/v1/alerts/cloudhub",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
}
Curl Command
curl -X POST
-H "Authorization: Bearer {{token}}"
-H "X-ANYPNT-ORG-ID: {{organization_id}}"
-H "X-ANYPNT-ENV-ID: {{environment_id}}"
-d '{
"name": "Platform API Postman Test 001",
"severity": "INFO",
"actions": [
{
"type": "email",
"content": "Hello,\nYou are receiving this alert because:\nThe application ${resource} is now in an ${state} state, based on the condition \'memory ${operator} ${value}%\'.",
"subject": "${severity}: memory usage ${state}",
"userIds": [
"2909a63d-c57a-47b0-90f1-7ddfb815efba"
]
}
],
"condition": {
"operator": "GREATER_THAN",
"periodCount": 20,
"value": 80,
"resourceType": "cloudhub-application",
"type": "memory",
"periodMins": 1,
"resources": [
"*"
]
}
}'
https://domain.com/armui/api/v1/alerts/cloudhub
Postman Collection Item JSON
{
"name": "Create an alert",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{token}}",
"type": "text"
},
{
"key": "X-ANYPNT-ORG-ID",
"value": "{{organization_id}}",
"type": "text"
},
{
"key": "X-ANYPNT-ENV-ID",
"value": "{{environment_id}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"name\": \"Platform API Postman Test 001\",\r\n \"severity\": \"INFO\",\r\n \"actions\": [\r\n {\r\n \"type\": \"email\",\r\n \"content\": \"Hello,\\nYou are receiving this alert because:\\nThe application ${resource} is now in an ${state} state, based on the condition 'memory ${operator} ${value}%'.\",\r\n \"subject\": \"${severity}: memory usage ${state}\",\r\n \"userIds\": [\r\n \"2909a63d-c57a-47b0-90f1-7ddfb815efba\"\r\n ]\r\n }\r\n ],\r\n \"condition\": {\r\n \"operator\": \"GREATER_THAN\",\r\n \"periodCount\": 20,\r\n \"value\": 80,\r\n \"resourceType\": \"cloudhub-application\",\r\n \"type\": \"memory\",\r\n \"periodMins\": 1,\r\n \"resources\": [\r\n \"*\"\r\n ]\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/armui/api/v1/alerts/cloudhub",
"host": [
"{{url}}"
],
"path": [
"armui",
"api",
"v1",
"alerts",
"cloudhub"
]
}
},
"response": [
]
}