Chilkat Online Tools

Perl / Datadog API Collection / Update a user's membership attributes on a team

Back to Collection Items

use chilkat();

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

$http = chilkat::CkHttp->new();

# 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": "team_memberships",
#     "attributes": {
#       "role": "admin"
#     }
#   }
# }

$json = chilkat::CkJsonObject->new();
$json->UpdateString("data.type","team_memberships");
$json->UpdateString("data.attributes.role","admin");

$http->SetRequestHeader("Content-Type","application/json");
$http->SetRequestHeader("Accept","application/json");

$sbRequestBody = chilkat::CkStringBuilder->new();
$json->EmitSb($sbRequestBody);

# resp is a HttpResponse
$resp = $http->PTextSb("PATCH","https://api.app.ddog-gov.com/api/v2/team/:team_id/memberships/:user_id",$sbRequestBody,"utf-8","application/json",0,0);
if ($http->get_LastMethodSuccess() == 0) {
    print $http->lastErrorText() . "\r\n";
    exit;
}

$sbResponseBody = chilkat::CkStringBuilder->new();
$resp->GetBodySb($sbResponseBody);

$jResp = chilkat::CkJsonObject->new();
$jResp->LoadSb($sbResponseBody);
$jResp->put_EmitCompact(0);

print "Response Body:" . "\r\n";
print $jResp->emit() . "\r\n";

$respStatusCode = $resp->get_StatusCode();
print "Response Status Code = " . $respStatusCode . "\r\n";
if ($respStatusCode >= 400) {
    print "Response Header:" . "\r\n";
    print $resp->header() . "\r\n";
    print "Failed." . "\r\n";

    exit;
}

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

# {
#   "data": {
#     "id": "<string>",
#     "type": "team_memberships",
#     "attributes": {
#       "role": "admin"
#     },
#     "relationships": {
#       "user": {
#         "data": {
#           "id": "<string>",
#           "type": "users"
#         }
#       }
#     }
#   }
# }

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

$Id = $jResp->stringOf("data.id");
$v_Type = $jResp->stringOf("data.type");
$Role = $jResp->stringOf("data.attributes.role");
$DataId = $jResp->stringOf("data.relationships.user.data.id");
$DataType = $jResp->stringOf("data.relationships.user.data.type");

Curl Command

curl -X PATCH
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "data": {
    "type": "team_memberships",
    "attributes": {
      "role": "admin"
    }
  }
}'
https://api.app.ddog-gov.com/api/v2/team/:team_id/memberships/:user_id

Postman Collection Item JSON

{
  "name": "Update a user's membership attributes on a team",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": {\n    \"type\": \"team_memberships\",\n    \"attributes\": {\n      \"role\": \"admin\"\n    }\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/team/:team_id/memberships/:user_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "team",
        ":team_id",
        "memberships",
        ":user_id"
      ],
      "variable": [
        {
          "key": "team_id",
          "value": "<string>"
        },
        {
          "key": "user_id",
          "value": "<string>"
        }
      ]
    },
    "description": "Update a user's membership attributes on a team."
  },
  "response": [
    {
      "name": "Represents a user's association to a team",
      "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    \"type\": \"team_memberships\",\n    \"attributes\": {\n      \"role\": \"admin\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/team/:team_id/memberships/:user_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team",
            ":team_id",
            "memberships",
            ":user_id"
          ],
          "variable": [
            {
              "key": "team_id"
            },
            {
              "key": "user_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"id\": \"<string>\",\n    \"type\": \"team_memberships\",\n    \"attributes\": {\n      \"role\": \"admin\"\n    },\n    \"relationships\": {\n      \"user\": {\n        \"data\": {\n          \"id\": \"<string>\",\n          \"type\": \"users\"\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    \"type\": \"team_memberships\",\n    \"attributes\": {\n      \"role\": \"admin\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/team/:team_id/memberships/:user_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team",
            ":team_id",
            "memberships",
            ":user_id"
          ],
          "variable": [
            {
              "key": "team_id"
            },
            {
              "key": "user_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": "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    \"type\": \"team_memberships\",\n    \"attributes\": {\n      \"role\": \"admin\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/team/:team_id/memberships/:user_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team",
            ":team_id",
            "memberships",
            ":user_id"
          ],
          "variable": [
            {
              "key": "team_id"
            },
            {
              "key": "user_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}"
    }
  ]
}