> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fluz.app/llms.txt
> Use this file to discover all available pages before exploring further.

# 生成用户访问令牌

> 将 API 凭证交换为具备范围的用户访问令牌。

```javascript theme={null}
import { GraphQLClient, gql } from 'graphql-request';

const API_URL = 'https://transactional-graph.staging.fluzapp.com/api/v1/graphql';
const API_KEY = '<YOUR_API_KEY>';
const USER_ID = '<YOUR_USER_ID>';
const ACCOUNT_ID = '<YOUR_ACCOUNT_ID>';

const SCOPES = [
  'LIST_PURCHASES',
  'LIST_OFFERS',
  'LIST_PAYMENT',
  'REVEAL_GIFTCARD',
  'PURCHASE_GIFTCARD',
  'MANAGE_PAYMENT',
];

const GENERATE_USER_ACCESS_TOKEN = gql`
  mutation generateUserAccessToken(
    $userId: UUID!
    $accountId: UUID!
    $scopes: [ScopeType!]!
    $seatId: UUID
  ) {
    generateUserAccessToken(
      userId: $userId
      accountId: $accountId
      scopes: $scopes
      seatId: $seatId
    ) {
      token
      scopes
    }
  }
`;

async function generateUserAccessToken() {
  const client = new GraphQLClient(API_URL, {
    headers: {
      Authorization: `Basic ${API_KEY}`,
      'Content-Type': 'application/json',
    },
  });

  const data = await client.request(GENERATE_USER_ACCESS_TOKEN, {
    userId: USER_ID,
    accountId: ACCOUNT_ID,
    scopes: SCOPES,
  });

  console.log('Access Token:', JSON.stringify(data, null, 2));
}

generateUserAccessToken();
```

Related: [身份验证](/get-started/api-credentials).
