Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkStringBuilder sbRequestBody;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *strVal;
const char *v_Type;
const char *Created;
const char *Description;
const char *Name;
const char *Public_id;
BOOL Private_widget_share;
BOOL Enabled;
const char *Saml_autocreate_access_role;
BOOL Saml_autocreate_users_domainsEnabled;
BOOL Saml_can_be_enabled;
const char *Saml_idp_endpoint;
BOOL Saml_idp_initiated_loginEnabled;
BOOL Saml_idp_metadata_uploaded;
const char *Saml_login_url;
BOOL Saml_strict_modeEnabled;
const char *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 = 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.
// {
// "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 = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"billing.type","parent_billing");
CkJsonObject_UpdateString(json,"created","2019-09-26T17:28:28Z");
CkJsonObject_UpdateString(json,"description","some description");
CkJsonObject_UpdateString(json,"name","New child org");
CkJsonObject_UpdateString(json,"public_id","abcdef12345");
CkJsonObject_UpdateBool(json,"settings.private_widget_share",FALSE);
CkJsonObject_UpdateBool(json,"settings.saml.enabled",FALSE);
CkJsonObject_UpdateString(json,"settings.saml_autocreate_access_role","ro");
CkJsonObject_UpdateString(json,"settings.saml_autocreate_users_domains.domains[0]","example.com");
CkJsonObject_UpdateString(json,"settings.saml_autocreate_users_domains.domains[1]","example.com");
CkJsonObject_UpdateBool(json,"settings.saml_autocreate_users_domains.enabled",FALSE);
CkJsonObject_UpdateBool(json,"settings.saml_can_be_enabled",FALSE);
CkJsonObject_UpdateString(json,"settings.saml_idp_endpoint","https://my.saml.endpoint");
CkJsonObject_UpdateBool(json,"settings.saml_idp_initiated_login.enabled",FALSE);
CkJsonObject_UpdateBool(json,"settings.saml_idp_metadata_uploaded",FALSE);
CkJsonObject_UpdateString(json,"settings.saml_login_url","https://my.saml.login.url");
CkJsonObject_UpdateBool(json,"settings.saml_strict_mode.enabled",FALSE);
CkJsonObject_UpdateString(json,"subscription.type","pro");
CkJsonObject_UpdateBool(json,"trial",FALSE);
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
CkHttp_SetRequestHeader(http,"Accept","application/json");
sbRequestBody = CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
resp = CkHttp_PTextSb(http,"PUT","https://api.app.ddog-gov.com/api/v1/org/:public_id",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_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 = CkJsonObject_stringOf(jResp,"org.billing.type");
Created = CkJsonObject_stringOf(jResp,"org.created");
Description = CkJsonObject_stringOf(jResp,"org.description");
Name = 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");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"org.settings.saml_autocreate_users_domains.domains");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"org.settings.saml_autocreate_users_domains.domains[i]");
i = i + 1;
}
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_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}"
}
]
}