# Libraries operations

## Get a collection of libraries

To get all libraries, you must execute a `GET` request to the following endpoint:

`{baseurl}/api/default/{media}`

Where `media` is the libraries’ entity set, for example – `albums` or `videolibraries`.

**Sample request**

> success **GET** `http://mysite.com/api/default/videolibraries`

**Sample response**

<SfDetails summary="Status code: 200 OK">

```JSON
{
    "@odata.context": "http://localhost:1337/api/default/$metadata#videolibraries(Id,LastModified,PublicationDate,Title,Description,DateCreated,IncludeInSitemap,UrlName,MaxSize,MaxItemSize,BlobStorageProvider,OutputCacheProfile,ClientCacheProfile,CoverId,ChildrenCount)",
    "value": [
        {
            "Id": "d4e22033-7bcd-4ce5-9c70-41f9b83d7d66",
            "LastModified": "2021-04-21T08:29:14Z",
            "PublicationDate": "2021-04-21T08:29:14Z",
            "Title": "Sample videos",
            "Description": "",
            "DateCreated": "2021-04-21T08:29:14Z",
            "IncludeInSitemap": true,
            "UrlName": "sample-videos",
            "MaxSize": 0,
            "MaxItemSize": 0,
            "BlobStorageProvider": "Database",
            "OutputCacheProfile": null,
            "ClientCacheProfile": null,
            "CoverId": null,
            "ChildrenCount": 1
        },
        {
            "Id": "2f94846a-8133-4a85-94bf-b11b1bf103e7",
            "LastModified": "2021-04-21T08:32:26Z",
            "PublicationDate": "2021-04-21T08:32:26Z",
            "Title": "Colors",
            "Description": "",
            "DateCreated": "2021-04-21T08:32:26Z",
            "IncludeInSitemap": true,
            "UrlName": "colors",
            "MaxSize": 0,
            "MaxItemSize": 0,
            "BlobStorageProvider": "FileSystem",
            "OutputCacheProfile": null,
            "ClientCacheProfile": null,
            "CoverId": null,
            "ChildrenCount": 0
        }
    ]
}
```

This request queries all available libraries and their child folders recursively.

> info **NOTE**: If in the request you do not specify a site, a culture, or a data provider, the libraries that are queried are taken from the default data provider and default culture of the default site in the system.

</SfDetails>

## Get a specific library

To get a single library, you must execute a `GET` request to the following endpoint:

`{baseurl}/api/default/{media}({id})`

Where:

* `media` is the library’s entity set, for example – `albums` or `videolibraries`
* `id` is the ID of the library that you want to get, for example – `d4e22033-7bcd-4ce5-9c70-41f9b83d7d66`

**Sample request**

> success **GET** `http://mysite.com/api/default/videolibraries(d4e22033-7bcd-4ce5-9c70-41f9b83d7d66)`

**Sample response**

<SfDetails summary="Status code: 200 OK">

```JSON
{
    "@odata.context": "http://localhost:1337/api/default/$metadata#videolibraries/$entity",
    "Id": "d4e22033-7bcd-4ce5-9c70-41f9b83d7d66",
    "LastModified": "2021-04-21T08:29:14Z",
    "PublicationDate": "2021-04-21T08:29:14Z",
    "Title": "Sample videos",
    "Description": "",
    "DateCreated": "2021-04-21T08:29:14Z",
    "IncludeInSitemap": true,
    "UrlName": "sample-videos",
    "MaxSize": 0,
    "MaxItemSize": 0,
    "BlobStorageProvider": "Database",
    "OutputCacheProfile": null,
    "ClientCacheProfile": null,
    "CoverId": null,
    "ThumbnailProfiles": [
        "vthumbnail"
    ],
    "ParentId": null,
    "Provider": "OpenAccessDataProvider",
    "ChildrenCount": 1
}
```

</SfDetails>

## Create a library

To create a library, you must execute a `POST` request to the following endpoint:

`{baseurl}/api/default/{media}`

Where `media` is the library’s entity set, for example – `albums` or `videolibraries`.

**Sample request**

> success **POST** `http://mysite.com/api/default/videolibraries`

<SfDetails summary="Request body">

```JSON
{
    "Title": "New library",
    "BlobStorageProvider": "Database",
    "UrlName": "new-library"
}
```

</SfDetails>

**Sample response**

<SfDetails summary="Status code: 201 Created">

```JSON
{
    "@odata.context": "http://localhost:1337/api/default/$metadata#videolibraries/$entity",
    "Id": "477045b1-56f3-4abf-8799-33d42813636f",
    "LastModified": "2021-04-26T16:22:06Z",
    "PublicationDate": "2021-04-26T16:22:06Z",
    "Title": "New library",
    "Description": "",
    "DateCreated": "2021-04-26T16:22:06Z",
    "IncludeInSitemap": true,
    "UrlName": "new-library",
    "MaxSize": 0,
    "MaxItemSize": 0,
    "BlobStorageProvider": "Database",
    "OutputCacheProfile": null,
    "ClientCacheProfile": null,
    "CoverId": null,
    "ThumbnailProfiles": [
        "vthumbnail"
    ],
    "ParentId": null,
    "Provider": "OpenAccessDataProvider",
    "ChildrenCount": 0
}
```

</SfDetails>

<SfDetails summary="Status code: 400 Bad Request">

If you make the same request as above, but you change the verb to PUT, the server responds with the following error:

```JSON
{
    "error": {
        "code": "BadRequest",
        "message": "Missing properties: Title,Description,IncludeInSitemap,Ordinal,UrlName,Author,Category,Tags,ParentId",
        "target": "Telerik.Sitefinity.Web.Api"
    }
}
```

</SfDetails>

## Partially update a library

Updating a library 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 library, you must execute a `PATCH` request to the following endpoint:

`{baseurl}/api/default/{media}({id})`

Where:

* `media` is the library’s entity set, for example – `albums` or `videolibraries`
* `id` is the ID of the library that you want to update, for example – `d4e22033-7bcd-4ce5-9c70-41f9b83d7d66`

**Sample request**

> success **PATCH** `http://misite.com/api/default/videolibraries(d4e22033-7bcd-4ce5-9c70-41f9b83d7d66)`

<SfDetails summary="Request body">

```JSON
{
    "Title":"Edited library title"
}
```

</SfDetails>

**Sample response**

<SfDetails summary="Status code: 400 Bad Request">

```JSON
{
    "error": {
        "code": "BadRequest",
        "message": "Missing properties: Description,IncludeInSitemap,MaxSize,MaxItemSize,BlobStorageProvider,OutputCacheProfile,ClientCacheProfile,CoverId,ThumbnailProfiles",
        "target": "Telerik.Sitefinity.Web.Api"
    }
}
```

</SfDetails>

## Fully update of a library

Updating a library 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 update a library, you must execute a `PUT` request to the following endpoint:

`{baseurl}/api/default/{media}({id})`

Where:

* `media` is the library’s entity set, for example – `albums` or `videolibraries`
* `id` is the ID of the library that you want to update, for example – `d4e22033-7bcd-4ce5-9c70-41f9b83d7d66`

> info **NOTE**: You can get an error, if one or more properties of the library are not included in the request’s body.

**Sample request**

> success **PUT** `http://mysite.com/api/default/videolibraries(d4e22033-7bcd-4ce5-9c70-41f9b83d7d66)`

<SfDetails summary="Request body">

```JSON
{
    "Title":"Edited library title"
}
```

</SfDetails>

**Sample response**

<SfDetails summary="Status code: 400 Bad Request">

```JSON
{
    "error": {
        "code": "BadRequest",
        "message": "Missing properties: Description,IncludeInSitemap,MaxSize,MaxItemSize,BlobStorageProvider,OutputCacheProfile,ClientCacheProfile,CoverId,ThumbnailProfiles",
        "target": "Telerik.Sitefinity.Web.Api"
    }
}
```

</SfDetails>

**Sample request (all required properties)**

> success  **PUT** `http://mysite.com/api/default/videolibraries(d4e22033-7bcd-4ce5-9c70-41f9b83d7d66)`

<SfDetails summary="Request body">

```JSON
{
    "Title":"Edited library title",
    "Description": "A description of the library.",
    "IncludeInSitemap": "False",
    "MaxSize": 0,
    "MaxItemSize": 0,
    "BlobStorageProvider": "Database",
    "OutputCacheProfile": "",
    "ClientCacheProfile": "",
    "ThumbnailProfiles": [],
    "CoverId": null
}
```

</SfDetails>

**Sample response**

<SfDetails summary="Status code: 204 No Content">

No response body

</SfDetails>

## Delete a library

To delete a library, you must execute a `DELETE` request to the following endpoint:

`{baseurl}/api/default/{media}({id})`

Where:

* `media` is the library’s entity set, for example – `albums` or `videolibraries`
* `id` is the ID of the library that you want to delete, for example – `d4e22033-7bcd-4ce5-9c70-41f9b83d7d66`

**Sample request**

> success **DELETE** `http://mysite.com/api/default/videolibraries(d4e22033-7bcd-4ce5-9c70-41f9b83d7d66)`

**Sample response**

<SfDetails summary="Status code: 204 No Content">

No response body

</SfDetails>
