Chilkat Online Tools

delphiDll / Datadog API Collection / Send invitation emails

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
Created_at: PWideChar;
Expires_at: PWideChar;
Invite_type: PWideChar;
Uuid: PWideChar;
id: PWideChar;
Id: PWideChar;
v_Type: PWideChar;
v_type: 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": [
//     {
//       "type": "user_invitations",
//       "relationships": {
//         "user": {
//           "data": {
//             "id": "<string>",
//             "type": "users"
//           }
//         }
//       }
//     },
//     {
//       "type": "user_invitations",
//       "relationships": {
//         "user": {
//           "data": {
//             "id": "<string>",
//             "type": "users"
//           }
//         }
//       }
//     }
//   ]
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'data[0].type','user_invitations');
CkJsonObject_UpdateString(json,'data[0].relationships.user.data.id','<string>');
CkJsonObject_UpdateString(json,'data[0].relationships.user.data.type','users');
CkJsonObject_UpdateString(json,'data[1].type','user_invitations');
CkJsonObject_UpdateString(json,'data[1].relationships.user.data.id','<string>');
CkJsonObject_UpdateString(json,'data[1].relationships.user.data.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/user_invitations','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": {
//         "created_at": "<dateTime>",
//         "expires_at": "<dateTime>",
//         "invite_type": "<string>",
//         "uuid": "<string>"
//       },
//       "id": "<string>",
//       "relationships": {
//         "user": {
//           "data": {
//             "id": "<string>",
//             "type": "users"
//           }
//         }
//       },
//       "type": "user_invitations"
//     },
//     {
//       "attributes": {
//         "created_at": "<dateTime>",
//         "expires_at": "<dateTime>",
//         "invite_type": "<string>",
//         "uuid": "<string>"
//       },
//       "id": "<string>",
//       "relationships": {
//         "user": {
//           "data": {
//             "id": "<string>",
//             "type": "users"
//           }
//         }
//       },
//       "type": "user_invitations"
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'data');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    Created_at := CkJsonObject__stringOf(jResp,'data[i].attributes.created_at');
    Expires_at := CkJsonObject__stringOf(jResp,'data[i].attributes.expires_at');
    Invite_type := CkJsonObject__stringOf(jResp,'data[i].attributes.invite_type');
    Uuid := CkJsonObject__stringOf(jResp,'data[i].attributes.uuid');
    id := CkJsonObject__stringOf(jResp,'data[i].id');
    Id := CkJsonObject__stringOf(jResp,'data[i].relationships.user.data.id');
    v_Type := CkJsonObject__stringOf(jResp,'data[i].relationships.user.data.type');
    v_type := CkJsonObject__stringOf(jResp,'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": [
    {
      "type": "user_invitations",
      "relationships": {
        "user": {
          "data": {
            "id": "<string>",
            "type": "users"
          }
        }
      }
    },
    {
      "type": "user_invitations",
      "relationships": {
        "user": {
          "data": {
            "id": "<string>",
            "type": "users"
          }
        }
      }
    }
  ]
}'
https://api.app.ddog-gov.com/api/v2/user_invitations

Postman Collection Item JSON

{
  "name": "Send invitation emails",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": [\n    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    },\n    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    }\n  ]\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/user_invitations",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "user_invitations"
      ]
    },
    "description": "Sends emails to one or more users inviting them to join the organization."
  },
  "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  \"data\": [\n    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    },\n    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    }\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/user_invitations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "user_invitations"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": [\n    {\n      \"attributes\": {\n        \"created_at\": \"<dateTime>\",\n        \"expires_at\": \"<dateTime>\",\n        \"invite_type\": \"<string>\",\n        \"uuid\": \"<string>\"\n      },\n      \"id\": \"<string>\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      },\n      \"type\": \"user_invitations\"\n    },\n    {\n      \"attributes\": {\n        \"created_at\": \"<dateTime>\",\n        \"expires_at\": \"<dateTime>\",\n        \"invite_type\": \"<string>\",\n        \"uuid\": \"<string>\"\n      },\n      \"id\": \"<string>\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      },\n      \"type\": \"user_invitations\"\n    }\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  \"data\": [\n    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    },\n    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    }\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/user_invitations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "user_invitations"
          ]
        }
      },
      "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": "Authentication error",
      "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    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    },\n    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    }\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/user_invitations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "user_invitations"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_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    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    },\n    {\n      \"type\": \"user_invitations\",\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    }\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/user_invitations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "user_invitations"
          ]
        }
      },
      "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}"
    }
  ]
}