Quickstart: read entries with the API
On this page, you sign up for Hako CMS, write and publish one article, and retrieve that article with the API. It takes about 5 minutes.
At the end, you get JSON like the following back.
{ "items": [ { "sys": { "id": "hello", "contentType": "posts", "version": 1 }, "title": "はじめての記事" } ], "total": 1}What you need
Section titled “What you need”- An email address that can receive email
- A terminal where you can use
curl, or a browser
1. Sign up
Section titled “1. Sign up”Sign up on the free plan. It’s free.
- Open the sign-up screen.
- Enter [メールアドレス](Email address), [お名前](Name), and [パスワード(契約・お支払いの画面用)](Password for the account and billing screen).
- In [CMS のアドレス](CMS address), enter a name using lowercase letters, digits, and hyphens (for example, “my-site”). This name becomes your environment’s address,
https://<hostname>.hakocms.net. - Select [利用規約に同意します](I agree to the Terms of Service).
- Click [申し込む](Sign up).

If “ボットでないことを確認しています” (Checking that you’re not a bot) is shown below [申し込む], you’re signed up automatically when the check finishes. The check can take about 10 seconds.
You receive an email at the address you entered for setting your admin password.
2. Set your admin password
Section titled “2. Set your admin password”- Open the link in the email you received.
- In [パスワード](Password) and [パスワード(確認)](Password (confirm)), enter the password to use in the admin.
- Click [パスワードを設定してログイン](Set password and log in).

The admin (https://<hostname>.hakocms.net/admin) opens and shows “まだスペースがありません” (No spaces yet).
The password you entered on the sign-up screen (for the account and billing screen) and the admin password are different. Save both.
3. Create a space
Section titled “3. Create a space”A space is the unit that groups the entries of one site or app.
- Click [スペースを作成](Create space).
- Enter “ブログ” in [スペース名](Space name) and “blog” in [スペース ID](Space ID).
- Click [作成](Create).

“まだコンテンツタイプがありません” (No content types yet) is shown.
4. Create a content type
Section titled “4. Create a content type”A content type is a box that holds entries. Here, you use a template to create “記事” (Article).
- Click [コンテンツタイプを作成](Create content type).
- Check that [コレクション](Collection) is selected, then click [次へ](Next).
- Enter “記事” in [コンテンツタイプ名](Content type name) and “posts” in [エンドポイント](Endpoint), then click [次へ].
- Choose [ブログ記事](Blog post), then click [作成](Create).

“記事” is created with the fields title, description, featured image, and body, and the article list screen opens. The “posts” you entered in [エンドポイント] goes into the API URL.
5. Write and publish an article
Section titled “5. Write and publish an article”- Click [新規作成](New).
- Enter “はじめての記事” in [タイトル](Title) and any text you like in [本文](Body).
- On the right, enter “hello” in [エントリー ID(省略すると自動で付ける)](Entry ID (assigned automatically if omitted)). If you leave it empty, an ID is assigned automatically.
- Click [公開](Publish).
“公開しました” (Published) is shown, and the article status becomes [公開中](Published).
![The article screen after publishing. “公開中” (Published) is shown below the title and in [ステータス] (Status) on the right](/_astro/05-publish.BmxglZGf_ZqWgD8.webp)
6. Issue an API key
Section titled “6. Issue an API key”You need an API key to retrieve entries with the API.
- Click [API キー](API keys) in the left menu.
- Enter “quickstart” in [名前](Name), then click [発行](Issue).
An API key starting with hako_ is shown.
![The API keys screen. A key starting with hako_ is shown below “API キーを発行しました” (API key issued), and the quickstart key is listed with [読み取り] (Read)](/_astro/06-api-key.BbWlcgAJ_j4KjE.webp)
The key is shown only this once. Copy it and save it somewhere safe.
The permission of the key you issued is [読み取り](Read). It can only read published entries.
7. Retrieve entries with the API
Section titled “7. Retrieve entries with the API”Retrieve them with curl. Replace <hostname> with the name you chose in step 1, and <API key> with the key you saved in step 6.
curl https://<hostname>.hakocms.net/api/v1/content/posts \ -H "Authorization: Bearer <API key>"You get the following back (dates and times are omitted).
{ "items": [ { "sys": { "id": "hello", "contentType": "posts", "version": 1 }, "title": "はじめての記事", "body": { "type": "doc", "content": [ { "type": "paragraph", "content": [{ "type": "text", "text": "Hako CMS から配信しています。" }] } ] } } ], "total": 1, "limit": 20, "offset": 0}In JavaScript, you can retrieve them the same way with fetch. You can call it from any origin.
const res = await fetch("https://<hostname>.hakocms.net/api/v1/content/posts", { headers: { Authorization: "Bearer <API key>" },});const { items } = await res.json();console.log(items[0].title); // はじめての記事To retrieve a single entry, add the entry ID to the end of the URL (/api/v1/content/posts/hello).
You’ve now retrieved your first entry with the API.
Troubleshooting
Section titled “Troubleshooting”| What you got back | Cause | Fix |
|---|---|---|
401 unauthorized |
The API key is missing or wrong | Check that you put the key starting with hako_ as is after Authorization: Bearer . If you lost the key, issue a new one on the [API キー](API keys) screen |
404 not_found |
The content type or entry isn’t found | Check that posts in the URL matches [エンドポイント](Endpoint) in step 4. Check that the entry is [公開中](Published). Draft entries aren’t returned with a read key |
| Clicking [申し込む](Sign up) doesn’t move forward | The Terms of Service checkbox isn’t selected, or the check hasn’t finished | If “申し込むには、利用規約への同意が要ります” (You must agree to the Terms of Service to sign up) is shown, select [利用規約に同意します](I agree to the Terms of Service). If “ボットでないことを確認しています” (Checking that you’re not a bot) is shown, just wait |
If it still doesn’t work, contact us with the value of the X-Request-Id response header.
What to do next
Section titled “What to do next”- Read entries:
bodyis returned as JSON. Add?richText=htmlto the URL to receive it as an HTML string - Filter, sort, and paginate