Chilkat Online Tools

SQL Server / Datadog API Collection / List your managed organizations

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.app.ddog-gov.com/api/v1/org', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

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

    DECLARE @v_Type nvarchar(4000)

    DECLARE @created nvarchar(4000)

    DECLARE @description nvarchar(4000)

    DECLARE @name nvarchar(4000)

    DECLARE @public_id nvarchar(4000)

    DECLARE @Private_widget_share int

    DECLARE @Enabled int

    DECLARE @Saml_autocreate_access_role nvarchar(4000)

    DECLARE @Saml_autocreate_users_domainsEnabled int

    DECLARE @Saml_can_be_enabled int

    DECLARE @Saml_idp_endpoint nvarchar(4000)

    DECLARE @Saml_idp_initiated_loginEnabled int

    DECLARE @Saml_idp_metadata_uploaded int

    DECLARE @Saml_login_url nvarchar(4000)

    DECLARE @Saml_strict_modeEnabled int

    DECLARE @subscriptionType nvarchar(4000)

    DECLARE @trial int

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @strVal nvarchar(4000)

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'orgs'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'orgs[i].billing.type'
        EXEC sp_OAMethod @jResp, 'StringOf', @created OUT, 'orgs[i].created'
        EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'orgs[i].description'
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'orgs[i].name'
        EXEC sp_OAMethod @jResp, 'StringOf', @public_id OUT, 'orgs[i].public_id'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Private_widget_share OUT, 'orgs[i].settings.private_widget_share'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Enabled OUT, 'orgs[i].settings.saml.enabled'
        EXEC sp_OAMethod @jResp, 'StringOf', @Saml_autocreate_access_role OUT, 'orgs[i].settings.saml_autocreate_access_role'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_autocreate_users_domainsEnabled OUT, 'orgs[i].settings.saml_autocreate_users_domains.enabled'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_can_be_enabled OUT, 'orgs[i].settings.saml_can_be_enabled'
        EXEC sp_OAMethod @jResp, 'StringOf', @Saml_idp_endpoint OUT, 'orgs[i].settings.saml_idp_endpoint'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_idp_initiated_loginEnabled OUT, 'orgs[i].settings.saml_idp_initiated_login.enabled'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_idp_metadata_uploaded OUT, 'orgs[i].settings.saml_idp_metadata_uploaded'
        EXEC sp_OAMethod @jResp, 'StringOf', @Saml_login_url OUT, 'orgs[i].settings.saml_login_url'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_strict_modeEnabled OUT, 'orgs[i].settings.saml_strict_mode.enabled'
        EXEC sp_OAMethod @jResp, 'StringOf', @subscriptionType OUT, 'orgs[i].subscription.type'
        EXEC sp_OAMethod @jResp, 'BoolOf', @trial OUT, 'orgs[i].trial'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'orgs[i].settings.saml_autocreate_users_domains.domains'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'orgs[i].settings.saml_autocreate_users_domains.domains[j]'
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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