|
1 | 1 | ---
|
2 |
| -page_title: /teams/authentication-token API reference for HCP Terraform |
| 2 | +page_title: /teams/:team_id/authentication-tokens API reference for HCP Terraform |
3 | 3 | description: >-
|
4 |
| - Use the HCP Terraform API's `/teams/authentication-token` endpoint to generate, delete, and list a team's API tokens. |
| 4 | + Use the HCP Terraform API's `/teams/:team_id/authentication-tokens` endpoint to generate, delete, and list a team's API tokens. |
5 | 5 | ---
|
6 | 6 |
|
7 | 7 | [200]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200
|
@@ -38,7 +38,265 @@ description: >-
|
38 | 38 |
|
39 | 39 | # Team tokens API reference
|
40 | 40 |
|
41 |
| -Team API tokens grant access to a team's workspaces. Each team can have an API token that is not associated with a specific user. You can create and delete team tokens and list an organization's team tokens. |
| 41 | +Team API tokens grant access to a team's workspaces. Teams are not limited to a single token, and can have multiple, valid tokens at a time. Team tokens are not are not associated with a specific user. |
| 42 | + |
| 43 | +Teams relying on the [**legacy**](/terraform/cloud-docs/api-docs/team-tokens#legacy-team-tokens-api-reference) team token API (`/teams/authentication-token`), can only have a **single**, valid token at a time. Generating a new legacy token revokes any previously existing tokens, replacing it with the new team token. |
| 44 | + |
| 45 | +You can create and delete team tokens and list an organization's team tokens. |
| 46 | + |
| 47 | +## Generate a new team token |
| 48 | + |
| 49 | +Generates a new team token. |
| 50 | + |
| 51 | +| Method | Path | |
| 52 | +| :----- | :----------------------------------- | |
| 53 | +| POST | /teams/:team_id/authentication-tokens | |
| 54 | + |
| 55 | +This endpoint returns the secret text of the new authentication token. You can only access this token when you create it and can not recover it later. |
| 56 | + |
| 57 | +### Parameters |
| 58 | + |
| 59 | +- `:team_id` (`string: <required>`) - specifies the team ID for generating the team token |
| 60 | + |
| 61 | +### Request body |
| 62 | + |
| 63 | +This POST endpoint requires a JSON object with the following properties as a request payload. |
| 64 | + |
| 65 | + |
| 66 | +| Key path | Type | Default | Description | |
| 67 | +| ----------------------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------- | |
| 68 | +| `data.type` | string | | Must be `"authentication-token"`. | |
| 69 | +| `data.attributes.description` | string | | The description of the team token. Each description **must** be unique. | |
| 70 | +| `data.attributes.expired-at` | string | `null` | The UTC date and time that the Team Token will expire, in ISO 8601 format. If omitted or set to `null` the token will never expire. | |
| 71 | + |
| 72 | +### Sample payload |
| 73 | + |
| 74 | +```json |
| 75 | +{ |
| 76 | + "data": { |
| 77 | + "type": "authentication-token", |
| 78 | + "attributes": { |
| 79 | + "description": "Team API token for team ABC", |
| 80 | + "expired-at": "2023-04-06T12:00:00.000Z" |
| 81 | + } |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +### Sample request |
| 87 | + |
| 88 | +```shell |
| 89 | +curl \ |
| 90 | + --header "Authorization: Bearer $TOKEN" \ |
| 91 | + --header "Content-Type: application/vnd.api+json" \ |
| 92 | + --request POST \ |
| 93 | + --data @payload.json \ |
| 94 | + https://app.terraform.io/api/v2/teams/team-BUHBEM97xboT8TVz/authentication-tokens |
| 95 | +``` |
| 96 | + |
| 97 | +### Sample response |
| 98 | + |
| 99 | +```json |
| 100 | +{ |
| 101 | + "data": { |
| 102 | + "id": "4111797", |
| 103 | + "type": "authentication-tokens", |
| 104 | + "attributes": { |
| 105 | + "created-at": "2017-11-29T19:18:09.976Z", |
| 106 | + "last-used-at": null, |
| 107 | + "description": "Team API token for team ABC", |
| 108 | + "token": "QnbSxjjhVMHJgw.atlasv1.gxZnWIjI5j752DGqdwEUVLOFf0mtyaQ00H9bA1j90qWb254lEkQyOdfqqcq9zZL7Sm0", |
| 109 | + "expired-at": "2023-04-06T12:00:00.000Z" |
| 110 | + }, |
| 111 | + "relationships": { |
| 112 | + "team": { |
| 113 | + "data": { |
| 114 | + "id": "team-Y7RyjccPVBKVEdp7", |
| 115 | + "type": "teams" |
| 116 | + } |
| 117 | + }, |
| 118 | + "created-by": { |
| 119 | + "data": { |
| 120 | + "id": "user-62goNpx1ThQf689e", |
| 121 | + "type": "users" |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +``` |
| 129 | + |
| 130 | +## Delete the team token |
| 131 | + |
| 132 | +| Method | Path | |
| 133 | +| :----- | :----------------------------------- | |
| 134 | +| DELETE | /teams/:team_id/authentication-tokens | |
| 135 | + |
| 136 | +### Parameters |
| 137 | + |
| 138 | +- `:team_id` (`string: <required>`) - specifies the team_id from which to delete the token |
| 139 | + |
| 140 | +### Sample request |
| 141 | + |
| 142 | +```shell |
| 143 | +curl \ |
| 144 | + --header "Authorization: Bearer $TOKEN" \ |
| 145 | + --header "Content-Type: application/vnd.api+json" \ |
| 146 | + --request DELETE \ |
| 147 | + https://app.terraform.io/api/v2/teams/team-BUHBEM97xboT8TVz/authentication-tokens |
| 148 | +``` |
| 149 | + |
| 150 | +## List team tokens |
| 151 | + |
| 152 | +Lists the team tokens for the team. |
| 153 | + |
| 154 | +`GET /teams/:team_id/authentication-tokens` |
| 155 | + |
| 156 | +| Parameter | Description | |
| 157 | +|----------------------|----------------------------------------------------------| |
| 158 | +| `:team_id` | The ID of the team whose team tokens you want to list. | |
| 159 | + |
| 160 | +This endpoint returns object metadata and does not include secret authentication details of tokens. You can only view a token when you create it and cannot recover it later. |
| 161 | + |
| 162 | +By default, this endpoint returns tokens by ascending expiration date. |
| 163 | + |
| 164 | +| Status | Response | Reason | |
| 165 | +| ------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------- | |
| 166 | +| [200][] | [JSON API document][] (`type: "team-tokens"`) | The request was successful. | |
| 167 | +| [200][] | Empty [JSON API document][] | The specified team has no team tokens. | |
| 168 | +| [404][] | [JSON API error object][] | Team not found. | |
| 169 | + |
| 170 | +### Query parameters |
| 171 | + |
| 172 | +This endpoint supports pagination [with standard URL query parameters](/terraform/cloud-docs/api-docs#query-parameters) and searching with the `q` parameter. Remember to percent-encode `[` as `%5B` and `]` as `%5D` if your tooling doesn't automatically encode URLs. |
| 173 | + |
| 174 | +| Parameter | Description | |
| 175 | +|----------------|---------------------------------------------------------------------| |
| 176 | +| `page[number]` | **Optional.** If omitted, the endpoint returns the first page. | |
| 177 | +| `page[size]` | **Optional.** If omitted, the endpoint returns 20 tokens per page. | |
| 178 | +| `q` | **Optional.** A search query string. You can search for a team authentication token using the team name. | |
| 179 | +| `sort` | **Optional.** Allows sorting the team tokens by `"created-by"`, `"expired-at"`, and `"last-used-at"`. Prepending a hyphen to the sort parameter reverses the order. If omitted, the default sort order ascending. | |
| 180 | + |
| 181 | +### Sample response |
| 182 | + |
| 183 | +```json |
| 184 | +{ |
| 185 | + "data": [ |
| 186 | + { |
| 187 | + "id": "at-TLhN8cc6ro6qYDvp", |
| 188 | + "type": "authentication-tokens", |
| 189 | + "attributes": { |
| 190 | + "created-at": "2017-11-29T19:18:09.976Z", |
| 191 | + "last-used-at": null, |
| 192 | + "description": "Team API token for team ABC", |
| 193 | + "token": "QnbSxjjhVMHJgw.atlasv1.gxZnWIjI5j752DGqdwEUVLOFf0mtyaQ00H9bA1j90qWb254lEkQyOdfqqcq9zZL7Sm0", |
| 194 | + "expired-at": "2023-04-06T12:00:00.000Z" |
| 195 | + }, |
| 196 | + "relationships": { |
| 197 | + "team": { |
| 198 | + "data": { |
| 199 | + "id": "team-Y7RyjccPVBKVEdp7", |
| 200 | + "type": "teams" |
| 201 | + } |
| 202 | + }, |
| 203 | + "created-by": { |
| 204 | + "data": { |
| 205 | + "id": "user-ccU6h629sszLJBpY", |
| 206 | + "type": "users" |
| 207 | + } |
| 208 | + } |
| 209 | + } |
| 210 | + }, |
| 211 | + { |
| 212 | + "id": "at-qfc2wqqJ1T5sCamM", |
| 213 | + "type": "authentication-tokens", |
| 214 | + "attributes": { |
| 215 | + "created-at": "2024-06-19T18:44:44.051Z", |
| 216 | + "last-used-at": null, |
| 217 | + "description": "Team API token for team XYZ", |
| 218 | + "token": null, |
| 219 | + "expired-at": "2024-07-19T18:44:43.818Z" |
| 220 | + }, |
| 221 | + "relationships": { |
| 222 | + "team": { |
| 223 | + "data": { |
| 224 | + "id": "team-58pFiBffTLMxLphR", |
| 225 | + "type": "teams" |
| 226 | + } |
| 227 | + }, |
| 228 | + "created-by": { |
| 229 | + "data": { |
| 230 | + "id": "user-ccU6h629hhzLJBpY", |
| 231 | + "type": "users" |
| 232 | + } |
| 233 | + } |
| 234 | + } |
| 235 | + }, |
| 236 | + ] |
| 237 | +} |
| 238 | +``` |
| 239 | + |
| 240 | +## Show a team token |
| 241 | + |
| 242 | +Use this endpoint to display a [team token](/terraform/cloud-docs/users-teams-organizations/teams#api-tokens) for a particular team. |
| 243 | + |
| 244 | +`GET /authentication-tokens/:token-id` |
| 245 | + |
| 246 | +| Parameter | Description | |
| 247 | +| ----------- | ------------------------- | |
| 248 | +| `:token-id` | The ID of the Team Token. | |
| 249 | + |
| 250 | +The object returned by this endpoint only contains metadata, and does not include the secret text of the authentication token. A token's secret test is only shown upon creation, and cannot be recovered later. |
| 251 | + |
| 252 | +| Status | Response | Reason | |
| 253 | +| ------- | ------------------------------------------------------- | ------------------------------------------------------------ | |
| 254 | +| [200][] | [JSON API document][] (`type: "authentication-tokens"`) | The request was successful | |
| 255 | +| [404][] | [JSON API error object][] | Team Token not found, or unauthorized to view the Team Token | |
| 256 | + |
| 257 | +### Sample request |
| 258 | + |
| 259 | +```shell |
| 260 | +curl \ |
| 261 | + --header "Authorization: Bearer $TOKEN" \ |
| 262 | + --header "Content-Type: application/vnd.api+json" \ |
| 263 | + --request GET \ |
| 264 | + https://app.terraform.io/api/v2/authentication-tokens/at-6yEmxNAhaoQLH1Da |
| 265 | +``` |
| 266 | + |
| 267 | +### Sample response |
| 268 | + |
| 269 | +```json |
| 270 | +{ |
| 271 | + "data": { |
| 272 | + "id": "at-6yEmxNAhaoQLH1Da", |
| 273 | + "type": "authentication-tokens", |
| 274 | + "attributes": { |
| 275 | + "created-at": "2017-11-29T19:18:09.976Z", |
| 276 | + "last-used-at": null, |
| 277 | + "description": "Team API token for team ABC", |
| 278 | + "token": "QnbSxjjhVMHJgw.atlasv1.gxZnWIjI5j752DGqdwEUVLOFf0mtyaQ00H9bA1j90qWb254lEkQyOdfqqcq9zZL7Sm0", |
| 279 | + "expired-at": "2023-04-06T12:00:00.000Z" |
| 280 | + }, |
| 281 | + "relationships": { |
| 282 | + "team": { |
| 283 | + "data": { |
| 284 | + "id": "team-LnREdjodkvZFGdXL", |
| 285 | + "type": "teams" |
| 286 | + } |
| 287 | + }, |
| 288 | + "created-by": { |
| 289 | + "data": { |
| 290 | + "id": "user-MA4GL63FmYRpSFxa", |
| 291 | + "type": "users" |
| 292 | + } |
| 293 | + } |
| 294 | + } |
| 295 | + } |
| 296 | +} |
| 297 | +``` |
| 298 | + |
| 299 | +# Legacy team tokens API reference |
42 | 300 |
|
43 | 301 | ## Generate a new team token
|
44 | 302 |
|
@@ -296,4 +554,3 @@ curl \
|
296 | 554 | }
|
297 | 555 | }
|
298 | 556 | ```
|
299 |
| - |
|
0 commit comments