[Fixed] fetch data using some condition in strapi

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.
enter image description here

Solution

In your case you will have to use these two concepts:

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
});

Leave a Reply

(*) Required, Your email will not be published