# List access tokens

GET https://app.launchdarkly.com/api/v2/tokens

Fetch a list of all access tokens.

Reference: https://launchdarkly.com/docs/api/access-tokens/get-tokens

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/tokens:
    get:
      operationId: get-tokens
      summary: List access tokens
      description: Fetch a list of all access tokens.
      tags:
        - subpackage_accessTokens
      parameters:
        - name: showAll
          in: query
          description: >-
            If set to true, and the authentication access token has the 'Admin'
            role, personal access tokens for all members will be retrieved.
          required: false
          schema:
            type: boolean
        - name: limit
          in: query
          description: >-
            The number of access tokens to return in the response. Defaults to
            25.
          required: false
          schema:
            type: integer
            format: int64
        - name: offset
          in: query
          description: >-
            Where to start in the list. This is for use with pagination. For
            example, an offset of 10 skips the first ten items and then returns
            the next items in the list, up to the query `limit`.
          required: false
          schema:
            type: integer
            format: int64
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Access tokens collection response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Tokens'
        '401':
          description: Invalid access token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedErrorRep'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ForbiddenErrorRep'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitedErrorRep'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    ObjectId:
      type: string
      title: ObjectId
    Link:
      type: object
      properties:
        href:
          type: string
          description: The URL of the link
        type:
          type: string
          description: The type of the link
      title: Link
    MemberSummary:
      type: object
      properties:
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        _id:
          type: string
          description: The member's ID
        firstName:
          type: string
          description: The member's first name
        lastName:
          type: string
          description: The member's last name
        role:
          type: string
          description: >-
            The member's base role. If the member has no additional roles, this
            role will be in effect.
        email:
          type: string
          description: The member's email address
      required:
        - _links
        - _id
        - role
        - email
      title: MemberSummary
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    ActionSpecifier:
      type: string
      title: ActionSpecifier
    StatementEffect:
      type: string
      enum:
        - allow
        - deny
      description: Whether this statement should allow or deny actions on the resources.
      title: StatementEffect
    Statement:
      type: object
      properties:
        resources:
          type: array
          items:
            type: string
          description: Resource specifier strings
        notResources:
          type: array
          items:
            type: string
          description: >-
            Targeted resources are the resources NOT in this list. The
            <code>resources</code> and <code>notActions</code> fields must be
            empty to use this field.
        actions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: Actions to perform on a resource
        notActions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: >-
            Targeted actions are the actions NOT in this list. The
            <code>actions</code> and <code>notResources</code> fields must be
            empty to use this field.
        effect:
          $ref: '#/components/schemas/StatementEffect'
          description: >-
            Whether this statement should allow or deny actions on the
            resources.
      required:
        - effect
      title: Statement
    Token:
      type: object
      properties:
        _id:
          $ref: '#/components/schemas/ObjectId'
          description: The ID of the access token
        ownerId:
          $ref: '#/components/schemas/ObjectId'
          description: The ID of the owner of the account for the access token
        memberId:
          $ref: '#/components/schemas/ObjectId'
          description: The ID of the member who created the access token
        _member:
          $ref: '#/components/schemas/MemberSummary'
          description: Details on the member who created the access token
        name:
          type: string
          description: A human-friendly name for the access token
        description:
          type: string
          description: A description for the access token
        creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the access token was created
        lastModified:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of the last modification of the access token
        customRoleIds:
          type: array
          items:
            $ref: '#/components/schemas/ObjectId'
          description: >-
            A list of custom role IDs to use as access limits for the access
            token
        inlineRole:
          type: array
          items:
            $ref: '#/components/schemas/Statement'
          description: >-
            An array of policy statements, with three attributes: effect,
            resources, actions. May be used in place of a role.
        role:
          type: string
          description: Base role for the token
        token:
          type: string
          description: >-
            The token value. When creating or resetting, contains the entire
            token value. Otherwise, contains the last four characters.
        serviceToken:
          type: boolean
          description: Whether this is a service token or a personal token
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        defaultApiVersion:
          type: integer
          description: The default API version for this token
        lastUsed:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the access token was last used
      required:
        - _id
        - ownerId
        - memberId
        - creationDate
        - lastModified
        - _links
      title: Token
    Tokens:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Token'
          description: An array of access tokens
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
        totalCount:
          type: integer
          description: The number of access tokens returned
      title: Tokens
    UnauthorizedErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: UnauthorizedErrorRep
    ForbiddenErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: ForbiddenErrorRep
    RateLimitedErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: RateLimitedErrorRep
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

```

## SDK Code Examples

```python
import requests

url = "https://app.launchdarkly.com/api/v2/tokens"

headers = {"Authorization": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/tokens';
const options = {method: 'GET', headers: {Authorization: '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://app.launchdarkly.com/api/v2/tokens"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("Authorization", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://app.launchdarkly.com/api/v2/tokens")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://app.launchdarkly.com/api/v2/tokens")
  .header("Authorization", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://app.launchdarkly.com/api/v2/tokens', [
  'headers' => [
    'Authorization' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/tokens");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/tokens")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```