Chilkat Online Tools

delphiDll / Datadog API Collection / Create a team

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
strVal: PWideChar;
id: PWideChar;
v_type: PWideChar;
Handle: PWideChar;
Name: PWideChar;
Avatar: PWideChar;
Banner: PWideChar;
Created_at: PWideChar;
Description: PWideChar;
Link_count: PWideChar;
Modified_at: PWideChar;
Summary: PWideChar;
User_count: PWideChar;
Id: PWideChar;
v_Type: PWideChar;
Related: PWideChar;
DataId: PWideChar;
DataType: PWideChar;
LinksRelated: PWideChar;
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.

// {
//   "data": {
//     "attributes": {
//       "handle": "<string>",
//       "name": "<string>",
//       "avatar": "<string>",
//       "banner": "<long>",
//       "description": "<string>",
//       "hidden_modules": [
//         "<string>",
//         "<string>"
//       ],
//       "visible_modules": [
//         "<string>",
//         "<string>"
//       ]
//     },
//     "type": "team",
//     "relationships": {
//       "users": {
//         "data": [
//           {
//             "id": "<string>",
//             "type": "users"
//           },
//           {
//             "id": "<string>",
//             "type": "users"
//           }
//         ]
//       }
//     }
//   }
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'data.attributes.handle','<string>');
CkJsonObject_UpdateString(json,'data.attributes.name','<string>');
CkJsonObject_UpdateString(json,'data.attributes.avatar','<string>');
CkJsonObject_UpdateString(json,'data.attributes.banner','<long>');
CkJsonObject_UpdateString(json,'data.attributes.description','<string>');
CkJsonObject_UpdateString(json,'data.attributes.hidden_modules[0]','<string>');
CkJsonObject_UpdateString(json,'data.attributes.hidden_modules[1]','<string>');
CkJsonObject_UpdateString(json,'data.attributes.visible_modules[0]','<string>');
CkJsonObject_UpdateString(json,'data.attributes.visible_modules[1]','<string>');
CkJsonObject_UpdateString(json,'data.type','team');
CkJsonObject_UpdateString(json,'data.relationships.users.data[0].id','<string>');
CkJsonObject_UpdateString(json,'data.relationships.users.data[0].type','users');
CkJsonObject_UpdateString(json,'data.relationships.users.data[1].id','<string>');
CkJsonObject_UpdateString(json,'data.relationships.users.data[1].type','users');

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

resp := CkHttp_PostJson3(http,'https://api.app.ddog-gov.com/api/v2/team','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)

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

Handle := CkJsonObject__stringOf(jResp,'data.attributes.handle');
Name := CkJsonObject__stringOf(jResp,'data.attributes.name');
Avatar := CkJsonObject__stringOf(jResp,'data.attributes.avatar');
Banner := CkJsonObject__stringOf(jResp,'data.attributes.banner');
Created_at := CkJsonObject__stringOf(jResp,'data.attributes.created_at');
Description := CkJsonObject__stringOf(jResp,'data.attributes.description');
Link_count := CkJsonObject__stringOf(jResp,'data.attributes.link_count');
Modified_at := CkJsonObject__stringOf(jResp,'data.attributes.modified_at');
Summary := CkJsonObject__stringOf(jResp,'data.attributes.summary');
User_count := CkJsonObject__stringOf(jResp,'data.attributes.user_count');
Id := CkJsonObject__stringOf(jResp,'data.id');
v_Type := CkJsonObject__stringOf(jResp,'data.type');
Related := CkJsonObject__stringOf(jResp,'data.relationships.team_links.links.related');
DataId := CkJsonObject__stringOf(jResp,'data.relationships.user_team_permissions.data.id');
DataType := CkJsonObject__stringOf(jResp,'data.relationships.user_team_permissions.data.type');
LinksRelated := CkJsonObject__stringOf(jResp,'data.relationships.user_team_permissions.links.related');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'data.attributes.hidden_modules');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'data.attributes.hidden_modules[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'data.attributes.visible_modules');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'data.attributes.visible_modules[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'data.relationships.team_links.data');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    id := CkJsonObject__stringOf(jResp,'data.relationships.team_links.data[i].id');
    v_type := CkJsonObject__stringOf(jResp,'data.relationships.team_links.data[i].type');
    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 '{
  "data": {
    "attributes": {
      "handle": "<string>",
      "name": "<string>",
      "avatar": "<string>",
      "banner": "<long>",
      "description": "<string>",
      "hidden_modules": [
        "<string>",
        "<string>"
      ],
      "visible_modules": [
        "<string>",
        "<string>"
      ]
    },
    "type": "team",
    "relationships": {
      "users": {
        "data": [
          {
            "id": "<string>",
            "type": "users"
          },
          {
            "id": "<string>",
            "type": "users"
          }
        ]
      }
    }
  }
}'
https://api.app.ddog-gov.com/api/v2/team

Postman Collection Item JSON

{
  "name": "Create a team",
  "request": {
    "method": "POST",
    "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      \"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      \"users\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        ]\n      }\n    }\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/team",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "team"
      ]
    },
    "description": "Create a new team.\nUser IDs passed through the `users` relationship field are added to the team."
  },
  "response": [
    {
      "name": "CREATED",
      "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  \"data\": {\n    \"attributes\": {\n      \"handle\": \"<string>\",\n      \"name\": \"<string>\",\n      \"avatar\": \"<string>\",\n      \"banner\": \"<long>\",\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      \"users\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        ]\n      }\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/team",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_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": "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  \"data\": {\n    \"attributes\": {\n      \"handle\": \"<string>\",\n      \"name\": \"<string>\",\n      \"avatar\": \"<string>\",\n      \"banner\": \"<long>\",\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      \"users\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        ]\n      }\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/team",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team"
          ]
        }
      },
      "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": "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  \"data\": {\n    \"attributes\": {\n      \"handle\": \"<string>\",\n      \"name\": \"<string>\",\n      \"avatar\": \"<string>\",\n      \"banner\": \"<long>\",\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      \"users\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        ]\n      }\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/team",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team"
          ]
        }
      },
      "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}"
    }
  ]
}