5

I am trying to figure out how to retrieve specific articles based on author (reference), my current function retrieves all articles, but I only want the author specific ones

 const resp = yield client.getEntries({
  'fields.insightsArticle': true,
  'fields.excludeCountries[nin]': country,
  'fields.publicationDate[lte]': moment(new Date()).toISOString(),
  'fields.author.fields.firstname': author.firstName,
  'fields.author.fields.lastname': author.lastName,
  content_type: 'insight',
  include: 2,
  order: '-fields.publicationDate',
  limit,
  locale,
});

The current log I am getting from contentful is: "When searching on references you must specify the Content Type of the reference. Please send a Content Type id as a query parameter"

I get that, since I am defining the content type as insight.

Any suggestions are welcome!

Bram Wesselink
  • 127
  • 1
  • 1
  • 6

1 Answers1

8

i had the same problem! you can specify the content type of the reference by adding:

'fields.author.sys.contentType.sys.id': 'author'

also, i would move the content_type: 'insight' line as the first entry and remove limit and locale since you're not using those fields.

cattourist
  • 209
  • 2
  • 5
  • also i got another error saying i had to reduce my category field to one instead of two, so you might also have to condense first and last names into just name – cattourist Jan 11 '20 at 01:08
  • I know this thread is super old, but where and how did you figure out the `fields.author.sys.contentType.sys.id` value? – hybrid9 Jun 30 '22 at 15:04
  • cattourist - hoping you can help ^^ – hybrid9 Jul 21 '22 at 02:32
  • 1
    See https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/search-on-references – wanna_coder101 Nov 21 '22 at 07:24