Chilkat Online Tools

unicodeC / Datadog API Collection / Update your organization

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *strVal;
    const wchar_t *v_Type;
    const wchar_t *Created;
    const wchar_t *Description;
    const wchar_t *Name;
    const wchar_t *Public_id;
    BOOL Private_widget_share;
    BOOL Enabled;
    const wchar_t *Saml_autocreate_access_role;
    BOOL Saml_autocreate_users_domainsEnabled;
    BOOL Saml_can_be_enabled;
    const wchar_t *Saml_idp_endpoint;
    BOOL Saml_idp_initiated_loginEnabled;
    BOOL Saml_idp_metadata_uploaded;
    const wchar_t *Saml_login_url;
    BOOL Saml_strict_modeEnabled;
    const wchar_t *SubscriptionType;
    BOOL Trial;
    int i;
    int count_i;

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

    http = CkHttpW_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.

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

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"billing.type",L"parent_billing");
    CkJsonObjectW_UpdateString(json,L"created",L"2019-09-26T17:28:28Z");
    CkJsonObjectW_UpdateString(json,L"description",L"some description");
    CkJsonObjectW_UpdateString(json,L"name",L"New child org");
    CkJsonObjectW_UpdateString(json,L"public_id",L"abcdef12345");
    CkJsonObjectW_UpdateBool(json,L"settings.private_widget_share",FALSE);
    CkJsonObjectW_UpdateBool(json,L"settings.saml.enabled",FALSE);
    CkJsonObjectW_UpdateString(json,L"settings.saml_autocreate_access_role",L"ro");
    CkJsonObjectW_UpdateString(json,L"settings.saml_autocreate_users_domains.domains[0]",L"example.com");
    CkJsonObjectW_UpdateString(json,L"settings.saml_autocreate_users_domains.domains[1]",L"example.com");
    CkJsonObjectW_UpdateBool(json,L"settings.saml_autocreate_users_domains.enabled",FALSE);
    CkJsonObjectW_UpdateBool(json,L"settings.saml_can_be_enabled",FALSE);
    CkJsonObjectW_UpdateString(json,L"settings.saml_idp_endpoint",L"https://my.saml.endpoint");
    CkJsonObjectW_UpdateBool(json,L"settings.saml_idp_initiated_login.enabled",FALSE);
    CkJsonObjectW_UpdateBool(json,L"settings.saml_idp_metadata_uploaded",FALSE);
    CkJsonObjectW_UpdateString(json,L"settings.saml_login_url",L"https://my.saml.login.url");
    CkJsonObjectW_UpdateBool(json,L"settings.saml_strict_mode.enabled",FALSE);
    CkJsonObjectW_UpdateString(json,L"subscription.type",L"pro");
    CkJsonObjectW_UpdateBool(json,L"trial",FALSE);

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PUT",L"https://api.app.ddog-gov.com/api/v1/org/:public_id",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    v_Type = CkJsonObjectW_stringOf(jResp,L"org.billing.type");
    Created = CkJsonObjectW_stringOf(jResp,L"org.created");
    Description = CkJsonObjectW_stringOf(jResp,L"org.description");
    Name = CkJsonObjectW_stringOf(jResp,L"org.name");
    Public_id = CkJsonObjectW_stringOf(jResp,L"org.public_id");
    Private_widget_share = CkJsonObjectW_BoolOf(jResp,L"org.settings.private_widget_share");
    Enabled = CkJsonObjectW_BoolOf(jResp,L"org.settings.saml.enabled");
    Saml_autocreate_access_role = CkJsonObjectW_stringOf(jResp,L"org.settings.saml_autocreate_access_role");
    Saml_autocreate_users_domainsEnabled = CkJsonObjectW_BoolOf(jResp,L"org.settings.saml_autocreate_users_domains.enabled");
    Saml_can_be_enabled = CkJsonObjectW_BoolOf(jResp,L"org.settings.saml_can_be_enabled");
    Saml_idp_endpoint = CkJsonObjectW_stringOf(jResp,L"org.settings.saml_idp_endpoint");
    Saml_idp_initiated_loginEnabled = CkJsonObjectW_BoolOf(jResp,L"org.settings.saml_idp_initiated_login.enabled");
    Saml_idp_metadata_uploaded = CkJsonObjectW_BoolOf(jResp,L"org.settings.saml_idp_metadata_uploaded");
    Saml_login_url = CkJsonObjectW_stringOf(jResp,L"org.settings.saml_login_url");
    Saml_strict_modeEnabled = CkJsonObjectW_BoolOf(jResp,L"org.settings.saml_strict_mode.enabled");
    SubscriptionType = CkJsonObjectW_stringOf(jResp,L"org.subscription.type");
    Trial = CkJsonObjectW_BoolOf(jResp,L"org.trial");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"org.settings.saml_autocreate_users_domains.domains");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        strVal = CkJsonObjectW_stringOf(jResp,L"org.settings.saml_autocreate_users_domains.domains[i]");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X PUT
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "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
}'
https://api.app.ddog-gov.com/api/v1/org/:public_id

Postman Collection Item JSON

{
  "name": "Update your organization",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\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}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/org/:public_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "org",
        ":public_id"
      ],
      "variable": [
        {
          "key": "public_id",
          "value": "abc123"
        }
      ]
    },
    "description": "Update your organization."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "PUT",
        "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  \"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}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "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": "PUT",
        "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  \"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}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "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": "PUT",
        "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  \"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}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "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": "PUT",
        "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  \"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}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "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}"
    }
  ]
}