Skip to content

Edit and retrieve entries in bulk

With hakocms-cli, you can do in bulk the work that takes a long time when you fix entries one at a time in the admin. The examples on this page use blog as the space and posts as the content type ID.

  • You are logged in with hakocms-cli and have set the space (hakocms-cli spaces use blog; see Log in with the CLI). If you have not set it, add --space blog to each command
  • You have a role that can edit and publish entries (owner, admin, or editor)
  • Before you run a bulk operation, try it on a small number of entries. Deletions cannot be undone

By default, a list returns 30 entries. Use --all to go through all pages.

ターミナルウィンドウ
hakocms-cli entries list -t posts --all
Filter Flag Example
Status --status --status draft (draft), --status published,closed (entries that match any of them)
Words --query --query お知らせ (full-text search)
Order --orders --orders -updatedAt (most recently updated first; - means descending)
Count --limit --limit 100

The status values are draft (draft), published (published), closed (unpublished), and reserved (waiting for scheduled publishing). When a published entry has a draft, the [STATUS] column in the list shows published_with_draft.

With --jq, you can filter JSON with a jq expression. You do not need to install jq separately.

ターミナルウィンドウ
hakocms-cli entries list -t posts --status draft --all --jq '.[].id'

The IDs are shown one per line.

wsa5cu2ittq5
9ngd93ymaerr
hfyrv6ip6ol0

Publish all draft entries. Pass the IDs you retrieved above to entries publish one at a time.

ターミナルウィンドウ
hakocms-cli entries list -t posts --status draft --all --jq '.[].id' |
while read -r id; do
hakocms-cli entries publish "$id" -t posts --jq '"\(.id) \(.status)"'
done

The ID and status of each published entry are shown.

wsa5cu2ittq5 published
9ngd93ymaerr published
hfyrv6ip6ol0 published

If an entry cannot be published (for example, a required field is empty), the reason is shown on that line and the loop moves on to the next entry. Because --jq is set, the reason is shown as JSON.

{"error":{"status":400,"message":"title: is required"}}

In the same way, you can run entries unpublish (unpublish) and entries delete (delete) in bulk. When you delete, the CLI asks for confirmation for each entry. It cannot ask outside a terminal (in a pipe or a script), so add --force.

entries update layers the --set values over the current values and saves the result as a draft. Fields you do not specify stay as they are.

ターミナルウィンドウ
hakocms-cli entries update <entry ID> -t posts --set body=書き換えた本文
  • A --set value is sent as JSON if it can be read as JSON, and as a string otherwise. --set count=3 is a number, --set featured=true is a boolean, --set tags='["news","tech"]' is an array, and --set title=hello is a string
  • To set the string 3 or true, write it as a JSON string (--set code='"3"')
  • When you change a published entry, the published revision stays as it is, and a draft is created (the status is published_with_draft). To publish right away, add --publish

This example appends the same sentence to the end of body in every entry.

ターミナルウィンドウ
hakocms-cli entries list -t posts --all --jq '.[].id' |
while read -r id; do
body=$(hakocms-cli entries get "$id" -t posts \
--jq '(.draft // .published).body // ""')
hakocms-cli entries update "$id" -t posts \
--set "body=${body}(この記事は 2026 年 10 月に更新しました)" --jq .id
done

(.draft // .published) uses the draft’s values if there is a draft, and the published revision’s values otherwise.

You can retrieve entries as JSON and pass them to other tools. --json outputs the Admin API response as it is (for a list, an array of entries).

ターミナルウィンドウ
hakocms-cli entries list -t posts --all --json > posts.json

To output only the items you need, as one JSON object per line, use tojson.

ターミナルウィンドウ
hakocms-cli entries list -t posts --all \
--jq '.[] | {id, title: .published.title} | tojson'
{"id":"hfyrv6ip6ol0","title":"お知らせ 1"}
{"id":"9ngd93ymaerr","title":"お知らせ 2"}
{"id":"wsa5cu2ittq5","title":"お知らせ 3"}

To retrieve entries in the form you show on your site (with references expanded and so on), use the Content API instead of the CLI (Read entries). To copy a whole space to another environment, use hakocms-cli exports create and imports create (CLI command reference: exports).

Write the values in a JSON file and pass it with --data @<file>. To pass them on standard input, use --data -.

{ "title": "ファイルから", "body": "JSON で渡しました" }
ターミナルウィンドウ
hakocms-cli entries create -t posts --data @post.json --publish

With --publish, the entry is published instead of saved as a draft. Without it, the entry is a draft.

When you move from another CMS, split the data into one file per entry, then pass each file to entries create in a loop.

ターミナルウィンドウ
for f in export/*.json; do
hakocms-cli entries create -t posts --data "@$f" --jq .id
done

The shapes of field values (images, references, rich text, and so on) are in Field types and value formats and Rich text format. Upload images first, then put their URL in the value in the form {"url": "<URL>"} (Upload media with the CLI).

entries edit writes the entry’s values to a JSON file and opens it in an editor. When you save and close it, the values are saved as a draft.

ターミナルウィンドウ
hakocms-cli entries edit <entry ID> -t posts

The editor is chosen by the environment variable VISUAL, or EDITOR if VISUAL is not set (export EDITOR=vim).

ターミナルウィンドウ
hakocms-cli entries schedule <entry ID> -t posts --publish-at 2026-11-01T09:00:00+09:00
  • Write the date and time in RFC 3339 format with a time zone offset (+09:00 for Japan time)

  • The date and time to unpublish is --close-at. Both must be within 1 year from now

  • To cancel a schedule, pass null with --data

    ターミナルウィンドウ
    hakocms-cli entries schedule <entry ID> -t posts --data '{"closeAt":null}'

In the admin, open the list of entries for the content type, and check that the statuses and values have changed. From the CLI, list the entries with the same filters and count them.

ターミナルウィンドウ
hakocms-cli entries list -t posts --status draft --all --jq 'length'