REST API 文档

💡 云策文档标注

概述

本文档详细介绍了 WordPress REST API 中应用密码的架构和端点操作。应用密码用于通过 API 进行身份验证,支持创建、检索、更新和删除操作。

关键要点

  • 应用密码记录包含多个字段,如 uuid、app_id、name、password、created、last_used 和 last_ip,每个字段都有特定的 JSON 数据类型、格式和上下文。
  • 支持通过 GET、POST 和 DELETE 方法操作应用密码,包括检索列表、创建新密码、更新和删除特定密码。
  • 所有端点都基于用户 ID 和 UUID 进行路径参数化,确保操作针对特定用户和密码记录。

代码示例

GET /wp/v2/users/<user_id>/application-passwords
$ curl https://example.com/wp-json/wp/v2/users/<user_id>/application-passwords

POST /wp/v2/users/<user_id>/application-passwords
参数:app_id(UUID v5 推荐)、name(必需)

DELETE /wp/v2/users/<user_id>/application-passwords/<uuid>
$ curl -X DELETE https://example.com/wp-json/wp/v2/users/<user_id>/application-passwords/<uuid>

注意事项

  • password 字段仅在创建后可用,且为只读,上下文为 edit。
  • last_used 和 last_ip 字段可能为 null,表示从未使用过。
  • 使用 context 参数(view、embed、edit)可以控制响应中包含的字段。

📄 原文内容

Schema

The schema defines all the fields that exist within a application password record. Any response from these endpoints can be expected to contain the fields below unless the `_filter` query parameter is used or the schema field only appears in a specific context.

uuid The unique identifier for the application password.

JSON data type: string,
Format: uuid

Read only

Context: view, edit, embed

app_id A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.

JSON data type: string,
Format: uuid

Context: view, edit, embed

name The name of the application password.

JSON data type: string

Context: view, edit, embed

password The generated password. Only available after adding an application.

JSON data type: string

Read only

Context: edit

created The GMT date the application password was created.

JSON data type: string,
Format: datetime (details)

Read only

Context: view, edit

last_used The GMT date the application password was last used.

JSON data type: string or null,
Format: datetime (details)

Read only

Context: view, edit

last_ip The IP address the application password was last used by.

JSON data type: string or null,
Format: ip

Read only

Context: view, edit

Retrieve a Application Password

Definition & Example Request

GET /wp/v2/users/<user_id>)/application-passwords

Query this endpoint to retrieve a specific application password record.

$ curl https://example.com/wp-json/wp/v2/users/<user_id>)/application-passwords

Arguments

context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit

Create a Application Password

Arguments

<a href="#schema-app_id">app_id</a> A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.
<a href="#schema-name">name</a> The name of the application password.

Required: 1

Definition

POST /wp/v2/users/<user_id>)/application-passwords

Delete a Application Password

There are no arguments for this endpoint.

Definition

DELETE /wp/v2/users/<user_id>)/application-passwords

Example Request

$ curl -X DELETE https://example.com/wp-json/wp/v2/users/<user_id>)/application-passwords

Retrieve a Application Password

Definition & Example Request

GET /wp/v2/users/<user_id>)/application-passwords/introspect

Query this endpoint to retrieve a specific application password record.

$ curl https://example.com/wp-json/wp/v2/users/<user_id>)/application-passwords/introspect

Arguments

context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit

Retrieve a Application Password

Definition & Example Request

GET /wp/v2/users/<user_id>)/application-passwords/<uuid>

Query this endpoint to retrieve a specific application password record.

$ curl https://example.com/wp-json/wp/v2/users/<user_id>)/application-passwords/<uuid>

Arguments

context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit

Update a Application Password

Arguments

<a href="#schema-app_id">app_id</a> A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.
<a href="#schema-name">name</a> The name of the application password.

Definition

POST /wp/v2/users/<user_id>)/application-passwords/<uuid>

Example Request

Delete a Application Password

There are no arguments for this endpoint.

Definition

DELETE /wp/v2/users/<user_id>)/application-passwords/<uuid>

Example Request

$ curl -X DELETE https://example.com/wp-json/wp/v2/users/<user_id>)/application-passwords/<uuid>