# Confused about collections

**URL:** <https://discourse.getcockpit.com/t/confused-about-collections/138>\
**Category:** Support\
**Created:** [July 6, 2018, 9:31am UTC](https://discourse.getcockpit.com/t/confused-about-collections/138 "2018-07-06T09:31:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jesperlandberg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jesperlandberg/32/60_2.png) [@jesperlandberg](https://discourse.getcockpit.com/u/jesperlandberg)\
**Post date:** [July 6, 2018, 9:31am UTC](https://discourse.getcockpit.com/t/confused-about-collections/138/1 "2018-07-06T09:31:06Z")

</div>

So coming from WordPress, I am having some issues/things I don’t understand here. Collections is supposed to work basically as post types in WP? I create a collection, and then I create entries in it. However, in WP i’m used to that each entry has a permalink to access it as a single post page. What I don’t understand is how I with Cockpit and JS can retrieve the data for a single entry, based on a slug for example. Can anyone explain how I would do the following:

- Page that lists all entries (So far so good).
- Each entry in the lists links to a single entry href="’/’ + entry.slug’"
- How do i retrieve the data for this single entry based on a slug or other param?

---

<div class="post-metadata">

**Author:** ![woutervddn](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/woutervddn/32/50_2.png) [@woutervddn](https://discourse.getcockpit.com/u/woutervddn)\
**Post date:** [July 6, 2018, 6:09pm UTC](https://discourse.getcockpit.com/t/confused-about-collections/138/2 "2018-07-06T18:09:08Z")

</div>

Your assumption about collections being like post types is correct.

Well, this is one of the points where Cockpit fails to be truly restful.

While you can get all entries using: `your.url/api/collections/get/COLLECTIONNAME`

You can only seem to get a single collection entry by

```
fetch('your.url/api/collections/get/COLLECTIONNAME?token=xxtokenxx', {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        filter: { '_id': { $in: [1, 4, 5] } },
        limit: 10,
        skip: 5,
        sort: {_created:-1},
        populate: 1 // resolve linked collection items
    })
})
.then(res=>res.json())
.then(res => console.log(res));

```

Note that filter allows you to filter based on entry ID.

That being said, there should be a restful way as well. I’ll try to see if it isn’t hidden in the API somewhere or if there’s a plugin for it. In any case, it’s not clearly documented.

---

<div class="post-metadata">

**Author:** ![woutervddn](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/woutervddn/32/50_2.png) [@woutervddn](https://discourse.getcockpit.com/u/woutervddn)\
**Post date:** [July 6, 2018, 7:21pm UTC](https://discourse.getcockpit.com/t/confused-about-collections/138/3 "2018-07-06T19:21:09Z")

</div>

So, after searching some of the issues on Github, I found this works as well

[https://your.url/api/collections/get/COLLECTIONNAME/?filter[{FILTERNAME}]={FILTERVALUE}](https://your.url/api/collections/get/COLLECTIONNAME/?filter%5B%7BFILTERNAME%7D%5D=%7BFILTERVALUE%7D)

example:  
[https://example.cpm/api/collections/get/posts/?filter[{\_id}]={b3f50bbcf7fd9004f3530d7}](https://example.cpm/api/collections/get/posts/?filter%5B%7B_id%7D%5D=%7Bb3f50bbcf7fd9004f3530d7%7D)

---

<div class="post-metadata">

**Author:** ![jesperlandberg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jesperlandberg/32/60_2.png) [@jesperlandberg](https://discourse.getcockpit.com/u/jesperlandberg)\
**Post date:** [July 17, 2018, 8:48pm UTC](https://discourse.getcockpit.com/t/confused-about-collections/138/4 "2018-07-17T20:48:17Z")

</div>

Thanks a lot, seems to work well.

---

<div class="post-metadata">

**Author:** ![jb-storms-media](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jb-storms-media](https://discourse.getcockpit.com/u/jb-storms-media)\
**Post date:** [July 18, 2018, 9:41am UTC](https://discourse.getcockpit.com/t/confused-about-collections/138/5 "2018-07-18T09:41:05Z")

</div>

do you have a clou how to use multiple filter fields without the json version?

\*edit

never mind; found out my self: ?filter[FILTER1]=valX&filter[FILTER2]=valY
