Patch a content with JSON Patch

Craft Cross CMSのコンテンツをJSON Patchを使って部分更新します。

Required Scope

APIの実行に必要なScopeです。

beta.cms.content.patch

Required Role

管理画面でScopeを追加する際に必要な権限です。

Craft Cross CMS > CMSの編集
Recent Requests
Log in to see full request history
TimeStatusUser Agent
Retrieving recent requests…
LoadingLoading…
Body Params
string
required

コンテンツが所属するモデルのID

string
required

更新するコンテンツのID

operations
array
required
length ≥ 1

JSON Patch操作の配列。複数の操作を順に適用できます。

操作の種類

  • add: 指定したパスに値を追加
  • remove: 指定したパスの値を削除(注: モデルで定義されたフィールドは、フィールドタイプの空値にリセットされます。例: text型は空文字''、number型は0)
  • replace: 指定したパスの値を置換
  • move: 指定したパスから別のパスへ値を移動
  • copy: 指定したパスから別のパスへ値をコピー
  • test: 指定したパスの値が期待値と一致するか検証(一致しない場合はエラー)

パスの指定方法

パスはJSON Pointerフォーマット(RFC 6901)で指定します。

例:

  • トップレベルのフィールド: /title
  • ネストしたフィールド: /author/name
  • 配列の要素: /tags/0

使用例

[
  {
    "op": "replace",
    "path": "/title",
    "value": "Updated Title"
  },
  {
    "op": "add",
    "path": "/tags/-",
    "value": "new-tag"
  },
  {
    "op": "remove",
    "path": "/oldField"
  }
]

リッチテキストフィールドの指定方法

リッチテキストフィールドの値は json 要素のみ有効です。 text および html は無視されます。

例: ID richtext のリッチテキストフィールドに、 <h1>RichText</h1> という内容を指定する場合、次のように指定します。

{
  "op": "replace",
  "path": "/richtext",
  "value": {
    "json": {
      "type": "doc",
      "content": [
        {
          "type": "heading",
          "attrs": {
            "level": 1
          },
          "content": [
            {
              "type": "text",
              "text": "RichText"
            }
          ]
        }
      ]
    }
  }
}

画像フィールドの指定方法

画像フィールドの値は、メディアライブラリの画像のIDを文字列として指定してください。

例:image というIDの画像フィールドに、6347f05d5d18d4536af5f336 というIDの画像を指定する場合、次のように指定します。

{
  "op": "replace",
  "path": "/image",
  "value": "6347f05d5d18d4536af5f336"
}
operations*
string
enum
required

add operation

Allowed:
string
required

JSON Pointer path to the target location

required

The value to add

boolean
Defaults to false

この操作でHook V2のトリガーを発火するかどうか。(参照

Headers
string

今後利用する可能性のある予約語です。現在は設定不要です。

Response

Language
Credentials
Bearer
URL
LoadingLoading…
Response
Choose an example:
application/json