🙆

DrupalのJSON:APIでcreatedやchangedに対するフィルタを適用する

に公開

概要

DrupalのJSON:APIでcreatedやchangedに対するフィルタを適用する方法の備忘録です。

背景

以下を参考にしました。

https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/filtering

例えば、6/2以降に更新されたものだけをフィルタリングしようとした際、以下のクエリでは適切に動作しませんでした。

?filter[a-label][condition][path]=changed&filter[a-label][condition][operator]=%3E%3D&filter[a-label][condition][value]=2025-06-02

正しい方法

以下の記事が参考になりました。

https://www.reddit.com/r/drupal/comments/1bdvu61/json_api_drupal_filter_on_date/

Note that timestamp fields (like created or changed) currently must use a timestamp for filtering:

タイムスタンプフィールド(createdやchangedなど)は現在、フィルタリングにタイムスタンプを使用する必要があります。

例えば、2025/6/2のタイムスタンプ1748790000を用いて、以下のようなクエリを使用することで、正しくフィルタリングできました。

?filter[a-label][condition][path]=changed&filter[a-label][condition][operator]=%3E%3D&filter[a-label][condition][value]=1748790000

まとめ

DrupalのJSON:APIで、createdやchangedに対するフィルタを適用する際にお役に立てば幸いです。

Discussion