Chilkat Online Tools

C# / Datadog API Collection / Update IP Allowlist

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": {
//     "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>"
//   }
// }

Chilkat.JsonObject json = new Chilkat.JsonObject();
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");

Chilkat.StringBuilder sbRequestBody = new Chilkat.StringBuilder();
json.EmitSb(sbRequestBody);

Chilkat.HttpResponse 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) {
    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": {
//     "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

string dataType;
string Cidr_block;
string Created_at;
string Modified_at;
string Note;
string dataId;

string v_Type = jResp.StringOf("data.type");
string Enabled = jResp.StringOf("data.attributes.enabled");
string Id = jResp.StringOf("data.id");
int i = 0;
int count_i = jResp.SizeOfArray("data.attributes.entries");
while (i < count_i) {
    jResp.I = 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;
}

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}"
    }
  ]
}