Issue
I am creating api using strapi.
i have a situation, i want to fetch data
where audience_name like ‘%audienceName%’ and created_by = 4;
below is my strapi code
findByName: async (ctx) => {
const audienceName = ctx.params.name;
return strapi.services.audience.find({
audience_name: { 'like' : audienceName},
created_by: ctx.state.user.id
});
},
but i am not able to get the data it is trowing internal server error as below.
Solution
In your case you will have to use these two concepts:
- Available filters – To see how filters with
contains
instead of%
- Deep filtering – To filters on
User
relation
You will see, params you are trying to send are not in the right format.
Your code should look like this
const data = await strapi.services.audience.find({
audience_name_contains: audienceName,
created_by: ctx.state.user.id
});