Chilkat Online Tools

PureBasic / Datadog API Collection / List your managed organizations

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://api.app.ddog-gov.com/api/v1/org",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    ; Sample JSON response:
    ; (Sample code for parsing the JSON response is shown below)

    ; {
    ;   "orgs": [
    ;     {
    ;       "billing": {
    ;         "type": "parent_billing"
    ;       },
    ;       "created": "2019-09-26T17:28:28Z",
    ;       "description": "some description",
    ;       "name": "New child org",
    ;       "public_id": "abcdef12345",
    ;       "settings": {
    ;         "private_widget_share": false,
    ;         "saml": {
    ;           "enabled": false
    ;         },
    ;         "saml_autocreate_access_role": "ro",
    ;         "saml_autocreate_users_domains": {
    ;           "domains": [
    ;             "example.com",
    ;             "example.com"
    ;           ],
    ;           "enabled": false
    ;         },
    ;         "saml_can_be_enabled": false,
    ;         "saml_idp_endpoint": "https://my.saml.endpoint",
    ;         "saml_idp_initiated_login": {
    ;           "enabled": false
    ;         },
    ;         "saml_idp_metadata_uploaded": false,
    ;         "saml_login_url": "https://my.saml.login.url",
    ;         "saml_strict_mode": {
    ;           "enabled": false
    ;         }
    ;       },
    ;       "subscription": {
    ;         "type": "pro"
    ;       },
    ;       "trial": false
    ;     },
    ;     {
    ;       "billing": {
    ;         "type": "parent_billing"
    ;       },
    ;       "created": "2019-09-26T17:28:28Z",
    ;       "description": "some description",
    ;       "name": "New child org",
    ;       "public_id": "abcdef12345",
    ;       "settings": {
    ;         "private_widget_share": false,
    ;         "saml": {
    ;           "enabled": false
    ;         },
    ;         "saml_autocreate_access_role": "ro",
    ;         "saml_autocreate_users_domains": {
    ;           "domains": [
    ;             "example.com",
    ;             "example.com"
    ;           ],
    ;           "enabled": false
    ;         },
    ;         "saml_can_be_enabled": false,
    ;         "saml_idp_endpoint": "https://my.saml.endpoint",
    ;         "saml_idp_initiated_login": {
    ;           "enabled": false
    ;         },
    ;         "saml_idp_metadata_uploaded": false,
    ;         "saml_login_url": "https://my.saml.login.url",
    ;         "saml_strict_mode": {
    ;           "enabled": false
    ;         }
    ;       },
    ;       "subscription": {
    ;         "type": "pro"
    ;       },
    ;       "trial": false
    ;     }
    ;   ]
    ; }

    ; Sample code for parsing the JSON response...
    ; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    v_Type.s
    created.s
    description.s
    name.s
    public_id.s
    Private_widget_share.i
    Enabled.i
    Saml_autocreate_access_role.s
    Saml_autocreate_users_domainsEnabled.i
    Saml_can_be_enabled.i
    Saml_idp_endpoint.s
    Saml_idp_initiated_loginEnabled.i
    Saml_idp_metadata_uploaded.i
    Saml_login_url.s
    Saml_strict_modeEnabled.i
    subscriptionType.s
    trial.i
    j.i
    count_j.i
    strVal.s

    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"orgs")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        v_Type = CkJsonObject::ckStringOf(jResp,"orgs[i].billing.type")
        created = CkJsonObject::ckStringOf(jResp,"orgs[i].created")
        description = CkJsonObject::ckStringOf(jResp,"orgs[i].description")
        name = CkJsonObject::ckStringOf(jResp,"orgs[i].name")
        public_id = CkJsonObject::ckStringOf(jResp,"orgs[i].public_id")
        Private_widget_share = CkJsonObject::ckBoolOf(jResp,"orgs[i].settings.private_widget_share")
        Enabled = CkJsonObject::ckBoolOf(jResp,"orgs[i].settings.saml.enabled")
        Saml_autocreate_access_role = CkJsonObject::ckStringOf(jResp,"orgs[i].settings.saml_autocreate_access_role")
        Saml_autocreate_users_domainsEnabled = CkJsonObject::ckBoolOf(jResp,"orgs[i].settings.saml_autocreate_users_domains.enabled")
        Saml_can_be_enabled = CkJsonObject::ckBoolOf(jResp,"orgs[i].settings.saml_can_be_enabled")
        Saml_idp_endpoint = CkJsonObject::ckStringOf(jResp,"orgs[i].settings.saml_idp_endpoint")
        Saml_idp_initiated_loginEnabled = CkJsonObject::ckBoolOf(jResp,"orgs[i].settings.saml_idp_initiated_login.enabled")
        Saml_idp_metadata_uploaded = CkJsonObject::ckBoolOf(jResp,"orgs[i].settings.saml_idp_metadata_uploaded")
        Saml_login_url = CkJsonObject::ckStringOf(jResp,"orgs[i].settings.saml_login_url")
        Saml_strict_modeEnabled = CkJsonObject::ckBoolOf(jResp,"orgs[i].settings.saml_strict_mode.enabled")
        subscriptionType = CkJsonObject::ckStringOf(jResp,"orgs[i].subscription.type")
        trial = CkJsonObject::ckBoolOf(jResp,"orgs[i].trial")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"orgs[i].settings.saml_autocreate_users_domains.domains")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            strVal = CkJsonObject::ckStringOf(jResp,"orgs[i].settings.saml_autocreate_users_domains.domains[j]")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -X GET
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/org

Postman Collection Item JSON

{
  "name": "List your managed organizations",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/org",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "org"
      ]
    },
    "description": "This endpoint returns data on your top-level organization."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/org",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "org"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"orgs\": [\n    {\n      \"billing\": {\n        \"type\": \"parent_billing\"\n      },\n      \"created\": \"2019-09-26T17:28:28Z\",\n      \"description\": \"some description\",\n      \"name\": \"New child org\",\n      \"public_id\": \"abcdef12345\",\n      \"settings\": {\n        \"private_widget_share\": false,\n        \"saml\": {\n          \"enabled\": false\n        },\n        \"saml_autocreate_access_role\": \"ro\",\n        \"saml_autocreate_users_domains\": {\n          \"domains\": [\n            \"example.com\",\n            \"example.com\"\n          ],\n          \"enabled\": false\n        },\n        \"saml_can_be_enabled\": false,\n        \"saml_idp_endpoint\": \"https://my.saml.endpoint\",\n        \"saml_idp_initiated_login\": {\n          \"enabled\": false\n        },\n        \"saml_idp_metadata_uploaded\": false,\n        \"saml_login_url\": \"https://my.saml.login.url\",\n        \"saml_strict_mode\": {\n          \"enabled\": false\n        }\n      },\n      \"subscription\": {\n        \"type\": \"pro\"\n      },\n      \"trial\": false\n    },\n    {\n      \"billing\": {\n        \"type\": \"parent_billing\"\n      },\n      \"created\": \"2019-09-26T17:28:28Z\",\n      \"description\": \"some description\",\n      \"name\": \"New child org\",\n      \"public_id\": \"abcdef12345\",\n      \"settings\": {\n        \"private_widget_share\": false,\n        \"saml\": {\n          \"enabled\": false\n        },\n        \"saml_autocreate_access_role\": \"ro\",\n        \"saml_autocreate_users_domains\": {\n          \"domains\": [\n            \"example.com\",\n            \"example.com\"\n          ],\n          \"enabled\": false\n        },\n        \"saml_can_be_enabled\": false,\n        \"saml_idp_endpoint\": \"https://my.saml.endpoint\",\n        \"saml_idp_initiated_login\": {\n          \"enabled\": false\n        },\n        \"saml_idp_metadata_uploaded\": false,\n        \"saml_login_url\": \"https://my.saml.login.url\",\n        \"saml_strict_mode\": {\n          \"enabled\": false\n        }\n      },\n      \"subscription\": {\n        \"type\": \"pro\"\n      },\n      \"trial\": false\n    }\n  ]\n}"
    },
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/org",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "org"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    },
    {
      "name": "Too many requests",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/org",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "org"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    }
  ]
}