CRUD media operations
Get a collection of media items
To get all media items, you must execute a GET request to the following endpoint:
{baseurl}/api/default/{media}
Where media is the media item’s entity set, for example – images or videos.
Sample request
GET http://localhost:1337/api/default/images
Sample response
NOTE: This endpoint returns all media items. In the above case, it returns all images in the default data provider, for the default site, in default culture, because none of these parameters are specified. Regardless of whether the media items are in one library, in this case, in the response all the media items are flattened.
In the JSON of the response above, you can see that there are two libraries on the root level – Animals and Cars. The Animals library has two images at its root level and another library called Cats, which has two more images inside; the Cars library has only one image at its root level. All of these five are present in this response. The libraries are not present in this response. However, each item has a reference to its library and folder – the ParentId of the library and the FolderId of the folder.
Get a media item
To get a single media item, you must execute a GET request to the following endpoint:
{baseurl}/api/default/{media}({id})
Where:
- media is the media item’s entity set, for example – images or videos
-
id is the ID of the media item that you want to get, for example – 04995fa1-0cb1-4247-ae10-0bade5d75d0e
Sample request
GET http://localhost:1337/api/default/images(04995fa1-0cb1-4247-ae10-0bade5d75d0e)
Sample response
Upload a media item
To upload a media item, you must execute a POST request to the following endpoint:
{baseurl}/api/default/{media}
Where media is the media item’s entity set, for example – images or videos.
Sample request
POST http://localhost:1337/api/default/images
The content type is the respective MIME type of the currently uploaded image.
The binary data of the currently uploaded file in base64 string.
Sample response
Partially update a media item
Updating a media item can be done in two ways – with a PATCH or with a PUT request. The difference between the two verbs is that PATCH allows for a partial update, whereas PUT requires all fields to be present in the request’s body.
To partially update a media item, you must execute a PATCH request to the following endpoint:
{baseurl}/api/default/{media}({id})
Where:
- media is the media item’s entity set, for example – images or videos
-
id is the ID of the media item that you want to update, for example – 04995fa1-0cb1-4247-ae10-0bade5d75d0e
For example, the following request updates only the AlternativeText property of the Image media type:
Sample request
PATCH http://localhost:1337/api/default/images(04995fa1-0cb1-4247-ae10-0bade5d75d0e)
Sample response
If you make the same request as above, but you change the verb to PUT, the server responds with the following error:
NOTE: This error is specific to the Images media type.
Fully update a media item
Updating a media item can be done in two ways – with a PATCH or with a PUT request. The difference between the two verbs is that PATCH allows for a partial update, whereas PUT requires all fields to be present in the request’s body.
To fully update a media item, you must execute a PUT request to the following endpoint:
{baseurl}/api/default/{media}({id})
Where:
- media is the media item’s entity set, for example – images or videos
-
id is the ID of the media item that you want to update, for example – 04995fa1-0cb1-4247-ae10-0bade5d75d0e
Sample request
PUT http://localhost:1337/api/default/images(04995fa1-0cb1-4247-ae10-0bade5d75d0e)
Sample response
Delete a media item
To delete a media item, you must execute a DELETE request to the following endpoint:
{baseurl}/api/default/{media}({id})
Where:
- media is the media item’s entity set, for example – images or videos
-
id is the ID of the media item that you want to update, for example – 04995fa1-0cb1-4247-ae10-0bade5d75d0e
Sample request
DELETE http://localhost:1337/api/default/images(04995fa1-0cb1-4247-ae10-0bade5d75d0e)
Sample response
NOTE: If you have enabled the Recycle bin module of Sitefinity CMS the media item will be moved to the Recycle bin. If the module is disabled - the media item will be deleted permanently.