Back to Collection Items
// This example assumes the Chilkat API to have been previously unlocked.
// See Global_Ref.html">Global Unlock Sample for sample code.
http := chilkat.NewHttp()
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": {
// "type": "ip_allowlist",
// "attributes": {
// "enabled": "<boolean>",
// "entries": [
// {
// "data": {
// "type": "ip_allowlist_entry",
// "attributes": {
// "cidr_block": "<string>",
// "created_at": "<dateTime>",
// "modified_at": "<dateTime>",
// "note": "<string>"
// },
// "id": "<string>"
// }
// },
// {
// "data": {
// "type": "ip_allowlist_entry",
// "attributes": {
// "cidr_block": "<string>",
// "created_at": "<dateTime>",
// "modified_at": "<dateTime>",
// "note": "<string>"
// },
// "id": "<string>"
// }
// }
// ]
// },
// "id": "<string>"
// }
// }
json := chilkat.NewJsonObject()
json.UpdateString("data.type","ip_allowlist")
json.UpdateString("data.attributes.enabled","<boolean>")
json.UpdateString("data.attributes.entries[0].data.type","ip_allowlist_entry")
json.UpdateString("data.attributes.entries[0].data.attributes.cidr_block","<string>")
json.UpdateString("data.attributes.entries[0].data.attributes.created_at","<dateTime>")
json.UpdateString("data.attributes.entries[0].data.attributes.modified_at","<dateTime>")
json.UpdateString("data.attributes.entries[0].data.attributes.note","<string>")
json.UpdateString("data.attributes.entries[0].data.id","<string>")
json.UpdateString("data.attributes.entries[1].data.type","ip_allowlist_entry")
json.UpdateString("data.attributes.entries[1].data.attributes.cidr_block","<string>")
json.UpdateString("data.attributes.entries[1].data.attributes.created_at","<dateTime>")
json.UpdateString("data.attributes.entries[1].data.attributes.modified_at","<dateTime>")
json.UpdateString("data.attributes.entries[1].data.attributes.note","<string>")
json.UpdateString("data.attributes.entries[1].data.id","<string>")
json.UpdateString("data.id","<string>")
http.SetRequestHeader("Content-Type","application/json")
http.SetRequestHeader("Accept","application/json")
sbRequestBody := chilkat.NewStringBuilder()
json.EmitSb(sbRequestBody)
resp := http.PTextSb("PATCH","https://api.app.ddog-gov.com/api/v2/ip_allowlist",sbRequestBody,"utf-8","application/json",false,false)
if http.LastMethodSuccess() == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
json.DisposeJsonObject()
sbRequestBody.DisposeStringBuilder()
return
}
sbResponseBody := chilkat.NewStringBuilder()
resp.GetBodySb(sbResponseBody)
jResp := chilkat.NewJsonObject()
jResp.LoadSb(sbResponseBody)
jResp.SetEmitCompact(false)
fmt.Println("Response Body:")
fmt.Println(*jResp.Emit())
respStatusCode := resp.StatusCode()
fmt.Println("Response Status Code = ", respStatusCode)
if respStatusCode >= 400 {
fmt.Println("Response Header:")
fmt.Println(resp.Header())
fmt.Println("Failed.")
resp.DisposeHttpResponse()
http.DisposeHttp()
json.DisposeJsonObject()
sbRequestBody.DisposeStringBuilder()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
return
}
resp.DisposeHttpResponse()
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "type": "ip_allowlist",
// "attributes": {
// "enabled": "<boolean>",
// "entries": [
// {
// "data": {
// "type": "ip_allowlist_entry",
// "attributes": {
// "cidr_block": "<string>",
// "created_at": "<dateTime>",
// "modified_at": "<dateTime>",
// "note": "<string>"
// },
// "id": "<string>"
// }
// },
// {
// "data": {
// "type": "ip_allowlist_entry",
// "attributes": {
// "cidr_block": "<string>",
// "created_at": "<dateTime>",
// "modified_at": "<dateTime>",
// "note": "<string>"
// },
// "id": "<string>"
// }
// }
// ]
// },
// "id": "<string>"
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
var dataType *string = new(string)
var Cidr_block *string = new(string)
var Created_at *string = new(string)
var Modified_at *string = new(string)
var Note *string = new(string)
data
v_Type := jResp.StringOf("data.type")
Enabled := jResp.StringOf("data.attributes.enabled")
Id := jResp.StringOf("data.id")
i := 0
count_i := jResp.SizeOfArray("data.attributes.entries")
for i < count_i {
jResp.SetI(i)
dataType = jResp.StringOf("data.attributes.entries[i].data.type")
Cidr_block = jResp.StringOf("data.attributes.entries[i].data.attributes.cidr_block")
Created_at = jResp.StringOf("data.attributes.entries[i].data.attributes.created_at")
Modified_at = jResp.StringOf("data.attributes.entries[i].data.attributes.modified_at")
Note = jResp.StringOf("data.attributes.entries[i].data.attributes.note")
dataId = jResp.StringOf("data.attributes.entries[i].data.id")
i = i + 1
}
http.DisposeHttp()
json.DisposeJsonObject()
sbRequestBody.DisposeStringBuilder()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
Curl Command
curl -X PATCH
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"data": {
"type": "ip_allowlist",
"attributes": {
"enabled": "<boolean>",
"entries": [
{
"data": {
"type": "ip_allowlist_entry",
"attributes": {
"cidr_block": "<string>",
"created_at": "<dateTime>",
"modified_at": "<dateTime>",
"note": "<string>"
},
"id": "<string>"
}
},
{
"data": {
"type": "ip_allowlist_entry",
"attributes": {
"cidr_block": "<string>",
"created_at": "<dateTime>",
"modified_at": "<dateTime>",
"note": "<string>"
},
"id": "<string>"
}
}
]
},
"id": "<string>"
}
}'
https://api.app.ddog-gov.com/api/v2/ip_allowlist
Postman Collection Item JSON
{
"name": "Update IP Allowlist",
"request": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"type\": \"ip_allowlist\",\n \"attributes\": {\n \"enabled\": \"<boolean>\",\n \"entries\": [\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n },\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n }\n ]\n },\n \"id\": \"<string>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/ip_allowlist",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"ip_allowlist"
]
},
"description": "Edit the entries in the IP allowlist, and enable or disable it."
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "PATCH",
"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 \"type\": \"ip_allowlist\",\n \"attributes\": {\n \"enabled\": \"<boolean>\",\n \"entries\": [\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n },\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n }\n ]\n },\n \"id\": \"<string>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/ip_allowlist",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"ip_allowlist"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"type\": \"ip_allowlist\",\n \"attributes\": {\n \"enabled\": \"<boolean>\",\n \"entries\": [\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n },\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n }\n ]\n },\n \"id\": \"<string>\"\n }\n}"
},
{
"name": "Bad Request",
"originalRequest": {
"method": "PATCH",
"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 \"type\": \"ip_allowlist\",\n \"attributes\": {\n \"enabled\": \"<boolean>\",\n \"entries\": [\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n },\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n }\n ]\n },\n \"id\": \"<string>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/ip_allowlist",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"ip_allowlist"
]
}
},
"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": "Forbidden",
"originalRequest": {
"method": "PATCH",
"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 \"type\": \"ip_allowlist\",\n \"attributes\": {\n \"enabled\": \"<boolean>\",\n \"entries\": [\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n },\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n }\n ]\n },\n \"id\": \"<string>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/ip_allowlist",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"ip_allowlist"
]
}
},
"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": "Not Found",
"originalRequest": {
"method": "PATCH",
"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 \"type\": \"ip_allowlist\",\n \"attributes\": {\n \"enabled\": \"<boolean>\",\n \"entries\": [\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n },\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n }\n ]\n },\n \"id\": \"<string>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/ip_allowlist",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"ip_allowlist"
]
}
},
"status": "Not Found",
"code": 404,
"_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": "PATCH",
"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 \"type\": \"ip_allowlist\",\n \"attributes\": {\n \"enabled\": \"<boolean>\",\n \"entries\": [\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n },\n {\n \"data\": {\n \"type\": \"ip_allowlist_entry\",\n \"attributes\": {\n \"cidr_block\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"modified_at\": \"<dateTime>\",\n \"note\": \"<string>\"\n },\n \"id\": \"<string>\"\n }\n }\n ]\n },\n \"id\": \"<string>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/ip_allowlist",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"ip_allowlist"
]
}
},
"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}"
}
]
}