Chilkat Online Tools

DataFlex / Datadog API Collection / Create a child organization

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sStrVal
    String sCreated
    String sCreated_by
    String sKey
    String sName
    String sHash
    String sApplication_keyName
    String sOwner
    String sV_Type
    String sOrgCreated
    String sDescription
    String sOrgName
    String sPublic_id
    Boolean iPrivate_widget_share
    Boolean iEnabled
    String sSaml_autocreate_access_role
    Boolean iSaml_autocreate_users_domainsEnabled
    Boolean iSaml_can_be_enabled
    String sSaml_idp_endpoint
    Boolean iSaml_idp_initiated_loginEnabled
    Boolean iSaml_idp_metadata_uploaded
    String sSaml_login_url
    Boolean iSaml_strict_modeEnabled
    String sSubscriptionType
    Boolean iTrial
    String sAccess_role
    Boolean iDisabled
    String sV_Email
    String sHandle
    String sIcon
    String sUserName
    Boolean iVerified
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "name" "New child org" To iSuccess
    Get ComUpdateString Of hoJson "billing.type" "parent_billing" To iSuccess
    Get ComUpdateString Of hoJson "subscription.type" "pro" To iSuccess

    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.app.ddog-gov.com/api/v1/org" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    Get ComStringOf Of hoJResp "api_key.created" To sCreated
    Get ComStringOf Of hoJResp "api_key.created_by" To sCreated_by
    Get ComStringOf Of hoJResp "api_key.key" To sKey
    Get ComStringOf Of hoJResp "api_key.name" To sName
    Get ComStringOf Of hoJResp "application_key.hash" To sHash
    Get ComStringOf Of hoJResp "application_key.name" To sApplication_keyName
    Get ComStringOf Of hoJResp "application_key.owner" To sOwner
    Get ComStringOf Of hoJResp "org.billing.type" To sV_Type
    Get ComStringOf Of hoJResp "org.created" To sOrgCreated
    Get ComStringOf Of hoJResp "org.description" To sDescription
    Get ComStringOf Of hoJResp "org.name" To sOrgName
    Get ComStringOf Of hoJResp "org.public_id" To sPublic_id
    Get ComBoolOf Of hoJResp "org.settings.private_widget_share" To iPrivate_widget_share
    Get ComBoolOf Of hoJResp "org.settings.saml.enabled" To iEnabled
    Get ComStringOf Of hoJResp "org.settings.saml_autocreate_access_role" To sSaml_autocreate_access_role
    Get ComBoolOf Of hoJResp "org.settings.saml_autocreate_users_domains.enabled" To iSaml_autocreate_users_domainsEnabled
    Get ComBoolOf Of hoJResp "org.settings.saml_can_be_enabled" To iSaml_can_be_enabled
    Get ComStringOf Of hoJResp "org.settings.saml_idp_endpoint" To sSaml_idp_endpoint
    Get ComBoolOf Of hoJResp "org.settings.saml_idp_initiated_login.enabled" To iSaml_idp_initiated_loginEnabled
    Get ComBoolOf Of hoJResp "org.settings.saml_idp_metadata_uploaded" To iSaml_idp_metadata_uploaded
    Get ComStringOf Of hoJResp "org.settings.saml_login_url" To sSaml_login_url
    Get ComBoolOf Of hoJResp "org.settings.saml_strict_mode.enabled" To iSaml_strict_modeEnabled
    Get ComStringOf Of hoJResp "org.subscription.type" To sSubscriptionType
    Get ComBoolOf Of hoJResp "org.trial" To iTrial
    Get ComStringOf Of hoJResp "user.access_role" To sAccess_role
    Get ComBoolOf Of hoJResp "user.disabled" To iDisabled
    Get ComStringOf Of hoJResp "user.email" To sV_Email
    Get ComStringOf Of hoJResp "user.handle" To sHandle
    Get ComStringOf Of hoJResp "user.icon" To sIcon
    Get ComStringOf Of hoJResp "user.name" To sUserName
    Get ComBoolOf Of hoJResp "user.verified" To iVerified
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "org.settings.saml_autocreate_users_domains.domains" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "org.settings.saml_autocreate_users_domains.domains[i]" To sStrVal
        Move (i + 1) To i
    Loop



End_Procedure

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