npm package: @plasma-platform/service-collections
Description: Collections Service api
Author: Anton Nemtsev
Latest version: 3.5.0

![version](https://badgen.net/npm/v/@plasma-platform/service-collections)
![nextVersion](https://badgen.net/npm/v/@plasma-platform/service-collections/next)
![downloads](https://badgen.net/npm/dt/@plasma-platform/service-collections)
![license](https://badgen.net/npm/license/@plasma-platform/service-collections)
![dependency](https://badgen.net/npm/dependents/@plasma-platform/service-collections)  

* * *

[Full documentation](https://templatemonster.gitlab.io/PlasmaPlatform/Frontend/plasma-platform/?path=/story/plasma-platform-sdk--service-collections)  
install:  
`npm i @plasma-platform/service-collections -S`  

# Short documentation

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [CollectionsService](#collectionsservice)
    -   [Parameters](#parameters)
    -   [messages](#messages)
    -   [getCollectionById](#getcollectionbyid)
        -   [Parameters](#parameters-1)
        -   [Examples](#examples)
    -   [getColectionItemsById](#getcolectionitemsbyid)
        -   [Examples](#examples-1)
    -   [getCollectionsOfUser](#getcollectionsofuser)
        -   [Parameters](#parameters-2)
        -   [Examples](#examples-2)
    -   [postCollection](#postcollection)
        -   [Parameters](#parameters-3)
        -   [Examples](#examples-3)
    -   [postItem](#postitem)
        -   [Parameters](#parameters-4)
        -   [Examples](#examples-4)
    -   [deleteItem](#deleteitem)
        -   [Parameters](#parameters-5)
        -   [Examples](#examples-5)
    -   [getCollections](#getcollections)
        -   [Parameters](#parameters-6)
        -   [Examples](#examples-6)
    -   [getMyCollections](#getmycollections)
        -   [Parameters](#parameters-7)
        -   [Examples](#examples-7)
    -   [mergeCollections](#mergecollections)
        -   [Parameters](#parameters-8)
        -   [Examples](#examples-8)

## CollectionsService

-   **See: //api.templatemonster.com/collection/v2/**

collections Micro Service API that you may adopt for your needs

### Parameters

-   `url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** service url
-   `token` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** user access tocken if available (optional, default `null`)

### messages

Object with class service messages

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

### getCollectionById

Get collection information specified by collection_id

#### Parameters

-   `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** collection id

#### Examples

Read collection info


```javascript
(async () => {
  const collections = new CollectionsService('//api.templatemonster.com/collection/v2/');
  const collection = await collections.getCollectionById('hgm1t2ltgyi7dim9nvo0');
})();
```

Returns **Collection** collection object

### getColectionItemsById

Get list of collection items of collection specified by collection_id

#### Examples

Read collection items list


```javascript
(async () => {
  const collections = new CollectionsService('//api.templatemonster.com/collection/v2/');
  const items = await collections.getColectionItemsById('mfsgxst31slvddqz0miv');
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** array of items

### getCollectionsOfUser

Get list of collections of user

#### Parameters

-   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** collection name
-   `page` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** page
-   `perPage` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** collections per page, 0 for all

#### Examples

Get Favorites Collection


```javascript
(async () => {
  const collections = new CollectionsService('//api.templatemonster.com/collection/v2/');
  const items = await collections.getCollectionsOfUser();
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** collections

### postCollection

Add new collection

#### Parameters

-   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** collection name

#### Examples

Create collection


```javascript
(async () => {
  const collections = new CollectionsService('//api.templatemonster.com/collection/v2/');
  const item = await collections.postCollection('Favorites');
})();
```

Returns **Collection** collection object

### postItem

Add new collection item

#### Parameters

-   `collectionId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** collection id
-   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** item name

#### Examples

Favorite item


```javascript
(async () => {
  const collections = new CollectionsService('//api.templatemonster.com/collection/v2/');
  const item = await collections.postItem('mfsgxst31slvddqz0miv', 'template-67020');
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** record in the collection

### deleteItem

Delete Collection Item

#### Parameters

-   `id` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** id of the record in the collection

#### Examples

Remove from collection


```javascript
(async () => {
  const collections = new CollectionsService('//api.templatemonster.com/collection/v2/');
  await collections.deleteItem(2342);
})();
```

### getCollections

Get list of collections

#### Parameters

-   `params` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object of params.
    -   `params.page` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Page number.
    -   `params.ids` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array Collection unique ID.
    -   `params.names` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array Collection Name.
    -   `params.name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Array Collection unique ID.
    -   `params.expand` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Get additional fields. Collection items are visible only if "expand=items" param is in request

#### Examples

```javascript
(async () => {
  const service = new CollectionsService(serviceUrl);
  const collections = await service.getCollections(params);
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** collection list & pagination

### getMyCollections

Get my list of collections

#### Parameters

-   `params` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object of params.
    -   `params.page` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Page number.
    -   `params.ids` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array Collection unique ID.
    -   `params.names` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array Collection Name.
    -   `params.name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Array Collection unique ID.
    -   `params.expand` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Get additional fields. Collection items are visible only if "expand=items" param is in request

#### Examples

```javascript
(async () => {
  const service = new CollectionsService(serviceUrl);
  const collections = await service.getCollections(params);
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** collection list & pagination

### mergeCollections

Collection - Merge Collections

#### Parameters

-   `targetCollectionId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Target collection unique ID.
-   `sourceCollectionId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Source collection unique ID.

#### Examples

```javascript
(async () => {
  const service = new CollectionsService(serviceUrl);
  const collections = await service.mergeCollections(targetCollectionId, sourceCollectionId);
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** collection data