Chilkat Online Tools

PowerBuilder / Datadog API Collection / Update IP Allowlist

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_DataType
string ls_Cidr_block
string ls_Created_at
string ls_Modified_at
string ls_Note
string ls_DataId
string ls_V_Type
string ls_Enabled
string ls_Id
integer i
integer li_Count_i

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("data.type","ip_allowlist")
loo_Json.UpdateString("data.attributes.enabled","<boolean>")
loo_Json.UpdateString("data.attributes.entries[0].data.type","ip_allowlist_entry")
loo_Json.UpdateString("data.attributes.entries[0].data.attributes.cidr_block","<string>")
loo_Json.UpdateString("data.attributes.entries[0].data.attributes.created_at","<dateTime>")
loo_Json.UpdateString("data.attributes.entries[0].data.attributes.modified_at","<dateTime>")
loo_Json.UpdateString("data.attributes.entries[0].data.attributes.note","<string>")
loo_Json.UpdateString("data.attributes.entries[0].data.id","<string>")
loo_Json.UpdateString("data.attributes.entries[1].data.type","ip_allowlist_entry")
loo_Json.UpdateString("data.attributes.entries[1].data.attributes.cidr_block","<string>")
loo_Json.UpdateString("data.attributes.entries[1].data.attributes.created_at","<dateTime>")
loo_Json.UpdateString("data.attributes.entries[1].data.attributes.modified_at","<dateTime>")
loo_Json.UpdateString("data.attributes.entries[1].data.attributes.note","<string>")
loo_Json.UpdateString("data.attributes.entries[1].data.id","<string>")
loo_Json.UpdateString("data.id","<string>")

loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Http.SetRequestHeader("Accept","application/json")

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Json.EmitSb(loo_SbRequestBody)

loo_Resp = loo_Http.PTextSb("PATCH","https://api.app.ddog-gov.com/api/v2/ip_allowlist",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbRequestBody
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_Resp

// 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

ls_V_Type = loo_JResp.StringOf("data.type")
ls_Enabled = loo_JResp.StringOf("data.attributes.enabled")
ls_Id = loo_JResp.StringOf("data.id")
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.attributes.entries")
do while i < li_Count_i
    loo_JResp.I = i
    ls_DataType = loo_JResp.StringOf("data.attributes.entries[i].data.type")
    ls_Cidr_block = loo_JResp.StringOf("data.attributes.entries[i].data.attributes.cidr_block")
    ls_Created_at = loo_JResp.StringOf("data.attributes.entries[i].data.attributes.created_at")
    ls_Modified_at = loo_JResp.StringOf("data.attributes.entries[i].data.attributes.modified_at")
    ls_Note = loo_JResp.StringOf("data.attributes.entries[i].data.attributes.note")
    ls_DataId = loo_JResp.StringOf("data.attributes.entries[i].data.id")
    i = i + 1
loop


destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JResp

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