Search code examples
javascriptnode.jsexpressstrapi

fetch data using some condition in strapi


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