Back to Collection Items
#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkStringBuilder.h>
#include <CkHttpResponse.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http;
bool success;
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "data": {
// "attributes": {
// "handle": "<string>",
// "name": "<string>",
// "avatar": "<string>",
// "banner": "<long>",
// "color": "<integer>",
// "description": "<string>",
// "hidden_modules": [
// "<string>",
// "<string>"
// ],
// "visible_modules": [
// "<string>",
// "<string>"
// ]
// },
// "type": "team",
// "relationships": {
// "team_links": {
// "data": [
// {
// "id": "<string>",
// "type": "team_links"
// },
// {
// "id": "<string>",
// "type": "team_links"
// }
// ],
// "links": {
// "related": "<string>"
// }
// }
// }
// }
// }
CkJsonObject json;
json.UpdateString("data.attributes.handle","<string>");
json.UpdateString("data.attributes.name","<string>");
json.UpdateString("data.attributes.avatar","<string>");
json.UpdateString("data.attributes.banner","<long>");
json.UpdateString("data.attributes.color","<integer>");
json.UpdateString("data.attributes.description","<string>");
json.UpdateString("data.attributes.hidden_modules[0]","<string>");
json.UpdateString("data.attributes.hidden_modules[1]","<string>");
json.UpdateString("data.attributes.visible_modules[0]","<string>");
json.UpdateString("data.attributes.visible_modules[1]","<string>");
json.UpdateString("data.type","team");
json.UpdateString("data.relationships.team_links.data[0].id","<string>");
json.UpdateString("data.relationships.team_links.data[0].type","team_links");
json.UpdateString("data.relationships.team_links.data[1].id","<string>");
json.UpdateString("data.relationships.team_links.data[1].type","team_links");
json.UpdateString("data.relationships.team_links.links.related","<string>");
http.SetRequestHeader("Content-Type","application/json");
http.SetRequestHeader("Accept","application/json");
CkStringBuilder sbRequestBody;
json.EmitSb(sbRequestBody);
CkHttpResponse *resp = http.PTextSb("PATCH","https://api.app.ddog-gov.com/api/v2/team/:team_id",sbRequestBody,"utf-8","application/json",false,false);
if (http.get_LastMethodSuccess() == false) {
std::cout << http.lastErrorText() << "\r\n";
return;
}
CkStringBuilder sbResponseBody;
resp->GetBodySb(sbResponseBody);
CkJsonObject jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
std::cout << "Response Body:" << "\r\n";
std::cout << jResp.emit() << "\r\n";
int respStatusCode = resp->get_StatusCode();
std::cout << "Response Status Code = " << respStatusCode << "\r\n";
if (respStatusCode >= 400) {
std::cout << "Response Header:" << "\r\n";
std::cout << resp->header() << "\r\n";
std::cout << "Failed." << "\r\n";
delete resp;
return;
}
delete resp;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "attributes": {
// "handle": "<string>",
// "name": "<string>",
// "avatar": "<string>",
// "banner": "<long>",
// "created_at": "<dateTime>",
// "description": "<string>",
// "hidden_modules": [
// "<string>",
// "<string>"
// ],
// "link_count": "<integer>",
// "modified_at": "<dateTime>",
// "summary": "<string>",
// "user_count": "<integer>",
// "visible_modules": [
// "<string>",
// "<string>"
// ]
// },
// "id": "<string>",
// "type": "team",
// "relationships": {
// "team_links": {
// "data": [
// {
// "id": "<string>",
// "type": "team_links"
// },
// {
// "id": "<string>",
// "type": "team_links"
// }
// ],
// "links": {
// "related": "<string>"
// }
// },
// "user_team_permissions": {
// "data": {
// "id": "<string>",
// "type": "user_team_permissions"
// },
// "links": {
// "related": "<string>"
// }
// }
// }
// }
// }
// 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.
const char *strVal = 0;
const char *id = 0;
const char *v_type = 0;
const char *Handle = jResp.stringOf("data.attributes.handle");
const char *Name = jResp.stringOf("data.attributes.name");
const char *Avatar = jResp.stringOf("data.attributes.avatar");
const char *Banner = jResp.stringOf("data.attributes.banner");
const char *Created_at = jResp.stringOf("data.attributes.created_at");
const char *Description = jResp.stringOf("data.attributes.description");
const char *Link_count = jResp.stringOf("data.attributes.link_count");
const char *Modified_at = jResp.stringOf("data.attributes.modified_at");
const char *Summary = jResp.stringOf("data.attributes.summary");
const char *User_count = jResp.stringOf("data.attributes.user_count");
const char *Id = jResp.stringOf("data.id");
const char *v_Type = jResp.stringOf("data.type");
const char *Related = jResp.stringOf("data.relationships.team_links.links.related");
const char *DataId = jResp.stringOf("data.relationships.user_team_permissions.data.id");
const char *DataType = jResp.stringOf("data.relationships.user_team_permissions.data.type");
const char *LinksRelated = jResp.stringOf("data.relationships.user_team_permissions.links.related");
int i = 0;
int count_i = jResp.SizeOfArray("data.attributes.hidden_modules");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf("data.attributes.hidden_modules[i]");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray("data.attributes.visible_modules");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf("data.attributes.visible_modules[i]");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray("data.relationships.team_links.data");
while (i < count_i) {
jResp.put_I(i);
id = jResp.stringOf("data.relationships.team_links.data[i].id");
v_type = jResp.stringOf("data.relationships.team_links.data[i].type");
i = i + 1;
}
}
Curl Command
curl -X PATCH
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"data": {
"attributes": {
"handle": "<string>",
"name": "<string>",
"avatar": "<string>",
"banner": "<long>",
"color": "<integer>",
"description": "<string>",
"hidden_modules": [
"<string>",
"<string>"
],
"visible_modules": [
"<string>",
"<string>"
]
},
"type": "team",
"relationships": {
"team_links": {
"data": [
{
"id": "<string>",
"type": "team_links"
},
{
"id": "<string>",
"type": "team_links"
}
],
"links": {
"related": "<string>"
}
}
}
}
}'
https://api.app.ddog-gov.com/api/v2/team/:team_id
Postman Collection Item JSON
{
"name": "Update a team",
"request": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"handle\": \"<string>\",\n \"name\": \"<string>\",\n \"avatar\": \"<string>\",\n \"banner\": \"<long>\",\n \"color\": \"<integer>\",\n \"description\": \"<string>\",\n \"hidden_modules\": [\n \"<string>\",\n \"<string>\"\n ],\n \"visible_modules\": [\n \"<string>\",\n \"<string>\"\n ]\n },\n \"type\": \"team\",\n \"relationships\": {\n \"team_links\": {\n \"data\": [\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n },\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n }\n ],\n \"links\": {\n \"related\": \"<string>\"\n }\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/team/:team_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"team",
":team_id"
],
"variable": [
{
"key": "team_id",
"value": "<string>"
}
]
},
"description": "Update a team using the team's `id`.\nIf the `team_links` relationship is present, the associated links are updated to be in the order they appear in the array, and any existing team links not present are removed."
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "PATCH",
"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 \"data\": {\n \"attributes\": {\n \"handle\": \"<string>\",\n \"name\": \"<string>\",\n \"avatar\": \"<string>\",\n \"banner\": \"<long>\",\n \"color\": \"<integer>\",\n \"description\": \"<string>\",\n \"hidden_modules\": [\n \"<string>\",\n \"<string>\"\n ],\n \"visible_modules\": [\n \"<string>\",\n \"<string>\"\n ]\n },\n \"type\": \"team\",\n \"relationships\": {\n \"team_links\": {\n \"data\": [\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n },\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n }\n ],\n \"links\": {\n \"related\": \"<string>\"\n }\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/team/:team_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"team",
":team_id"
],
"variable": [
{
"key": "team_id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"attributes\": {\n \"handle\": \"<string>\",\n \"name\": \"<string>\",\n \"avatar\": \"<string>\",\n \"banner\": \"<long>\",\n \"created_at\": \"<dateTime>\",\n \"description\": \"<string>\",\n \"hidden_modules\": [\n \"<string>\",\n \"<string>\"\n ],\n \"link_count\": \"<integer>\",\n \"modified_at\": \"<dateTime>\",\n \"summary\": \"<string>\",\n \"user_count\": \"<integer>\",\n \"visible_modules\": [\n \"<string>\",\n \"<string>\"\n ]\n },\n \"id\": \"<string>\",\n \"type\": \"team\",\n \"relationships\": {\n \"team_links\": {\n \"data\": [\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n },\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n }\n ],\n \"links\": {\n \"related\": \"<string>\"\n }\n },\n \"user_team_permissions\": {\n \"data\": {\n \"id\": \"<string>\",\n \"type\": \"user_team_permissions\"\n },\n \"links\": {\n \"related\": \"<string>\"\n }\n }\n }\n }\n}"
},
{
"name": "API error response.",
"originalRequest": {
"method": "PATCH",
"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 \"data\": {\n \"attributes\": {\n \"handle\": \"<string>\",\n \"name\": \"<string>\",\n \"avatar\": \"<string>\",\n \"banner\": \"<long>\",\n \"color\": \"<integer>\",\n \"description\": \"<string>\",\n \"hidden_modules\": [\n \"<string>\",\n \"<string>\"\n ],\n \"visible_modules\": [\n \"<string>\",\n \"<string>\"\n ]\n },\n \"type\": \"team\",\n \"relationships\": {\n \"team_links\": {\n \"data\": [\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n },\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n }\n ],\n \"links\": {\n \"related\": \"<string>\"\n }\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/team/:team_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"team",
":team_id"
],
"variable": [
{
"key": "team_id"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "API error response.",
"originalRequest": {
"method": "PATCH",
"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 \"data\": {\n \"attributes\": {\n \"handle\": \"<string>\",\n \"name\": \"<string>\",\n \"avatar\": \"<string>\",\n \"banner\": \"<long>\",\n \"color\": \"<integer>\",\n \"description\": \"<string>\",\n \"hidden_modules\": [\n \"<string>\",\n \"<string>\"\n ],\n \"visible_modules\": [\n \"<string>\",\n \"<string>\"\n ]\n },\n \"type\": \"team\",\n \"relationships\": {\n \"team_links\": {\n \"data\": [\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n },\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n }\n ],\n \"links\": {\n \"related\": \"<string>\"\n }\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/team/:team_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"team",
":team_id"
],
"variable": [
{
"key": "team_id"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "API error response.",
"originalRequest": {
"method": "PATCH",
"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 \"data\": {\n \"attributes\": {\n \"handle\": \"<string>\",\n \"name\": \"<string>\",\n \"avatar\": \"<string>\",\n \"banner\": \"<long>\",\n \"color\": \"<integer>\",\n \"description\": \"<string>\",\n \"hidden_modules\": [\n \"<string>\",\n \"<string>\"\n ],\n \"visible_modules\": [\n \"<string>\",\n \"<string>\"\n ]\n },\n \"type\": \"team\",\n \"relationships\": {\n \"team_links\": {\n \"data\": [\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n },\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n }\n ],\n \"links\": {\n \"related\": \"<string>\"\n }\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/team/:team_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"team",
":team_id"
],
"variable": [
{
"key": "team_id"
}
]
}
},
"status": "Conflict",
"code": 409,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Too many requests",
"originalRequest": {
"method": "PATCH",
"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 \"data\": {\n \"attributes\": {\n \"handle\": \"<string>\",\n \"name\": \"<string>\",\n \"avatar\": \"<string>\",\n \"banner\": \"<long>\",\n \"color\": \"<integer>\",\n \"description\": \"<string>\",\n \"hidden_modules\": [\n \"<string>\",\n \"<string>\"\n ],\n \"visible_modules\": [\n \"<string>\",\n \"<string>\"\n ]\n },\n \"type\": \"team\",\n \"relationships\": {\n \"team_links\": {\n \"data\": [\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n },\n {\n \"id\": \"<string>\",\n \"type\": \"team_links\"\n }\n ],\n \"links\": {\n \"related\": \"<string>\"\n }\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/team/:team_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"team",
":team_id"
],
"variable": [
{
"key": "team_id"
}
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
}
]
}