# 快速入門

> 透過幾個簡單步驟開始使用 Turso API。
> Canonical HTML: https://tursodb.cn/zh-tw/docs/api-reference/quickstart/
> Upstream Source (MIT): https://docs.turso.tech/api-reference/quickstart
> Language: zh-TW

---
<div class="doc-callout doc-callout-info"><div class="doc-callout-title">注意</div><div class="doc-callout-body">

**使用 TypeScript？** 您可以略過原始 HTTP 範例，改用 [`@tursodatabase/api`](https://www.npmjs.com/package/@tursodatabase/api) 用戶端。請參閱 [SDK 快速入門](/zh-tw/docs/api-reference/introduction/#quickstart-with-the-typescript-sdk)。

</div></div>


**1. 使用 Turso CLI 註冊或登入**

如果您尚未安裝，請務必先[安裝 Turso CLI](/zh-tw/docs/cli/installation/)。

```bash Signup
turso auth signup
```

```bash Login
turso auth login
```

**2. 取得您的帳號或組織 slug**

Platform API 可用於您的個人帳號或組織。您需要使用 Turso CLI 取得帳號或組織的 `slug`：

```bash
turso org list
```

**3. 建立新的 Platform API Token**

現在使用 Turso CLI 建立新的 API Token：

```bash
turso auth api-tokens mint quickstart
```

您可以使用 `--org` 將權杖限定於特定組織：

```bash
turso auth api-tokens mint quickstart --org my-org
```

<div class="doc-callout doc-callout-info"><div class="doc-callout-title">注意</div><div class="doc-callout-body">

請務必將權杖保存在安全的地方。我們接下來會用到它。

</div></div>


**4. 取得可用的位置**

在我們於特定區域建立群組或資料庫之前，需要先取得可用區域的清單：

```bash cURL
curl -L 'https://api.turso.tech/v1/locations' \
  -H 'Authorization: Bearer TOKEN' \
```

```ts Node.js
import { createClient } from "@tursodatabase/api";

const turso = createClient({
  org: "...",
  token: "",
});

const locations = await turso.locations.list();
```

<div class="doc-callout doc-callout-info"><div class="doc-callout-title">注意</div><div class="doc-callout-body">

`organizationSlug` 是您的組織或個人帳號名稱。

</div></div>


**5. 建立群組**

所有資料庫都屬於某個群組，而該群組可以存在於一個或多個位置。

首先建立群組，為其指定 `name` 與主要 `location`：

```bash cURL
curl -L -X POST 'https://api.turso.tech/v1/organizations/{organizationSlug}/groups' \
  -H 'Authorization: Bearer TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
      "name": "default",
      "location": "lhr"
  }'
```

```ts Node.js
import { createClient } from "@tursodatabase/api";

const turso = createClient({
  org: "...",
  token: "",
});

const group = await turso.groups.addLocation("default", "lhr");
```

**6. 建立資料庫**

現在在您剛才建立的群組中建立第一個資料庫：

```bash cURL
curl -L -X POST 'https://api.turso.tech/v1/organizations/{organizationSlug}/databases' \
  -H 'Authorization: Bearer TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
      "name": "my-db",
      "group": "default"
  }'
```

```ts Node.js
import { createClient } from "@tursodatabase/api";

const turso = createClient({
  org: "...",
  token: "",
});

const database = await turso.databases.create("my-db", "ams");
```

**7. 連線至您的資料庫**

您現在已有一個分散於多個區域的資料庫，可以使用下列任一官方或實驗性 SDK 連線：

<div class="doc-cards">
<a class="doc-card" href="/zh-tw/docs/sdk/ts/quickstart/"><div class="doc-card-title"><span>TypeScript</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<a class="doc-card" href="/zh-tw/docs/sdk/rust/quickstart/"><div class="doc-card-title"><span>Rust</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<a class="doc-card" href="/zh-tw/docs/sdk/go/quickstart/"><div class="doc-card-title"><span>Go</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<a class="doc-card" href="/zh-tw/docs/sdk/python/quickstart/"><div class="doc-card-title"><span>Python</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<div class="doc-card doc-card-static"><div class="doc-card-title"><span>Android</span></div></div>
<a class="doc-card" href="/zh-tw/docs/sdk/swift/quickstart/"><div class="doc-card-title"><span>Swift</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<a class="doc-card" href="/zh-tw/docs/sdk/php/quickstart/"><div class="doc-card-title"><span>PHP</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<div class="doc-card doc-card-static"><div class="doc-card-title"><span>Ruby</span></div></div>
<div class="doc-card doc-card-static"><div class="doc-card-title"><span>Ruby on Rails</span></div></div>
<div class="doc-card doc-card-static"><div class="doc-card-title"><span>C</span></div></div>
</div>
<div class="doc-cards">

</div>
