C# / Datadog API Collection / Create a new entry for your service account
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;
// 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"
// }
// }
Chilkat.JsonObject json = new Chilkat.JsonObject();
json.UpdateString("data.attributes.automute","<boolean>");
json.UpdateString("data.attributes.client_email","<string>");
json.UpdateString("data.attributes.host_filters[0]","<string>");
json.UpdateString("data.attributes.host_filters[1]","<string>");
json.UpdateString("data.attributes.is_cspm_enabled","<boolean>");
json.UpdateString("data.type","gcp_service_account");
http.SetRequestHeader("Content-Type","application/json");
http.SetRequestHeader("Accept","application/json");
Chilkat.HttpResponse resp = http.PostJson3("https://api.app.ddog-gov.com/api/v2/integration/gcp/accounts","application/json",json);
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)
// {
// "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
string strVal;
string Automute = jResp.StringOf("data.attributes.automute");
string Client_email = jResp.StringOf("data.attributes.client_email");
string Is_cspm_enabled = jResp.StringOf("data.attributes.is_cspm_enabled");
string Id = jResp.StringOf("data.id");
string v_Type = jResp.StringOf("data.type");
int i = 0;
int count_i = jResp.SizeOfArray("data.attributes.host_filters");
while (i < count_i) {
jResp.I = i;
strVal = jResp.StringOf("data.attributes.host_filters[i]");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray("data.meta.accessible_projects");
while (i < count_i) {
jResp.I = i;
strVal = jResp.StringOf("data.meta.accessible_projects[i]");
i = i + 1;
}
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}"
}
]
}