diff --git a/examples/v2/teams/CreateTeamMembership.java b/examples/v2/teams/CreateTeamMembership.java index 6e5ac62ed14..427112ed64f 100644 --- a/examples/v2/teams/CreateTeamMembership.java +++ b/examples/v2/teams/CreateTeamMembership.java @@ -3,8 +3,6 @@ import com.datadog.api.client.ApiClient; import com.datadog.api.client.ApiException; import com.datadog.api.client.v2.api.TeamsApi; -import com.datadog.api.client.v2.model.RelationshipToUserTeamTeam; -import com.datadog.api.client.v2.model.RelationshipToUserTeamTeamData; import com.datadog.api.client.v2.model.RelationshipToUserTeamUser; import com.datadog.api.client.v2.model.RelationshipToUserTeamUserData; import com.datadog.api.client.v2.model.UserTeamAttributes; @@ -13,7 +11,6 @@ import com.datadog.api.client.v2.model.UserTeamRequest; import com.datadog.api.client.v2.model.UserTeamResponse; import com.datadog.api.client.v2.model.UserTeamRole; -import com.datadog.api.client.v2.model.UserTeamTeamType; import com.datadog.api.client.v2.model.UserTeamType; import com.datadog.api.client.v2.model.UserTeamUserType; @@ -22,6 +19,12 @@ public static void main(String[] args) { ApiClient defaultClient = ApiClient.getDefaultApiClient(); TeamsApi apiInstance = new TeamsApi(defaultClient); + // there is a valid "dd_team" in the system + String DD_TEAM_DATA_ID = System.getenv("DD_TEAM_DATA_ID"); + + // there is a valid "user" in the system + String USER_DATA_ID = System.getenv("USER_DATA_ID"); + UserTeamRequest body = new UserTeamRequest() .data( @@ -29,22 +32,16 @@ public static void main(String[] args) { .attributes(new UserTeamAttributes().role(UserTeamRole.ADMIN)) .relationships( new UserTeamRelationships() - .team( - new RelationshipToUserTeamTeam() - .data( - new RelationshipToUserTeamTeamData() - .id("d7e15d9d-d346-43da-81d8-3d9e71d9a5e9") - .type(UserTeamTeamType.TEAM))) .user( new RelationshipToUserTeamUser() .data( new RelationshipToUserTeamUserData() - .id("b8626d7e-cedd-11eb-abf5-da7ad0900001") + .id(USER_DATA_ID) .type(UserTeamUserType.USERS)))) .type(UserTeamType.TEAM_MEMBERSHIPS)); try { - UserTeamResponse result = apiInstance.createTeamMembership("team_id", body); + UserTeamResponse result = apiInstance.createTeamMembership(DD_TEAM_DATA_ID, body); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling TeamsApi#createTeamMembership"); diff --git a/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_API_error_response_response.freeze b/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_API_error_response_response.freeze new file mode 100644 index 00000000000..1858032e081 --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_API_error_response_response.freeze @@ -0,0 +1 @@ +2026-03-31T14:58:05.044Z \ No newline at end of file diff --git a/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_API_error_response_response.json b/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_API_error_response_response.json new file mode 100644 index 00000000000..4b97f6d2d90 --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_API_error_response_response.json @@ -0,0 +1,185 @@ +[ + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"data\":{\"attributes\":{\"handle\":\"test-handle-22e42ce95626a92a\",\"name\":\"test-name-22e42ce95626a92a\"},\"type\":\"team\"}}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v2/team", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"data\":{\"id\":\"abc7c612-d3a1-4147-bcfa-f28b4af43d33\",\"type\":\"team\",\"attributes\":{\"avatar\":null,\"banner\":10,\"created_at\":\"2026-03-31T14:58:05.503733+00:00\",\"description\":null,\"handle\":\"test-handle-22e42ce95626a92a\",\"hidden_modules\":null,\"is_managed\":false,\"link_count\":0,\"modified_at\":\"2026-03-31T14:58:05.503733+00:00\",\"name\":\"test-name-22e42ce95626a92a\",\"summary\":null,\"user_count\":0,\"visible_modules\":null},\"relationships\":{\"team_links\":{\"data\":[],\"links\":{\"related\":\"/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/links\"}},\"user_team_permissions\":{\"data\":null,\"links\":{\"related\":\"/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/permission-settings\"}}}}}", + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "statusCode": 201, + "reasonPhrase": "Created" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "0f6d2248-08e0-ef27-3687-08f6b4d31e4c" + }, + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"data\":{\"attributes\":{\"email\":\"Test-Add_a_user_to_a_team_returns_API_error_response_response-1774969085@datadoghq.com\",\"title\":\"user title\"},\"type\":\"users\"}}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v2/users", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"data\": {\"type\": \"users\", \"id\": \"825c5f4c-585c-494a-aade-60f1e1aa189b\", \"attributes\": {\"name\": null, \"handle\": \"test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com\", \"created_at\": \"2026-03-31T14:58:06.030754+00:00\", \"modified_at\": \"2026-03-31T14:58:06.030754+00:00\", \"email\": \"test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com\", \"icon\": \"https://secure.gravatar.com/avatar/53ba6f826ef9a49acaeec55d1bcc1c47?s=48&d=retro\", \"title\": \"user title\", \"verified\": false, \"service_account\": false, \"disabled\": false, \"allowed_login_methods\": [], \"status\": \"Pending\", \"last_login_time\": null}, \"relationships\": {\"roles\": {\"data\": []}, \"org\": {\"data\": {\"type\": \"orgs\", \"id\": \"4dee724d-00cc-11ea-a77b-570c9d03c6c5\"}}}}}", + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "statusCode": 201, + "reasonPhrase": "Created" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "3785ade5-25e6-768c-c12e-a07fcfa448c0" + }, + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"data\":{\"attributes\":{\"role\":\"admin\"},\"relationships\":{\"user\":{\"data\":{\"id\":\"825c5f4c-585c-494a-aade-60f1e1aa189b\",\"type\":\"users\"}}},\"type\":\"team_memberships\"}}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/memberships", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"data\":{\"id\":\"TeamMembership-abc7c612-d3a1-4147-bcfa-f28b4af43d33-66215044\",\"type\":\"team_memberships\",\"attributes\":{\"provisioned_by\":null,\"provisioned_by_id\":\"a1d5ff5a-c6dd-11f0-9cb6-06640ca27ad4\",\"role\":\"admin\"},\"relationships\":{\"user\":{\"data\":{\"id\":\"825c5f4c-585c-494a-aade-60f1e1aa189b\",\"type\":\"users\"}}}},\"included\":[{\"id\":\"825c5f4c-585c-494a-aade-60f1e1aa189b\",\"type\":\"users\",\"attributes\":{\"disabled\":false,\"email\":\"test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com\",\"handle\":\"test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/53ba6f826ef9a49acaeec55d1bcc1c47?d=retro\\u0026s=48\",\"name\":null,\"service_account\":false,\"status\":\"Pending\"}}]}", + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "statusCode": 200, + "reasonPhrase": "OK" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "a61ba428-f7d6-96c4-ae6a-680ac4abf3bf" + }, + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"data\":{\"attributes\":{\"role\":\"admin\"},\"relationships\":{\"user\":{\"data\":{\"id\":\"825c5f4c-585c-494a-aade-60f1e1aa189b\",\"type\":\"users\"}}},\"type\":\"team_memberships\"}}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/memberships", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"errors\":[{\"status\":\"409\",\"title\":\"Conflict\",\"detail\":\"users already present on the team [825c5f4c-585c-494a-aade-60f1e1aa189b]\"}]}", + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "statusCode": 409, + "reasonPhrase": "Conflict" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "a61ba428-f7d6-96c4-ae6a-680ac4abf3c0" + }, + { + "httpRequest": { + "headers": {}, + "method": "DELETE", + "path": "/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/memberships/825c5f4c-585c-494a-aade-60f1e1aa189b", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "headers": {}, + "statusCode": 204, + "reasonPhrase": "No Content" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "92142243-fca9-c24f-cecb-3f2102c692e4" + }, + { + "httpRequest": { + "headers": {}, + "method": "DELETE", + "path": "/api/v2/users/825c5f4c-585c-494a-aade-60f1e1aa189b", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "headers": {}, + "statusCode": 204, + "reasonPhrase": "No Content" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "f4641238-0094-30cf-34fd-cbb0584c39bb" + }, + { + "httpRequest": { + "headers": {}, + "method": "DELETE", + "path": "/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "headers": {}, + "statusCode": 204, + "reasonPhrase": "No Content" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "3c4a5d8e-3898-0fa5-ef47-5e299f966144" + } +] \ No newline at end of file diff --git a/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_Represents_a_user_s_association_to_a_team_response.freeze b/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_Represents_a_user_s_association_to_a_team_response.freeze new file mode 100644 index 00000000000..41a13b9fdc5 --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_Represents_a_user_s_association_to_a_team_response.freeze @@ -0,0 +1 @@ +2026-03-31T14:57:49.739Z \ No newline at end of file diff --git a/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_Represents_a_user_s_association_to_a_team_response.json b/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_Represents_a_user_s_association_to_a_team_response.json new file mode 100644 index 00000000000..2ef4c1eb7dd --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Add_a_user_to_a_team_returns_Represents_a_user_s_association_to_a_team_response.json @@ -0,0 +1,155 @@ +[ + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"data\":{\"attributes\":{\"handle\":\"test-handle-3170c6f6f5b25b4d\",\"name\":\"test-name-3170c6f6f5b25b4d\"},\"type\":\"team\"}}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v2/team", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"data\":{\"id\":\"95ac9e78-0a56-4a6a-9e5e-21580dc141cc\",\"type\":\"team\",\"attributes\":{\"avatar\":null,\"banner\":9,\"created_at\":\"2026-03-31T14:57:54.888553+00:00\",\"description\":null,\"handle\":\"test-handle-3170c6f6f5b25b4d\",\"hidden_modules\":null,\"is_managed\":false,\"link_count\":0,\"modified_at\":\"2026-03-31T14:57:54.888553+00:00\",\"name\":\"test-name-3170c6f6f5b25b4d\",\"summary\":null,\"user_count\":0,\"visible_modules\":null},\"relationships\":{\"team_links\":{\"data\":[],\"links\":{\"related\":\"/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/links\"}},\"user_team_permissions\":{\"data\":null,\"links\":{\"related\":\"/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/permission-settings\"}}}}}", + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "statusCode": 201, + "reasonPhrase": "Created" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "0d46afe4-41c5-ca57-11b3-1cc706ef2425" + }, + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"data\":{\"attributes\":{\"email\":\"Test-Add_a_user_to_a_team_returns_Represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com\",\"title\":\"user title\"},\"type\":\"users\"}}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v2/users", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"data\": {\"type\": \"users\", \"id\": \"ebb17d15-5e46-4440-856f-75710cbbce4b\", \"attributes\": {\"name\": null, \"handle\": \"test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com\", \"created_at\": \"2026-03-31T14:57:55.106406+00:00\", \"modified_at\": \"2026-03-31T14:57:55.106406+00:00\", \"email\": \"test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com\", \"icon\": \"https://secure.gravatar.com/avatar/52a30c814f85968a9d363cc103840284?s=48&d=retro\", \"title\": \"user title\", \"verified\": false, \"service_account\": false, \"disabled\": false, \"allowed_login_methods\": [], \"status\": \"Pending\", \"last_login_time\": null}, \"relationships\": {\"roles\": {\"data\": []}, \"org\": {\"data\": {\"type\": \"orgs\", \"id\": \"4dee724d-00cc-11ea-a77b-570c9d03c6c5\"}}}}}", + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "statusCode": 201, + "reasonPhrase": "Created" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "a52463fd-793a-1c72-cc09-6d63c811d620" + }, + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"data\":{\"attributes\":{\"role\":\"admin\"},\"relationships\":{\"user\":{\"data\":{\"id\":\"ebb17d15-5e46-4440-856f-75710cbbce4b\",\"type\":\"users\"}}},\"type\":\"team_memberships\"}}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/memberships", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"data\":{\"id\":\"TeamMembership-95ac9e78-0a56-4a6a-9e5e-21580dc141cc-66215040\",\"type\":\"team_memberships\",\"attributes\":{\"provisioned_by\":null,\"provisioned_by_id\":\"a1d5ff5a-c6dd-11f0-9cb6-06640ca27ad4\",\"role\":\"admin\"},\"relationships\":{\"user\":{\"data\":{\"id\":\"ebb17d15-5e46-4440-856f-75710cbbce4b\",\"type\":\"users\"}}}},\"included\":[{\"id\":\"ebb17d15-5e46-4440-856f-75710cbbce4b\",\"type\":\"users\",\"attributes\":{\"disabled\":false,\"email\":\"test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com\",\"handle\":\"test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/52a30c814f85968a9d363cc103840284?d=retro\\u0026s=48\",\"name\":null,\"service_account\":false,\"status\":\"Pending\"}}]}", + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "statusCode": 200, + "reasonPhrase": "OK" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "f45f7198-3d4d-db9e-318c-b47bf6d2300c" + }, + { + "httpRequest": { + "headers": {}, + "method": "DELETE", + "path": "/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/memberships/ebb17d15-5e46-4440-856f-75710cbbce4b", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "headers": {}, + "statusCode": 204, + "reasonPhrase": "No Content" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "b7082329-3c72-4c4d-d096-0cb7c9dcb9c3" + }, + { + "httpRequest": { + "headers": {}, + "method": "DELETE", + "path": "/api/v2/users/ebb17d15-5e46-4440-856f-75710cbbce4b", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "headers": {}, + "statusCode": 204, + "reasonPhrase": "No Content" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "220d4ba7-8709-dd0d-a7a8-2f8319b01e90" + }, + { + "httpRequest": { + "headers": {}, + "method": "DELETE", + "path": "/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "headers": {}, + "statusCode": 204, + "reasonPhrase": "No Content" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "63c1c7a0-2f25-f84c-7456-42a0d2916117" + } +] \ No newline at end of file diff --git a/src/test/resources/com/datadog/api/client/v2/api/teams.feature b/src/test/resources/com/datadog/api/client/v2/api/teams.feature index c24ced9ffbf..b21078ebf32 100644 --- a/src/test/resources/com/datadog/api/client/v2/api/teams.feature +++ b/src/test/resources/com/datadog/api/client/v2/api/teams.feature @@ -27,21 +27,28 @@ Feature: Teams When the request is sent Then the response status is 204 Added - @generated @skip @team:DataDog/aaa-omg + @team:DataDog/aaa-omg Scenario: Add a user to a team returns "API error response." response Given new "CreateTeamMembership" request - And request contains "team_id" parameter from "REPLACE.ME" - And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"team": {"data": {"id": "d7e15d9d-d346-43da-81d8-3d9e71d9a5e9", "type": "team"}}, "user": {"data": {"id": "b8626d7e-cedd-11eb-abf5-da7ad0900001", "type": "users"}}}, "type": "team_memberships"}} + And there is a valid "dd_team" in the system + And there is a valid "user" in the system + And there is a valid "team_membership" in the system + And request contains "team_id" parameter from "dd_team.data.id" + And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"user": {"data": {"id": "{{user.data.id}}", "type": "users"}}}, "type": "team_memberships"}} When the request is sent Then the response status is 409 API error response. - @generated @skip @team:DataDog/aaa-omg + @team:DataDog/aaa-omg Scenario: Add a user to a team returns "Represents a user's association to a team" response Given new "CreateTeamMembership" request - And request contains "team_id" parameter from "REPLACE.ME" - And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"team": {"data": {"id": "d7e15d9d-d346-43da-81d8-3d9e71d9a5e9", "type": "team"}}, "user": {"data": {"id": "b8626d7e-cedd-11eb-abf5-da7ad0900001", "type": "users"}}}, "type": "team_memberships"}} + And there is a valid "dd_team" in the system + And there is a valid "user" in the system + And request contains "team_id" parameter from "dd_team.data.id" + And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"user": {"data": {"id": "{{user.data.id}}", "type": "users"}}}, "type": "team_memberships"}} When the request is sent Then the response status is 200 Represents a user's association to a team + And the response "data.attributes.role" is equal to "admin" + And the response "data.relationships.user.data.id" is equal to "{{ user.data.id }}" @team:DataDog/aaa-omg Scenario: Create a team hierarchy link returns "Conflict" response