-
Notifications
You must be signed in to change notification settings - Fork 21
Docs: REST API Reference #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aa4ce0a
Docs: REST API Reference
gziolo a2f1306
Update docs/5.rest-api.md
gziolo 12a43c5
Improve the examples included in the document
gziolo 5276094
Document user access requirements for REST API
gziolo c0ffb6c
Merge branch 'trunk' into add/rest-api-docs
gziolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
# 5. REST API Reference | ||
|
||
The WordPress Abilities API provides REST endpoints that allow external systems to discover and execute abilities via HTTP requests. | ||
|
||
## Schema | ||
|
||
The Abilities API endpoints are available under the `/wp/v2/abilities` namespace. | ||
|
||
### Ability Object | ||
|
||
Abilities are represented in JSON with the following structure: | ||
|
||
```json | ||
{ | ||
"name": "my-plugin/get-site-info", | ||
"label": "Get Site Information", | ||
"description": "Retrieves basic information about the WordPress site.", | ||
"output_schema": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Site name" | ||
}, | ||
"url": { | ||
"type": "string", | ||
"format": "uri", | ||
"description": "Site URL" | ||
} | ||
} | ||
}, | ||
"meta": {} | ||
} | ||
``` | ||
|
||
## List Abilities | ||
|
||
### Definition | ||
|
||
`GET /wp/v2/abilities` | ||
|
||
### Arguments | ||
|
||
- `page` _(integer)_: Current page of the collection. Default: `1`. | ||
- `per_page` _(integer)_: Maximum number of items to return per page. Default: `50`, Maximum: `100`. | ||
|
||
### Example Request | ||
|
||
```bash | ||
curl https://example.com/wp-json/wp/v2/abilities | ||
``` | ||
|
||
### Example Response | ||
|
||
```json | ||
[ | ||
{ | ||
"name": "my-plugin/get-site-info", | ||
"label": "Get Site Information", | ||
"description": "Retrieves basic information about the WordPress site.", | ||
"output_schema": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Site name" | ||
}, | ||
"url": { | ||
"type": "string", | ||
"format": "uri", | ||
"description": "Site URL" | ||
} | ||
} | ||
}, | ||
"meta": {} | ||
} | ||
] | ||
``` | ||
|
||
## Retrieve an Ability | ||
|
||
### Definition | ||
|
||
`GET /wp/v2/abilities/(?P<namespace>[a-z0-9-]+)/(?P<ability>[a-z0-9-]+)` | ||
|
||
### Arguments | ||
|
||
- `namespace` _(string)_: The namespace part of the ability name. | ||
- `ability` _(string)_: The ability name part. | ||
|
||
### Example Request | ||
|
||
```bash | ||
curl https://example.com/wp-json/wp/v2/abilities/my-plugin/get-site-info | ||
``` | ||
|
||
### Example Response | ||
|
||
```json | ||
{ | ||
"name": "my-plugin/get-site-info", | ||
"label": "Get Site Information", | ||
"description": "Retrieves basic information about the WordPress site.", | ||
"output_schema": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Site name" | ||
}, | ||
"url": { | ||
"type": "string", | ||
"format": "uri", | ||
"description": "Site URL" | ||
} | ||
} | ||
}, | ||
"meta": {} | ||
} | ||
``` | ||
|
||
## Execute an Ability | ||
|
||
### Definition | ||
|
||
`POST /wp/v2/abilities/(?P<namespace>[a-z0-9-]+)/(?P<ability>[a-z0-9-]+)/run` | ||
|
||
### Arguments | ||
|
||
- `namespace` _(string)_: The namespace part of the ability name. | ||
- `ability` _(string)_: The ability name part. | ||
- `input` _(integer|number|boolean|string|array|object|null)_: Optional input data for the ability as defined by its input schema. | ||
|
||
### Example Request (No Input) | ||
|
||
```bash | ||
curl -X POST https://example.com/wp-json/wp/v2/abilities/my-plugin/get-site-info/run | ||
``` | ||
|
||
### Example Request (With Input) | ||
|
||
```bash | ||
curl -X POST \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"input":{"option_name":"blogname","option_value":"New Site Name"}}' \ | ||
https://example.com/wp-json/wp/v2/abilities/my-plugin/update-option/run | ||
``` | ||
|
||
### Example Response (Success) | ||
|
||
```json | ||
{ | ||
"name": "My WordPress Site", | ||
"url": "https://example.com" | ||
} | ||
``` | ||
|
||
### Example Response (Error) | ||
|
||
```json | ||
{ | ||
"code": "ability_invalid_permissions", | ||
"message": "Ability \"my-plugin/update-option\" does not have necessary permission.", | ||
"data": { | ||
"status": 403 | ||
} | ||
} | ||
``` | ||
|
||
## Authentication | ||
|
||
The Abilities API supports all WordPress REST API authentication methods: | ||
|
||
- Cookie authentication (same-origin requests) | ||
- Application passwords (recommended for external access) | ||
- Custom authentication plugins | ||
|
||
### Using Application Passwords | ||
|
||
```bash | ||
curl -u 'USERNAME:APPLICATION_PASSWORD' \ | ||
https://example.com/wp-json/wp/v2/abilities | ||
``` | ||
|
||
## Error Responses | ||
|
||
The API returns standard WordPress REST API error responses with these common codes: | ||
|
||
- `ability_missing_input_schema` – the ability requires input but none was provided. | ||
- `ability_invalid_input` - input validation failed according to the ability's schema. | ||
- `ability_invalid_permissions` - current user lacks permission to execute the ability. | ||
- `ability_invalid_output` - output validation failed according to the ability's schema. | ||
- `ability_invalid_execute_callback` - the ability's execute callback is not callable. | ||
- `rest_ability_not_found` - the requested ability is not registered. | ||
- `rest_ability_invalid_method` - the requested HTTP method is not allowed for executing the selected ability. | ||
- `rest_ability_cannot_execute` - the ability cannot be executed due to insufficient permissions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.