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

No response body

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

No response body

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

No request body

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.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?