> ## 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 以程式化方式建立新的使用者帳戶。

透過 API 以程式化方式建立新的使用者帳戶。此 mutation 會佈建一個完整的使用者，包含帳戶、網路席位、餘額與推薦功能。

<Warning>
  **限制存取**

  此端點需要 Fluz 的特殊許可。請聯絡您的客戶經理以為您的應用程式啟用使用者註冊功能。
</Warning>

```graphql theme={null}
mutation RegisterUser(
  $firstName: String!
  $lastName: String!
  $phoneNumber: String!
  $regionCode: String!
  $emailAddress: String!
  $dateOfBirth: String!
) {
  registerUser(
    firstName: $firstName
    lastName: $lastName
    phoneNumber: $phoneNumber
    regionCode: $regionCode
    emailAddress: $emailAddress
    dateOfBirth: $dateOfBirth
  ) {
    success
    error
  }
}
```

<br />

### 參數

| 參數           | 型別     | 必填  | 說明                                                       |
| :----------- | :----- | :-- | :------------------------------------------------------- |
| firstName    | String | Yes | 使用者的名字                                                   |
| lastName     | String | Yes | 使用者的姓氏                                                   |
| phoneNumber  | String | Yes | 使用者的電話號碼（接受數字與 `-`）。例如，`"5551234567"` 或 `"555-123-4567"` |
| regionCode   | String | YES | 電話號碼的 ISO 3166-1 alpha-2 國家/地區代碼（例如，`"US"`、`"CA"`）       |
| emailAddress | String | Yes | 使用者的電子郵件地址                                               |
| dateOfBirth  | String | Yes | 使用者的出生日期，格式為 `YYYY-MM-DD`                                |

<br />

### 回應

#### 成功回應

```json theme={null}
{
  "data": {
    "registerUser": {
      "success": true,
      "error": null
    }
  }
}
```

<br />

### 回應欄位

| 欄位        | 型別                | 說明                                                 |
| :-------- | :---------------- | :------------------------------------------------- |
| `success` | Boolean           | 若成功註冊使用者則為 `true`                                  |
| `error`   | RegisterUserError | 若 `success` 為 false，會回傳包含 `message` 與 `code` 的錯誤物件 |

<br />

> 注意：此 mutation 會在回應資料中回傳錯誤，而非作為 GraphQL 錯誤。請務必檢查 success 欄位，並在 success 為 false 時處理錯誤物件。

### 範例請求

```curl theme={null}
curl -X POST https://transactional-graph.staging.fluzapp.com/api/v1/graphql \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_access_token>" \
  -d '{
  "query": "mutation RegisterUser($firstName: String!, $lastName: String!, $phoneNumber: String!, $regionCode: String!, $emailAddress: String!, $dateOfBirth: String!) { registerUser(firstName: $firstName, lastName: $lastName, phoneNumber: $phoneNumber, regionCode: $regionCode, emailAddress: $emailAddress, dateOfBirth: $dateOfBirth) { success error { code message } } }",
  "variables": {
    "firstName": "Jane",
    "lastName": "Doe",
    "phoneNumber": "5551234567",
    "regionCode": "US",
    "emailAddress": "jane.doe@example.com",
    "dateOfBirth": "1990-05-15"
  }
}'
```

```typescript theme={null}
const response = await fetch('https://transactional-graph.staging.fluzapp.com/api/v1/graphql', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${accessToken}`
  },
  body: JSON.stringify({
    query: `
      mutation RegisterUser(
        $firstName: String!
        $lastName: String!
        $phoneNumber: String!
        $regionCode: String!
        $emailAddress: String!
        $dateOfBirth: String!
      ) {
        registerUser(
          firstName: $firstName
          lastName: $lastName
          phoneNumber: $phoneNumber
          regionCode: $regionCode
          emailAddress: $emailAddress
          dateOfBirth: $dateOfBirth
        ) {
          success
          error {
            code
            message
          }
        }
      }
    `,
    variables: {
      firstName: "Jane",
      lastName: "Doe",
      phoneNumber: "5551234567",
      regionCode: "US",
      emailAddress: "jane.doe@example.com",
      dateOfBirth: "1990-05-15"
    }
  })
});

const data = await response.json();

if (data.data.registerUser.success) {
  console.log('User registered successfully!');
} else {
  console.error('Registration failed:', data.data.registerUser.error);
}
```

### 錯誤代碼

| 代碼          | 訊息                                                         | 說明                                  |
| :---------- | :--------------------------------------------------------- | :---------------------------------- |
| `AUTH-0004` | Invalid phone number                                       | 電話號碼格式無效，或無法以給定的地區代碼解析。             |
| `AUTH-0022` | Registration not allowed, please contact customer support! | 您的應用程式沒有註冊使用者的權限。請聯絡 Fluz 支援以啟用此功能。 |
| `AUTH-0025` | Please try again or contact support.                       | 發生一般性的註冊失敗。請重試或聯絡支援。                |
| `AUTH-0026` | The phone number you chose is already in use.              | 該電話號碼已與現有帳戶關聯。                      |
| `AUTH-0027` | The email address you chose is already in use.             | 該電子郵件地址已與現有帳戶關聯。                    |
| `AUTH-0030` | Your application is not active.                            | 您的應用程式未啟用，無法註冊使用者。                  |

<br />
