Content Mangement API: filter[query] Examples

Are there any examples of what the “textual query” used in items.all() call might look like? The example provided only has the unfortunately obtuse filter[query]: "foo"

hello @glebdenisov, welcome :slight_smile:

You are very right that we should improve our documentation. Meanwhile, what you can do is to use the CMS to filter and inspect the calls that we do in the browser to replicate them in your code.

An example that I can provide is:

filter[fields][title][matches][pattern]: some text

Let me know if the workaround is fine or if you need more details on a specific query.

1 Like

Can you please update the examples to this instead ? filter[query]: "foo" is not helpful.

hello @niko thank you for spotting that, it was actually a bug!

Please have a look now at the documentation: https://www.datocms.com/docs/content-management-api/resources/item/instances

hopefully it’s more helpful now.

@mat_jack1
I was trying to use the way you provide. but it isn’t work
when I try with this, it work
const records = await client.items.all({
filter: {
type: “testmodel”,
fields: {
testtitle: {eq: “test1”}
},
}
});

but when I tried this, it’s not working
client.items.all({
nested: ‘true’,
‘filter[type]’: ‘testmodel’,
‘filter[fields][testtitle][eq]’: ‘test2’,
‘page[offset]’: 2,
‘page[limit]’: 15,
})

Is there anything I did wrong?

Hey @jeff.f.chen I just tried and it works for me.

Can you maybe give me the real example with your project URL as well so that I can try? If you prefer send the info over at support@datocms.com

Thanks!

Sure,
Just PM you and also send my project URL to that email address.

Thank you!

1 Like

Hi,
I am trying to list some records using the filter parameter on with a http request, but the documentation only provides examples for the Javascript client.
I tried your suggestion to get the filter[fields]...: some text and encode it, but didn’t work.
Could you give me an example on how I can use the filter parameter in http request?

Thanks in advance!

Hello @tiago

Here is an example:

Lets say you want to find a record in the model posts that has a field title with the value travel you would run a

GET

https://site-api.datocms.com/items?filter[type]=posts&filter[fields][title][eq]=travel