Chilkat Online Tools

DataFlex / Datadog API Collection / Add a user to a role

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sCreated_at
    String sDisabled
    String sV_Email
    String sHandle
    String sIcon
    String sModified_at
    String sName
    String sService_account
    String sStatus
    String sTitle
    String sVerified
    String sId
    String sId
    String sV_Type
    String sV_type
    Integer j
    Integer iCount_j
    String sAttributesCreated_at
    String sDescription
    String sAttributesDisabled
    String sAttributesModified_at
    String sAttributesName
    String sPublic_id
    String sSharing
    String sV_Url
    String sTotal_count
    String sTotal_filtered_count
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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": {
    //     "id": "<string>",
    //     "type": "users"
    //   }
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "data.id" "<string>" To iSuccess
    Get ComUpdateString Of hoJson "data.type" "users" To iSuccess

    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.app.ddog-gov.com/api/v2/roles/:role_id/users" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "data": [
    //     {
    //       "attributes": {
    //         "created_at": "<dateTime>",
    //         "disabled": "<boolean>",
    //         "email": "<string>",
    //         "handle": "<string>",
    //         "icon": "<string>",
    //         "modified_at": "<dateTime>",
    //         "name": "<string>",
    //         "service_account": "<boolean>",
    //         "status": "<string>",
    //         "title": "<string>",
    //         "verified": "<boolean>"
    //       },
    //       "id": "<string>",
    //       "relationships": {
    //         "org": {
    //           "data": {
    //             "id": "<string>",
    //             "type": "orgs"
    //           }
    //         },
    //         "other_orgs": {
    //           "data": [
    //             {
    //               "id": "<string>",
    //               "type": "orgs"
    //             },
    //             {
    //               "id": "<string>",
    //               "type": "orgs"
    //             }
    //           ]
    //         },
    //         "other_users": {
    //           "data": [
    //             {
    //               "id": "<string>",
    //               "type": "users"
    //             },
    //             {
    //               "id": "<string>",
    //               "type": "users"
    //             }
    //           ]
    //         },
    //         "roles": {
    //           "data": [
    //             {
    //               "id": "<string>",
    //               "type": "roles"
    //             },
    //             {
    //               "id": "<string>",
    //               "type": "roles"
    //             }
    //           ]
    //         }
    //       },
    //       "type": "users"
    //     },
    //     {
    //       "attributes": {
    //         "created_at": "<dateTime>",
    //         "disabled": "<boolean>",
    //         "email": "<string>",
    //         "handle": "<string>",
    //         "icon": "<string>",
    //         "modified_at": "<dateTime>",
    //         "name": "<string>",
    //         "service_account": "<boolean>",
    //         "status": "<string>",
    //         "title": "<string>",
    //         "verified": "<boolean>"
    //       },
    //       "id": "<string>",
    //       "relationships": {
    //         "org": {
    //           "data": {
    //             "id": "<string>",
    //             "type": "orgs"
    //           }
    //         },
    //         "other_orgs": {
    //           "data": [
    //             {
    //               "id": "<string>",
    //               "type": "orgs"
    //             },
    //             {
    //               "id": "<string>",
    //               "type": "orgs"
    //             }
    //           ]
    //         },
    //         "other_users": {
    //           "data": [
    //             {
    //               "id": "<string>",
    //               "type": "users"
    //             },
    //             {
    //               "id": "<string>",
    //               "type": "users"
    //             }
    //           ]
    //         },
    //         "roles": {
    //           "data": [
    //             {
    //               "id": "<string>",
    //               "type": "roles"
    //             },
    //             {
    //               "id": "<string>",
    //               "type": "roles"
    //             }
    //           ]
    //         }
    //       },
    //       "type": "users"
    //     }
    //   ],
    //   "included": [
    //     {
    //       "type": "orgs",
    //       "attributes": {
    //         "created_at": "<dateTime>",
    //         "description": "<string>",
    //         "disabled": "<boolean>",
    //         "modified_at": "<dateTime>",
    //         "name": "<string>",
    //         "public_id": "<string>",
    //         "sharing": "<string>",
    //         "url": "<string>"
    //       },
    //       "id": "<string>"
    //     },
    //     {
    //       "type": "orgs",
    //       "attributes": {
    //         "created_at": "<dateTime>",
    //         "description": "<string>",
    //         "disabled": "<boolean>",
    //         "modified_at": "<dateTime>",
    //         "name": "<string>",
    //         "public_id": "<string>",
    //         "sharing": "<string>",
    //         "url": "<string>"
    //       },
    //       "id": "<string>"
    //     }
    //   ],
    //   "meta": {
    //     "page": {
    //       "total_count": "<long>",
    //       "total_filtered_count": "<long>"
    //     }
    //   }
    // }

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

    Get ComStringOf Of hoJResp "meta.page.total_count" To sTotal_count
    Get ComStringOf Of hoJResp "meta.page.total_filtered_count" To sTotal_filtered_count
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data[i].attributes.created_at" To sCreated_at
        Get ComStringOf Of hoJResp "data[i].attributes.disabled" To sDisabled
        Get ComStringOf Of hoJResp "data[i].attributes.email" To sV_Email
        Get ComStringOf Of hoJResp "data[i].attributes.handle" To sHandle
        Get ComStringOf Of hoJResp "data[i].attributes.icon" To sIcon
        Get ComStringOf Of hoJResp "data[i].attributes.modified_at" To sModified_at
        Get ComStringOf Of hoJResp "data[i].attributes.name" To sName
        Get ComStringOf Of hoJResp "data[i].attributes.service_account" To sService_account
        Get ComStringOf Of hoJResp "data[i].attributes.status" To sStatus
        Get ComStringOf Of hoJResp "data[i].attributes.title" To sTitle
        Get ComStringOf Of hoJResp "data[i].attributes.verified" To sVerified
        Get ComStringOf Of hoJResp "data[i].id" To sId
        Get ComStringOf Of hoJResp "data[i].relationships.org.data.id" To sId
        Get ComStringOf Of hoJResp "data[i].relationships.org.data.type" To sV_Type
        Get ComStringOf Of hoJResp "data[i].type" To sV_type
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "data[i].relationships.other_orgs.data" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "data[i].relationships.other_orgs.data[j].id" To sId
            Get ComStringOf Of hoJResp "data[i].relationships.other_orgs.data[j].type" To sV_type
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "data[i].relationships.other_users.data" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "data[i].relationships.other_users.data[j].id" To sId
            Get ComStringOf Of hoJResp "data[i].relationships.other_users.data[j].type" To sV_type
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "data[i].relationships.roles.data" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "data[i].relationships.roles.data[j].id" To sId
            Get ComStringOf Of hoJResp "data[i].relationships.roles.data[j].type" To sV_type
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "included" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "included[i].type" To sV_type
        Get ComStringOf Of hoJResp "included[i].attributes.created_at" To sAttributesCreated_at
        Get ComStringOf Of hoJResp "included[i].attributes.description" To sDescription
        Get ComStringOf Of hoJResp "included[i].attributes.disabled" To sAttributesDisabled
        Get ComStringOf Of hoJResp "included[i].attributes.modified_at" To sAttributesModified_at
        Get ComStringOf Of hoJResp "included[i].attributes.name" To sAttributesName
        Get ComStringOf Of hoJResp "included[i].attributes.public_id" To sPublic_id
        Get ComStringOf Of hoJResp "included[i].attributes.sharing" To sSharing
        Get ComStringOf Of hoJResp "included[i].attributes.url" To sV_Url
        Get ComStringOf Of hoJResp "included[i].id" To sId
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "data": {
    "id": "<string>",
    "type": "users"
  }
}'
https://api.app.ddog-gov.com/api/v2/roles/:role_id/users

Postman Collection Item JSON

{
  "name": "Add a user to a role",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": {\n    \"id\": \"<string>\",\n    \"type\": \"users\"\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/roles/:role_id/users",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "roles",
        ":role_id",
        "users"
      ],
      "variable": [
        {
          "key": "role_id",
          "value": "<string>"
        }
      ]
    },
    "description": "Adds a user to a role."
  },
  "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    \"id\": \"<string>\",\n    \"type\": \"users\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/roles/:role_id/users",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "roles",
            ":role_id",
            "users"
          ],
          "variable": [
            {
              "key": "role_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": [\n    {\n      \"attributes\": {\n        \"created_at\": \"<dateTime>\",\n        \"disabled\": \"<boolean>\",\n        \"email\": \"<string>\",\n        \"handle\": \"<string>\",\n        \"icon\": \"<string>\",\n        \"modified_at\": \"<dateTime>\",\n        \"name\": \"<string>\",\n        \"service_account\": \"<boolean>\",\n        \"status\": \"<string>\",\n        \"title\": \"<string>\",\n        \"verified\": \"<boolean>\"\n      },\n      \"id\": \"<string>\",\n      \"relationships\": {\n        \"org\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"orgs\"\n          }\n        },\n        \"other_orgs\": {\n          \"data\": [\n            {\n              \"id\": \"<string>\",\n              \"type\": \"orgs\"\n            },\n            {\n              \"id\": \"<string>\",\n              \"type\": \"orgs\"\n            }\n          ]\n        },\n        \"other_users\": {\n          \"data\": [\n            {\n              \"id\": \"<string>\",\n              \"type\": \"users\"\n            },\n            {\n              \"id\": \"<string>\",\n              \"type\": \"users\"\n            }\n          ]\n        },\n        \"roles\": {\n          \"data\": [\n            {\n              \"id\": \"<string>\",\n              \"type\": \"roles\"\n            },\n            {\n              \"id\": \"<string>\",\n              \"type\": \"roles\"\n            }\n          ]\n        }\n      },\n      \"type\": \"users\"\n    },\n    {\n      \"attributes\": {\n        \"created_at\": \"<dateTime>\",\n        \"disabled\": \"<boolean>\",\n        \"email\": \"<string>\",\n        \"handle\": \"<string>\",\n        \"icon\": \"<string>\",\n        \"modified_at\": \"<dateTime>\",\n        \"name\": \"<string>\",\n        \"service_account\": \"<boolean>\",\n        \"status\": \"<string>\",\n        \"title\": \"<string>\",\n        \"verified\": \"<boolean>\"\n      },\n      \"id\": \"<string>\",\n      \"relationships\": {\n        \"org\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"orgs\"\n          }\n        },\n        \"other_orgs\": {\n          \"data\": [\n            {\n              \"id\": \"<string>\",\n              \"type\": \"orgs\"\n            },\n            {\n              \"id\": \"<string>\",\n              \"type\": \"orgs\"\n            }\n          ]\n        },\n        \"other_users\": {\n          \"data\": [\n            {\n              \"id\": \"<string>\",\n              \"type\": \"users\"\n            },\n            {\n              \"id\": \"<string>\",\n              \"type\": \"users\"\n            }\n          ]\n        },\n        \"roles\": {\n          \"data\": [\n            {\n              \"id\": \"<string>\",\n              \"type\": \"roles\"\n            },\n            {\n              \"id\": \"<string>\",\n              \"type\": \"roles\"\n            }\n          ]\n        }\n      },\n      \"type\": \"users\"\n    }\n  ],\n  \"included\": [\n    {\n      \"type\": \"orgs\",\n      \"attributes\": {\n        \"created_at\": \"<dateTime>\",\n        \"description\": \"<string>\",\n        \"disabled\": \"<boolean>\",\n        \"modified_at\": \"<dateTime>\",\n        \"name\": \"<string>\",\n        \"public_id\": \"<string>\",\n        \"sharing\": \"<string>\",\n        \"url\": \"<string>\"\n      },\n      \"id\": \"<string>\"\n    },\n    {\n      \"type\": \"orgs\",\n      \"attributes\": {\n        \"created_at\": \"<dateTime>\",\n        \"description\": \"<string>\",\n        \"disabled\": \"<boolean>\",\n        \"modified_at\": \"<dateTime>\",\n        \"name\": \"<string>\",\n        \"public_id\": \"<string>\",\n        \"sharing\": \"<string>\",\n        \"url\": \"<string>\"\n      },\n      \"id\": \"<string>\"\n    }\n  ],\n  \"meta\": {\n    \"page\": {\n      \"total_count\": \"<long>\",\n      \"total_filtered_count\": \"<long>\"\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    \"id\": \"<string>\",\n    \"type\": \"users\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/roles/:role_id/users",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "roles",
            ":role_id",
            "users"
          ],
          "variable": [
            {
              "key": "role_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": "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    \"id\": \"<string>\",\n    \"type\": \"users\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/roles/:role_id/users",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "roles",
            ":role_id",
            "users"
          ],
          "variable": [
            {
              "key": "role_id"
            }
          ]
        }
      },
      "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": "Not found",
      "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    \"id\": \"<string>\",\n    \"type\": \"users\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/roles/:role_id/users",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "roles",
            ":role_id",
            "users"
          ],
          "variable": [
            {
              "key": "role_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": "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    \"id\": \"<string>\",\n    \"type\": \"users\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/roles/:role_id/users",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "roles",
            ":role_id",
            "users"
          ],
          "variable": [
            {
              "key": "role_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}"
    }
  ]
}