These routes allow you to retrieve/create/update/delete an attachment (media).
Possible routes (endpoints are described below):
/wp/v2/media // works with all attachments
/wp/v2/media/{ID} // works with the specified attachment instead of {ID}
/wp/v2/media/{ID}/post-process
/wp/v2/media/{ID}/edit
Controller class:
Resource Schema
The schema shows all fields that exist for the object record: the fields of the object that the request will return.
Parameter
Context
Description
date String/null
view, edit, embed
The publication date of the object, according to the site's time zone.
date_gmt String/null
view, edit
The publication time of the object, in GMT.
guid Object readonly
view, edit
A globally unique identifier for the object.
id Number readonly
view, edit, embed
A unique identifier for the object.
link String readonly
view, edit, embed
The URL of the object.
modified String readonly
view, edit
The date of the last modification of the object, according to the site's time zone.
modified_gmt String readonly
view, edit
The date of the last modification of the object, in GMT.
slug String
view, edit, embed
An alphanumeric identifier for the object unique to its type.
status String
view, edit
A named status for the object.
type String readonly
view, edit, embed
The type of record for the object.
permalink_template String readonly
edit
The permalink template for the object.
generated_slug String readonly
edit
A slug automatically created from the object's title.
title Object
view, edit, embed
The title for the object.
author Number
view, edit, embed
The ID of the object's author.
comment_status String
view, edit
Whether comments are open for the object.
ping_status String
view, edit
Whether the object accepts notifications.
meta Object
view, edit
Meta fields.
template String
view, edit
The theme file used to display the object.
alt_text String
view, edit, embed
Alternative text to display when the attachment is not shown.
caption Object
view, edit, embed
The caption of the attachment.
description Object
view, edit
The description of the attachment.
media_type String readonly
view, edit, embed
The type of the attachment.
mime_type String readonly
view, edit, embed
The MIME type of the attachment.
media_details Object readonly
view, edit, embed
Details about the media file, specific to its type.
post Number
view, edit
The ID for associated records for the attachment.
source_url String readonly
view, edit, embed
The URL of the original attachment file.
missing_image_sizes Array readonly
edit
A list of missing image sizes for the attachment.
An OPTIONS request to the route will return a complete description of this route: endpoints, their parameters, schema.
$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/media
GitHub
{
"namespace": "wp/v2",
"methods": [
"GET",
"POST"
],
"endpoints": [
{
"methods": [
"GET"
],
"args": {
"context": {
"required": false,
"default": "view",
"enum": [
"view",
"embed",
"edit"
],
"description": "Рамки в которых сделан запрос, определяют поля в ответе.",
"type": "string"
},
"page": {
"required": false,
"default": 1,
"description": "Текущая страница коллекции.",
"type": "integer"
},
"per_page": {
"required": false,
"default": 10,
"description": "Максимальное число объектов возвращаемое в выборке.",
"type": "integer"
},
"search": {
"required": false,
"description": "Ограничить результаты до совпадающих со строкой.",
"type": "string"
},
"after": {
"required": false,
"description": "Ограничить ответ записями опубликованными после заданной ISO8601 совместимой даты. ",
"type": "string"
},
"author": {
"required": false,
"default": [],
"description": "Ограничить выборку записями определенных авторов.",
"type": "array",
"items": {
"type": "integer"
}
},
"author_exclude": {
"required": false,
"default": [],
"description": "Убедиться что выборка исключает записи назначенные определенным авторам.",
"type": "array",
"items": {
"type": "integer"
}
},
"before": {
"required": false,
"description": "Ограничить ответ записями опубликованными до заданной ISO8601 совместимой даты.",
"type": "string"
},
"exclude": {
"required": false,
"default": [],
"description": "Убедиться что выборка исключает определенные ID.",
"type": "array",
"items": {
"type": "integer"
}
},
"include": {
"required": false,
"default": [],
"description": "Ограничить выборку до определенных ID.",
"type": "array",
"items": {
"type": "integer"
}
},
"offset": {
"required": false,
"description": "Сдвиг выборки на определенное число объектов.",
"type": "integer"
},
"order": {
"required": false,
"default": "desc",
"enum": [
"asc",
"desc"
],
"description": "Упорядочить сортировку атрибута по возрастанию или убыванию.",
"type": "string"
},
"orderby": {
"required": false,
"default": "date",
"enum": [
"author",
"date",
"id",
"include",
"modified",
"parent",
"relevance",
"slug",
"include_slugs",
"title"
],
"description": "Сортировать коллекцию по атрибуту объекта.",
"type": "string"
},
"parent": {
"required": false,
"default": [],
"description": "Ограничить выборку до определенных ID родителей.",
"type": "array",
"items": {
"type": "integer"
}
},
"parent_exclude": {
"required": false,
"default": [],
"description": "Ограничить выборку до объектов за исключением имеющих определенный ID родителя.",
"type": "array",
"items": {
"type": "integer"
}
},
"slug": {
"required": false,
"description": "Ограничить выборку до записей с одним или несколькими установленными конкретными ярлыками.",
"type": "array",
"items": {
"type": "string"
}
},
"status": {
"required": false,
"default": "inherit",
"description": "Ограничить выборку до записей с одним или несколькими установленными статусами.",
"type": "array",
"items": {
"enum": [
"inherit",
"private",
"trash"
],
"type": "string"
}
},
"media_type": {
"required": false,
"enum": [
"image",
"video",
"text",
"application",
"audio"
],
"description": "Ограничить выборку до вложений определенного типа медиа.",
"type": "string"
},
"mime_type": {
"required": false,
"description": "Ограничить выборку до вложений определенного MIME типа.",
"type": "string"
}
}
},
{
"methods": [
"POST"
],
"args": {
"date": {
"required": false,
"description": "Дата публикации объекта, по временной зоне сайта.",
"type": "string"
},
"date_gmt": {
"required": false,
"description": "Время публикации объекта, по GMT.",
"type": "string"
},
"slug": {
"required": false,
"description": "Буквенно-цифровой идентификатор для объекта уникальный для его типа.",
"type": "string"
},
"status": {
"required": false,
"enum": [
"publish",
"future",
"draft",
"pending",
"private"
],
"description": "Именованный статус для объекта.",
"type": "string"
},
"title": {
"required": false,
"description": "Название для объекта.",
"type": "object"
},
"author": {
"required": false,
"description": "ID автора объекта.",
"type": "integer"
},
"comment_status": {
"required": false,
"enum": [
"open",
"closed"
],
"description": "Открыты ли комментарии для объекта.",
"type": "string"
},
"ping_status": {
"required": false,
"enum": [
"open",
"closed"
],
"description": "Принимает ли объект уведомления.",
"type": "string"
},
"meta": {
"required": false,
"description": "Мета поля.",
"type": "object"
},
"template": {
"required": false,
"description": "Файл темы используемый для показа объекта.",
"type": "string"
},
"alt_text": {
"required": false,
"description": "Альтернативный текст для показа когда вложение не отображается.",
"type": "string"
},
"caption": {
"required": false,
"description": "Подпись вложения.",
"type": "object"
},
"description": {
"required": false,
"description": "Описание вложения.",
"type": "object"
},
"post": {
"required": false,
"description": "ID для ассоциированых записей для вложения.",
"type": "integer"
}
}
}
],
"schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "attachment",
"type": "object",
"properties": {
"date": {
"description": "Дата публикации объекта, по временной зоне сайта.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit",
"embed"
]
},
"date_gmt": {
"description": "Время публикации объекта, по GMT.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
]
},
"guid": {
"description": "Глобальный уникальный идентификатор для объекта.",
"type": "object",
"context": [
"view",
"edit"
],
"readonly": true,
"properties": {
"raw": {
"description": "GUID для объекта, как он существует в базе данных.",
"type": "string",
"context": [
"edit"
],
"readonly": true
},
"rendered": {
"description": "GUID для объекта, преобразованный для показа.",
"type": "string",
"context": [
"view",
"edit"
],
"readonly": true
}
}
},
"id": {
"description": "Уникальный идентификатор для объекта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"link": {
"description": "URL объекта.",
"type": "string",
"format": "uri",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"modified": {
"description": "Дата последнего изменения объекта, по временной зоне сайта.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
],
"readonly": true
},
"modified_gmt": {
"description": "Дата последнего изменения объекта, в GMT.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
],
"readonly": true
},
"slug": {
"description": "Буквенно-цифровой идентификатор для объекта уникальный для его типа.",
"type": "string",
"context": [
"view",
"edit",
"embed"
]
},
"status": {
"description": "Именованный статус для объекта.",
"type": "string",
"enum": [
"publish",
"future",
"draft",
"pending",
"private"
],
"context": [
"view",
"edit"
]
},
"type": {
"description": "Тип записи для объекта.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"title": {
"description": "Название для объекта.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"properties": {
"raw": {
"description": "Название объекта как оно существует в базе данных.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML название объекта, преобразованное для показа.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"author": {
"description": "ID автора объекта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
]
},
"comment_status": {
"description": "Открыты ли комментарии для объекта.",
"type": "string",
"enum": [
"open",
"closed"
],
"context": [
"view",
"edit"
]
},
"ping_status": {
"description": "Принимает ли объект уведомления.",
"type": "string",
"enum": [
"open",
"closed"
],
"context": [
"view",
"edit"
]
},
"meta": {
"description": "Мета поля.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": []
},
"template": {
"description": "Файл темы используемый для показа объекта.",
"type": "string",
"context": [
"view",
"edit"
]
},
"alt_text": {
"description": "Альтернативный текст для показа когда вложение не отображается.",
"type": "string",
"context": [
"view",
"edit",
"embed"
]
},
"caption": {
"description": "Подпись вложения.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"properties": {
"raw": {
"description": "Подпись для вложения, как она существует в базе данных.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML подпись для вложения, преобразованная для показа.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"description": {
"description": "Описание вложения.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": {
"raw": {
"description": "Описание для объекта как оно существует в базе данных.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML описание для объекта преобразованное для показа.",
"type": "string",
"context": [
"view",
"edit"
],
"readonly": true
}
}
},
"media_type": {
"description": "Тип вложения.",
"type": "string",
"enum": [
"image",
"file"
],
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"mime_type": {
"description": "MIME тип вложения.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"media_details": {
"description": "Подробности о медиа файле, специфичные его типу.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"post": {
"description": "ID для ассоциированых записей для вложения.",
"type": "integer",
"context": [
"view",
"edit"
]
},
"source_url": {
"description": "URL оригинала файла вложения.",
"type": "string",
"format": "uri",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
},
"links": [
{
"rel": "https://api.w.org/action-assign-author",
"title": "Текущий пользователь может сменить автора для этой записи.",
"href": "http://wp-test.ru/wp-json/wp/v2/media/{id}",
"targetSchema": {
"type": "object",
"properties": {
"author": {
"type": "integer"
}
}
}
}
]
},
"_links": {
"self": "http://wp-test.ru/wp-json/wp/v2/media"
}
}
List of all attachments
The algorithm is similar to the function get_posts() , where specific properties are added for each attachment object.
Request type
Access: public
GET /wp/v2/media
Request parameters
context
The context in which the request is made; determines the fields present in the response. Can be view , embed , edit .
Default: view
page
The current page of the collection.
Default: 1
per_page
The maximum number of attachments in the resulting set.
Default: 10
search
Limit on the number of returned records when searching.
after
Limit the response to attachments published after the specified date, corresponding to ISO8601.
before
Limit the response to attachments published before the specified date, corresponding to ISO8601.
exclude
Excludes attachments from the set by their IDs.
include
Includes attachments in the set by their IDs. Only those attachments whose IDs are specified will be present in the set.
offset
Offset (indentation) the result set by the specified number.
Default: 1
order
Sorting of attachments in the selection. Can be asc or desc .
Default: desc
orderby
Sorting records in the selection by attributes. Can be author , date , id , include , modified , parent , relevance , slug , title .
Default: date
parent
Limit the selection to certain parent IDs.
parent_exclude
Limit the selection to objects excluding those with a certain parent ID.
slug
Limit the selection by a specified single slug of the attachment or multiple slugs.
status
Limit the selection by a single status or multiple statuses.
Default: inherit
media_type
Limit the selection to attachments of a specific media type. Can be: image , video , audio , application
mime_type
Limit the selection to attachments of a specific MIME type.
Example request
$ curl http://demo.wp-api.org/wp-json/wp/v2/media
An array of objects will be returned, where each attachment object is similar to what is described in the "Get Attachment" section:
[
{
... attachment data <id> ...
},
{
... attachment data <id> ...
},
{
... attachment data <id> ...
}
]
Creating an attachment
Creates a media file. The algorithm is similar to the function wp_insert_attachment() .
Request type
Access: authorization required
POST /wp/v2/media
Request parameters
date(string)
The publication date of the object, according to the site's time zone.
date_gmt(string)
The publication time of the object, in GMT.
slug(string)
An alphanumeric identifier for the object unique to its type.
status(string)
A named status for the object. Possible values: publish , future , draft , pending , private .
title(object)
The title for the object.
author(number)
The ID of the object's author.
comment_status(string)
Whether comments are open for the object. Possible values: open , closed .
ping_status(string)
Whether the object accepts notifications. Possible values: open , closed .
meta(object)
Meta fields.
template(string)
The theme file used to display the object.
alt_text(string)
Alternative text to display when the attachment is not shown.
caption(object)
The caption of the attachment.
description(object)
The description of the attachment.
post(number)
The ID for associated records for the attachment.
Example request
$ curl -X POST http://demo.wp-api.org/wp-json/wp/v2/media
An OPTIONS request to the route will return a complete description of this route: endpoints, their parameters, schema.
$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/media/{id}
GitHub
{
"namespace": "wp/v2",
"methods": [
"GET",
"POST",
"PUT",
"PATCH",
"DELETE"
],
"endpoints": [
{
"methods": [
"GET"
],
"args": {
"id": {
"required": false,
"description": "Уникальный идентификатор для объекта.",
"type": "integer"
},
"context": {
"required": false,
"default": "view",
"enum": [
"view",
"embed",
"edit"
],
"description": "Рамки в которых сделан запрос, определяют поля в ответе.",
"type": "string"
}
}
},
{
"methods": [
"POST",
"PUT",
"PATCH"
],
"args": {
"id": {
"required": false,
"description": "Уникальный идентификатор для объекта.",
"type": "integer"
},
"date": {
"required": false,
"description": "Дата публикации объекта, по временной зоне сайта.",
"type": "string"
},
"date_gmt": {
"required": false,
"description": "Время публикации объекта, по GMT.",
"type": "string"
},
"slug": {
"required": false,
"description": "Буквенно-цифровой идентификатор для объекта уникальный для его типа.",
"type": "string"
},
"status": {
"required": false,
"enum": [
"publish",
"future",
"draft",
"pending",
"private"
],
"description": "Именованный статус для объекта.",
"type": "string"
},
"title": {
"required": false,
"description": "Название для объекта.",
"type": "object"
},
"author": {
"required": false,
"description": "ID автора объекта.",
"type": "integer"
},
"comment_status": {
"required": false,
"enum": [
"open",
"closed"
],
"description": "Открыты ли комментарии для объекта.",
"type": "string"
},
"ping_status": {
"required": false,
"enum": [
"open",
"closed"
],
"description": "Принимает ли объект уведомления.",
"type": "string"
},
"meta": {
"required": false,
"description": "Мета поля.",
"type": "object"
},
"template": {
"required": false,
"description": "Файл темы используемый для показа объекта.",
"type": "string"
},
"alt_text": {
"required": false,
"description": "Альтернативный текст для показа когда вложение не отображается.",
"type": "string"
},
"caption": {
"required": false,
"description": "Подпись вложения.",
"type": "object"
},
"description": {
"required": false,
"description": "Описание вложения.",
"type": "object"
},
"post": {
"required": false,
"description": "ID для ассоциированых записей для вложения.",
"type": "integer"
}
}
},
{
"methods": [
"DELETE"
],
"args": {
"id": {
"required": false,
"description": "Уникальный идентификатор для объекта.",
"type": "integer"
},
"force": {
"required": false,
"default": false,
"description": "Игнорировать ли перемещение в корзину и принудительно удалять.",
"type": "boolean"
}
}
}
],
"schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "attachment",
"type": "object",
"properties": {
"date": {
"description": "Дата публикации объекта, по временной зоне сайта.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit",
"embed"
]
},
"date_gmt": {
"description": "Время публикации объекта, по GMT.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
]
},
"guid": {
"description": "Глобальный уникальный идентификатор для объекта.",
"type": "object",
"context": [
"view",
"edit"
],
"readonly": true,
"properties": {
"raw": {
"description": "GUID для объекта, как он существует в базе данных.",
"type": "string",
"context": [
"edit"
],
"readonly": true
},
"rendered": {
"description": "GUID для объекта, преобразованный для показа.",
"type": "string",
"context": [
"view",
"edit"
],
"readonly": true
}
}
},
"id": {
"description": "Уникальный идентификатор для объекта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"link": {
"description": "URL объекта.",
"type": "string",
"format": "uri",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"modified": {
"description": "Дата последнего изменения объекта, по временной зоне сайта.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
],
"readonly": true
},
"modified_gmt": {
"description": "Дата последнего изменения объекта, в GMT.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
],
"readonly": true
},
"slug": {
"description": "Буквенно-цифровой идентификатор для объекта уникальный для его типа.",
"type": "string",
"context": [
"view",
"edit",
"embed"
]
},
"status": {
"description": "Именованный статус для объекта.",
"type": "string",
"enum": [
"publish",
"future",
"draft",
"pending",
"private"
],
"context": [
"view",
"edit"
]
},
"type": {
"description": "Тип записи для объекта.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"title": {
"description": "Название для объекта.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"properties": {
"raw": {
"description": "Название объекта как оно существует в базе данных.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML название объекта, преобразованное для показа.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"author": {
"description": "ID автора объекта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
]
},
"comment_status": {
"description": "Открыты ли комментарии для объекта.",
"type": "string",
"enum": [
"open",
"closed"
],
"context": [
"view",
"edit"
]
},
"ping_status": {
"description": "Принимает ли объект уведомления.",
"type": "string",
"enum": [
"open",
"closed"
],
"context": [
"view",
"edit"
]
},
"meta": {
"description": "Мета поля.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": []
},
"template": {
"description": "Файл темы используемый для показа объекта.",
"type": "string",
"context": [
"view",
"edit"
]
},
"alt_text": {
"description": "Альтернативный текст для показа когда вложение не отображается.",
"type": "string",
"context": [
"view",
"edit",
"embed"
]
},
"caption": {
"description": "Подпись вложения.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"properties": {
"raw": {
"description": "Подпись для вложения, как она существует в базе данных.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML подпись для вложения, преобразованная для показа.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"description": {
"description": "Описание вложения.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": {
"raw": {
"description": "Описание для объекта как оно существует в базе данных.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML описание для объекта преобразованное для показа.",
"type": "string",
"context": [
"view",
"edit"
],
"readonly": true
}
}
},
"media_type": {
"description": "Тип вложения.",
"type": "string",
"enum": [
"image",
"file"
],
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"mime_type": {
"description": "MIME тип вложения.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"media_details": {
"description": "Подробности о медиа файле, специфичные его типу.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"post": {
"description": "ID для ассоциированых записей для вложения.",
"type": "integer",
"context": [
"view",
"edit"
]
},
"source_url": {
"description": "URL оригинала файла вложения.",
"type": "string",
"format": "uri",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
},
"links": [
{
"rel": "https://api.w.org/action-assign-author",
"title": "Текущий пользователь может сменить автора для этой записи.",
"href": "http://wp-test.ru/wp-json/wp/v2/media/{id}",
"targetSchema": {
"type": "object",
"properties": {
"author": {
"type": "integer"
}
}
}
}
]
}
}
Retrieving an attachment
Request type
Access: public
GET /wp/v2/media/{id}
Request parameters
id (required)
A unique identifier for the attachment. This same parameter is specified in the route.
context
The context in which the request is made; determines the fields present in the response. Can be view , embed , edit .
Default: view
Example request
Request the attachment with ID = 411 :
$ curl http://demo.wp-api.org/wp-json/wp/v2/media/411
Result:
{
"id": 411,
"date": "2018-06-10T17:41:48",
"date_gmt": "2018-06-10T14:41:48",
"guid": {
"rendered": "http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish.jpg"
},
"modified": "2018-06-10T17:41:48",
"modified_gmt": "2018-06-10T14:41:48",
"slug": "cropped-jellyfish-jpg",
"status": "inherit",
"type": "attachment",
"link": "http://wp-test.ru/cropped-jellyfish-jpg/",
"title": {
"rendered": "cropped-Jellyfish.jpg"
},
"author": 1,
"comment_status": "open",
"ping_status": "closed",
"template": "",
"meta": [],
"description": {
"rendered": "<p class=\"attachment\"><a href='http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish.jpg'><img width=\"250\" height=\"250\" src=\"http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish.jpg\" class=\"attachment-medium size-medium\" alt=\"\" srcset=\"http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish.jpg 250w, http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish-100x100.jpg 100w, http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish-150x150.jpg 150w\" sizes=\"100vw\" /></a></p>\n<p>http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish.jpg</p>\n"
},
"caption": {
"rendered": "<p>http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish.jpg</p>\n"
},
"alt_text": "",
"media_type": "image",
"mime_type": "image/jpeg",
"media_details": {
"width": 250,
"height": 250,
"file": "2018/03/cropped-Jellyfish.jpg",
"sizes": {
"woocommerce_gallery_thumbnail": {
"file": "cropped-Jellyfish-100x100.jpg",
"width": 100,
"height": 100,
"mime_type": "image/jpeg",
"source_url": "http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish-100x100.jpg"
},
"thumbnail": {
"file": "cropped-Jellyfish-150x150.jpg",
"width": 150,
"height": 150,
"mime_type": "image/jpeg",
"source_url": "http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish-150x150.jpg"
},
"twentyseventeen-thumbnail-avatar": {
"file": "cropped-Jellyfish-100x100.jpg",
"width": 100,
"height": 100,
"mime_type": "image/jpeg",
"source_url": "http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish-100x100.jpg"
},
"full": {
"file": "cropped-Jellyfish.jpg",
"width": 250,
"height": 250,
"mime_type": "image/jpeg",
"source_url": "http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish.jpg"
}
},
"image_meta": {
"aperture": "0",
"credit": "",
"camera": "",
"caption": "",
"created_timestamp": "0",
"copyright": "",
"focal_length": "0",
"iso": "0",
"shutter_speed": "0",
"title": "",
"orientation": "0",
"keywords": []
}
},
"post": null,
"source_url": "http://wp-test.ru/wp-content/uploads/2018/03/cropped-Jellyfish.jpg",
"_links": {
"self": [
{
"attributes": [],
"href": "http://wp-test.ru/wp-json/wp/v2/media/411"
}
],
"collection": [
{
"attributes": [],
"href": "http://wp-test.ru/wp-json/wp/v2/media"
}
],
"about": [
{
"attributes": [],
"href": "http://wp-test.ru/wp-json/wp/v2/types/attachment"
}
],
"author": [
{
"attributes": {
"embeddable": true
},
"href": "http://wp-test.ru/wp-json/wp/v2/users/1"
}
],
"replies": [
{
"attributes": {
"embeddable": true
},
"href": "http://wp-test.ru/wp-json/wp/v2/comments?post=411"
}
]
}
}
Updating an attachment
The algorithm is similar to the function wp_update_post()
Request type
Access: authorization required
POST|PUT|PATCH /wp/v2/media/{id}
Request parameters
See parameters when creating an attachment .
Example request
$ curl -X POST http://demo.wp-api.org/wp-json/wp/v2/media/25?caption=New caption
Deleting an attachment
The algorithm is similar to the function wp_delete_attachment() .
Request type
Access: authorization required
DELETE /wp/v2/media/{id}
Request parameters
force(true/false)
Whether to ignore moving to the trash and forcibly delete.
Default: false
Example request
Delete attachment 25:
$ curl -X DELETE http://demo.wp-api.org/wp-json/wp/v2/media/25
/wp/v2/media/{ID}/post-process
Post-processing of the attachment.
Request type
Access: authorization required.
POST /wp/v2/media/{ID}/post-process
Request parameters
$action(string) (required)
What processing needs to be done. Possible values: create-image-subsizes
.
Editing.
Request type
Access: authorization required.
POST /wp/v2/media/{ID}/edit
Request parameters
$src(string) (required)
URL of the edited image file.
$rotation(number)
The amount (in degrees, from 0 to 360) to rotate the image clockwise.
$x(number)
In percentage of the image, the X position to start cropping. Possible values: 0 - 100.
$y(number)
In percentage of the image, the Y position to start cropping. Possible values: 0 - 100.
$width(number)
In percentage of the image, the width for cropping the image.
$height(number)
In percentage of the image, the height for cropping the image.