C / Datadog API Collection / Create a new entry for your service account
Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *strVal;
const char *Automute;
const char *Client_email;
const char *Is_cspm_enabled;
const char *Id;
const char *v_Type;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_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.
// {
// "data": {
// "attributes": {
// "automute": "<boolean>",
// "client_email": "<string>",
// "host_filters": [
// "<string>",
// "<string>"
// ],
// "is_cspm_enabled": "<boolean>"
// },
// "type": "gcp_service_account"
// }
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"data.attributes.automute","<boolean>");
CkJsonObject_UpdateString(json,"data.attributes.client_email","<string>");
CkJsonObject_UpdateString(json,"data.attributes.host_filters[0]","<string>");
CkJsonObject_UpdateString(json,"data.attributes.host_filters[1]","<string>");
CkJsonObject_UpdateString(json,"data.attributes.is_cspm_enabled","<boolean>");
CkJsonObject_UpdateString(json,"data.type","gcp_service_account");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
CkHttp_SetRequestHeader(http,"Accept","application/json");
resp = CkHttp_PostJson3(http,"https://api.app.ddog-gov.com/api/v2/integration/gcp/accounts","application/json",json);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "attributes": {
// "automute": "<boolean>",
// "client_email": "<string>",
// "host_filters": [
// "<string>",
// "<string>"
// ],
// "is_cspm_enabled": "<boolean>"
// },
// "id": "<string>",
// "meta": {
// "accessible_projects": [
// "<string>",
// "<string>"
// ]
// },
// "type": "gcp_service_account"
// }
// }
// 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.
Automute = CkJsonObject_stringOf(jResp,"data.attributes.automute");
Client_email = CkJsonObject_stringOf(jResp,"data.attributes.client_email");
Is_cspm_enabled = CkJsonObject_stringOf(jResp,"data.attributes.is_cspm_enabled");
Id = CkJsonObject_stringOf(jResp,"data.id");
v_Type = CkJsonObject_stringOf(jResp,"data.type");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"data.attributes.host_filters");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"data.attributes.host_filters[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"data.meta.accessible_projects");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"data.meta.accessible_projects[i]");
i = i + 1;
}
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"data": {
"attributes": {
"automute": "<boolean>",
"client_email": "<string>",
"host_filters": [
"<string>",
"<string>"
],
"is_cspm_enabled": "<boolean>"
},
"type": "gcp_service_account"
}
}'
https://api.app.ddog-gov.com/api/v2/integration/gcp/accounts
Postman Collection Item JSON
{
"name": "Create a new entry for your service account",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"automute\": \"<boolean>\",\n \"client_email\": \"<string>\",\n \"host_filters\": [\n \"<string>\",\n \"<string>\"\n ],\n \"is_cspm_enabled\": \"<boolean>\"\n },\n \"type\": \"gcp_service_account\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/integration/gcp/accounts",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"integration",
"gcp",
"accounts"
]
},
"description": "Create a new entry within Datadog for your STS enabled service account."
},
"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 \"data\": {\n \"attributes\": {\n \"automute\": \"<boolean>\",\n \"client_email\": \"<string>\",\n \"host_filters\": [\n \"<string>\",\n \"<string>\"\n ],\n \"is_cspm_enabled\": \"<boolean>\"\n },\n \"type\": \"gcp_service_account\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/integration/gcp/accounts",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"integration",
"gcp",
"accounts"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"attributes\": {\n \"automute\": \"<boolean>\",\n \"client_email\": \"<string>\",\n \"host_filters\": [\n \"<string>\",\n \"<string>\"\n ],\n \"is_cspm_enabled\": \"<boolean>\"\n },\n \"id\": \"<string>\",\n \"meta\": {\n \"accessible_projects\": [\n \"<string>\",\n \"<string>\"\n ]\n },\n \"type\": \"gcp_service_account\"\n }\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 \"data\": {\n \"attributes\": {\n \"automute\": \"<boolean>\",\n \"client_email\": \"<string>\",\n \"host_filters\": [\n \"<string>\",\n \"<string>\"\n ],\n \"is_cspm_enabled\": \"<boolean>\"\n },\n \"type\": \"gcp_service_account\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/integration/gcp/accounts",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"integration",
"gcp",
"accounts"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Unauthorized",
"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 \"data\": {\n \"attributes\": {\n \"automute\": \"<boolean>\",\n \"client_email\": \"<string>\",\n \"host_filters\": [\n \"<string>\",\n \"<string>\"\n ],\n \"is_cspm_enabled\": \"<boolean>\"\n },\n \"type\": \"gcp_service_account\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/integration/gcp/accounts",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"integration",
"gcp",
"accounts"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Not Authorized",
"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 \"data\": {\n \"attributes\": {\n \"automute\": \"<boolean>\",\n \"client_email\": \"<string>\",\n \"host_filters\": [\n \"<string>\",\n \"<string>\"\n ],\n \"is_cspm_enabled\": \"<boolean>\"\n },\n \"type\": \"gcp_service_account\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/integration/gcp/accounts",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"integration",
"gcp",
"accounts"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Conflict",
"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 \"data\": {\n \"attributes\": {\n \"automute\": \"<boolean>\",\n \"client_email\": \"<string>\",\n \"host_filters\": [\n \"<string>\",\n \"<string>\"\n ],\n \"is_cspm_enabled\": \"<boolean>\"\n },\n \"type\": \"gcp_service_account\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/integration/gcp/accounts",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"integration",
"gcp",
"accounts"
]
}
},
"status": "Conflict",
"code": 409,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\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 \"data\": {\n \"attributes\": {\n \"automute\": \"<boolean>\",\n \"client_email\": \"<string>\",\n \"host_filters\": [\n \"<string>\",\n \"<string>\"\n ],\n \"is_cspm_enabled\": \"<boolean>\"\n },\n \"type\": \"gcp_service_account\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/integration/gcp/accounts",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"integration",
"gcp",
"accounts"
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
}
]
}