Chilkat Online Tools

SQL Server / Datadog API Collection / Get organization information

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/:public_id', @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)

    -- {
    --   "org": {
    --     "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 @strVal nvarchar(4000)

    DECLARE @v_Type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'org.billing.type'
    DECLARE @Created nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Created OUT, 'org.created'
    DECLARE @Description nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'org.description'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'org.name'
    DECLARE @Public_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Public_id OUT, 'org.public_id'
    DECLARE @Private_widget_share int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Private_widget_share OUT, 'org.settings.private_widget_share'
    DECLARE @Enabled int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Enabled OUT, 'org.settings.saml.enabled'
    DECLARE @Saml_autocreate_access_role nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Saml_autocreate_access_role OUT, 'org.settings.saml_autocreate_access_role'
    DECLARE @Saml_autocreate_users_domainsEnabled int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_autocreate_users_domainsEnabled OUT, 'org.settings.saml_autocreate_users_domains.enabled'
    DECLARE @Saml_can_be_enabled int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_can_be_enabled OUT, 'org.settings.saml_can_be_enabled'
    DECLARE @Saml_idp_endpoint nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Saml_idp_endpoint OUT, 'org.settings.saml_idp_endpoint'
    DECLARE @Saml_idp_initiated_loginEnabled int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_idp_initiated_loginEnabled OUT, 'org.settings.saml_idp_initiated_login.enabled'
    DECLARE @Saml_idp_metadata_uploaded int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_idp_metadata_uploaded OUT, 'org.settings.saml_idp_metadata_uploaded'
    DECLARE @Saml_login_url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Saml_login_url OUT, 'org.settings.saml_login_url'
    DECLARE @Saml_strict_modeEnabled int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Saml_strict_modeEnabled OUT, 'org.settings.saml_strict_mode.enabled'
    DECLARE @SubscriptionType nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @SubscriptionType OUT, 'org.subscription.type'
    DECLARE @Trial int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Trial OUT, 'org.trial'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'org.settings.saml_autocreate_users_domains.domains'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'org.settings.saml_autocreate_users_domains.domains[i]'
        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/:public_id

Postman Collection Item JSON

{
  "name": "Get organization information",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/org/:public_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "org",
        ":public_id"
      ],
      "variable": [
        {
          "key": "public_id",
          "value": "abc123"
        }
      ]
    },
    "description": "Get organization information."
  },
  "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/:public_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "org",
            ":public_id"
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"org\": {\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}"
    },
    {
      "name": "Bad Request",
      "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/:public_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "org",
            ":public_id"
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\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/:public_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "org",
            ":public_id"
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "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/:public_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "org",
            ":public_id"
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "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}"
    }
  ]
}