Swift3 / Datadog API Collection / Create a new entry for your service account
Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var success: Bool
// 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"
// }
// }
let json = CkoJsonObject()!
json.update("data.attributes.automute", value: "<boolean>")
json.update("data.attributes.client_email", value: "<string>")
json.update("data.attributes.host_filters[0]", value: "<string>")
json.update("data.attributes.host_filters[1]", value: "<string>")
json.update("data.attributes.is_cspm_enabled", value: "<boolean>")
json.update("data.type", value: "gcp_service_account")
http.setRequestHeader("Content-Type", value: "application/json")
http.setRequestHeader("Accept", value: "application/json")
var resp: CkoHttpResponse? = http.postJson3("https://api.app.ddog-gov.com/api/v2/integration/gcp/accounts", contentType: "application/json", json: json)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
let sbResponseBody = CkoStringBuilder()!
resp!.getBodySb(sbResponseBody)
let jResp = CkoJsonObject()!
jResp.loadSb(sbResponseBody)
jResp.emitCompact = false
print("Response Body:")
print("\(jResp.emit()!)")
var respStatusCode: Int = resp!.statusCode.intValue
print("Response Status Code = \(respStatusCode)")
if respStatusCode >= 400 {
print("Response Header:")
print("\(resp!.header!)")
print("Failed.")
resp = nil
return
}
resp = nil
// 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
var strVal: String?
var Automute: String? = jResp.string(of: "data.attributes.automute")
var Client_email: String? = jResp.string(of: "data.attributes.client_email")
var Is_cspm_enabled: String? = jResp.string(of: "data.attributes.is_cspm_enabled")
var Id: String? = jResp.string(of: "data.id")
var v_Type: String? = jResp.string(of: "data.type")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "data.attributes.host_filters").intValue
while i < count_i {
jResp.i = i
strVal = jResp.string(of: "data.attributes.host_filters[i]")
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "data.meta.accessible_projects").intValue
while i < count_i {
jResp.i = i
strVal = jResp.string(of: "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}"
}
]
}