Chilkat Online Tools

delphiDll / Datadog API Collection / Create a child organization

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
strVal: PWideChar;
Created: PWideChar;
Created_by: PWideChar;
Key: PWideChar;
Name: PWideChar;
Hash: PWideChar;
application_keyName: PWideChar;
Owner: PWideChar;
v_Type: PWideChar;
orgCreated: PWideChar;
Description: PWideChar;
orgName: PWideChar;
Public_id: PWideChar;
Private_widget_share: Boolean;
Enabled: Boolean;
Saml_autocreate_access_role: PWideChar;
Saml_autocreate_users_domainsEnabled: Boolean;
Saml_can_be_enabled: Boolean;
Saml_idp_endpoint: PWideChar;
Saml_idp_initiated_loginEnabled: Boolean;
Saml_idp_metadata_uploaded: Boolean;
Saml_login_url: PWideChar;
Saml_strict_modeEnabled: Boolean;
SubscriptionType: PWideChar;
Trial: Boolean;
Access_role: PWideChar;
Disabled: Boolean;
v_Email: PWideChar;
Handle: PWideChar;
Icon: PWideChar;
userName: PWideChar;
Verified: Boolean;
i: Integer;
count_i: Integer;

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

http := CkHttp_Create();

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "name": "New child org",
//   "billing": {
//     "type": "parent_billing"
//   },
//   "subscription": {
//     "type": "pro"
//   }
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'name','New child org');
CkJsonObject_UpdateString(json,'billing.type','parent_billing');
CkJsonObject_UpdateString(json,'subscription.type','pro');

CkHttp_SetRequestHeader(http,'Content-Type','application/json');
CkHttp_SetRequestHeader(http,'Accept','application/json');

resp := CkHttp_PostJson3(http,'https://api.app.ddog-gov.com/api/v1/org','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

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

// {
//   "api_key": {
//     "created": "2019-08-02 15:31:07",
//     "created_by": "john@example.com",
//     "key": "1234512345123456abcabc912349abcd",
//     "name": "example user"
//   },
//   "application_key": {
//     "hash": "1234512345123459cda4eb9ced49a3d84fd0138c",
//     "name": "example user",
//     "owner": "example.com"
//   },
//   "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
//   },
//   "user": {
//     "access_role": "ro",
//     "disabled": false,
//     "email": "test@datadoghq.com",
//     "handle": "test@datadoghq.com",
//     "icon": "/path/to/matching/gravatar/icon",
//     "name": "test user",
//     "verified": true
//   }
// }

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

Created := CkJsonObject__stringOf(jResp,'api_key.created');
Created_by := CkJsonObject__stringOf(jResp,'api_key.created_by');
Key := CkJsonObject__stringOf(jResp,'api_key.key');
Name := CkJsonObject__stringOf(jResp,'api_key.name');
Hash := CkJsonObject__stringOf(jResp,'application_key.hash');
application_keyName := CkJsonObject__stringOf(jResp,'application_key.name');
Owner := CkJsonObject__stringOf(jResp,'application_key.owner');
v_Type := CkJsonObject__stringOf(jResp,'org.billing.type');
orgCreated := CkJsonObject__stringOf(jResp,'org.created');
Description := CkJsonObject__stringOf(jResp,'org.description');
orgName := CkJsonObject__stringOf(jResp,'org.name');
Public_id := CkJsonObject__stringOf(jResp,'org.public_id');
Private_widget_share := CkJsonObject_BoolOf(jResp,'org.settings.private_widget_share');
Enabled := CkJsonObject_BoolOf(jResp,'org.settings.saml.enabled');
Saml_autocreate_access_role := CkJsonObject__stringOf(jResp,'org.settings.saml_autocreate_access_role');
Saml_autocreate_users_domainsEnabled := CkJsonObject_BoolOf(jResp,'org.settings.saml_autocreate_users_domains.enabled');
Saml_can_be_enabled := CkJsonObject_BoolOf(jResp,'org.settings.saml_can_be_enabled');
Saml_idp_endpoint := CkJsonObject__stringOf(jResp,'org.settings.saml_idp_endpoint');
Saml_idp_initiated_loginEnabled := CkJsonObject_BoolOf(jResp,'org.settings.saml_idp_initiated_login.enabled');
Saml_idp_metadata_uploaded := CkJsonObject_BoolOf(jResp,'org.settings.saml_idp_metadata_uploaded');
Saml_login_url := CkJsonObject__stringOf(jResp,'org.settings.saml_login_url');
Saml_strict_modeEnabled := CkJsonObject_BoolOf(jResp,'org.settings.saml_strict_mode.enabled');
SubscriptionType := CkJsonObject__stringOf(jResp,'org.subscription.type');
Trial := CkJsonObject_BoolOf(jResp,'org.trial');
Access_role := CkJsonObject__stringOf(jResp,'user.access_role');
Disabled := CkJsonObject_BoolOf(jResp,'user.disabled');
v_Email := CkJsonObject__stringOf(jResp,'user.email');
Handle := CkJsonObject__stringOf(jResp,'user.handle');
Icon := CkJsonObject__stringOf(jResp,'user.icon');
userName := CkJsonObject__stringOf(jResp,'user.name');
Verified := CkJsonObject_BoolOf(jResp,'user.verified');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'org.settings.saml_autocreate_users_domains.domains');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'org.settings.saml_autocreate_users_domains.domains[i]');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "name": "New child org",
  "billing": {
    "type": "parent_billing"
  },
  "subscription": {
    "type": "pro"
  }
}'
https://api.app.ddog-gov.com/api/v1/org

Postman Collection Item JSON

{
  "name": "Create a child organization",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"name\": \"New child org\",\n  \"billing\": {\n    \"type\": \"parent_billing\"\n  },\n  \"subscription\": {\n    \"type\": \"pro\"\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/org",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "org"
      ]
    },
    "description": "Create a child organization.\n\nThis endpoint requires the\n[multi-organization account](https://docs.datadoghq.com/account_management/multi_organization/)\nfeature and must be enabled by\n[contacting support](https://docs.datadoghq.com/help/).\n\nOnce a new child organization is created, you can interact with it\nby using the `org.public_id`, `api_key.key`, and\n`application_key.hash` provided in the response."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "POST",
        "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  \"name\": \"New child org\",\n  \"billing\": {\n    \"type\": \"parent_billing\"\n  },\n  \"subscription\": {\n    \"type\": \"pro\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "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  \"api_key\": {\n    \"created\": \"2019-08-02 15:31:07\",\n    \"created_by\": \"john@example.com\",\n    \"key\": \"1234512345123456abcabc912349abcd\",\n    \"name\": \"example user\"\n  },\n  \"application_key\": {\n    \"hash\": \"1234512345123459cda4eb9ced49a3d84fd0138c\",\n    \"name\": \"example user\",\n    \"owner\": \"example.com\"\n  },\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  \"user\": {\n    \"access_role\": \"ro\",\n    \"disabled\": false,\n    \"email\": \"test@datadoghq.com\",\n    \"handle\": \"test@datadoghq.com\",\n    \"icon\": \"/path/to/matching/gravatar/icon\",\n    \"name\": \"test user\",\n    \"verified\": true\n  }\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "POST",
        "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  \"name\": \"New child org\",\n  \"billing\": {\n    \"type\": \"parent_billing\"\n  },\n  \"subscription\": {\n    \"type\": \"pro\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/org",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "org"
          ]
        }
      },
      "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": "POST",
        "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  \"name\": \"New child org\",\n  \"billing\": {\n    \"type\": \"parent_billing\"\n  },\n  \"subscription\": {\n    \"type\": \"pro\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "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": "POST",
        "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  \"name\": \"New child org\",\n  \"billing\": {\n    \"type\": \"parent_billing\"\n  },\n  \"subscription\": {\n    \"type\": \"pro\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "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}"
    }
  ]
}