Querying my Strapi by post title

System Information
  • Strapi Version: v3.3.4
  • Operating System: Mac OS Big Sur
  • Database: MongoDB
  • Node Version: 14.15.1
  • NPM Version: 6.14.10
  • Yarn Version: N/A

I’m really sorry firstly if this question has already been asked before.

I am attempting to query my Strapi database using the ‘Title’ of the post. This is being done through ‘Strapi’ installed via NPM, in my React front-end.

As an example of the code:

const strapiInstance = new Strapi('https://lemio-blog.herokuapp.com')

  async componentDidMount() {
    const params = this.props.match.params.title
    console.log(params)
    try {
      const posts = await strapiInstance.getEntry('blog-posts', this.props.match.params.title)
      this.setState({
        title: posts.Title,
        description: posts.Description,
        datePosted: posts.createdAt,
        category: posts.Category,
        content: posts.Content,
        author: posts.Author,
        image: posts.MainImage.url
      })
    }
    catch(err) {
      console.log(err)
    }
  }

But unfortunately, it’s not working - it’s erroring out.

Now the params are definitely right. The console log shows the title successfully for each of the posts.

So I guess the problem is coming from my ‘await strapiInstance.getEntry’ code.

Does anyone know how I can re-factor that particular line to get my posts based off of their ‘title’?

Please say if that’s not clear. It feels like I could have explained it better!

const strapiInstance = new Strapi();
What in this case represents the new Strapi? That’s your custom wrapper that returns data? Since I’ve never met somebody doing this.

Related to get the article by title, the easier way: https://your.blog/articles?title=your_title
And the second way, Slug System - Strapi Developer Documentation