Query using multiple IDs

Hi guys,

I have a JavaScript application that is trying to get 3 bits of content using their entry ID as the search param. As per the documentation here (https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/array-with-multiple-values) I have tried this:

contentful
    .getEntries({
      content_type: 'questions',
      'sys.id[all]': '3Lxm3zFmkMe0qAuougiEIC,2pZvONhDmy0saKgqqi4E0W,5E26wo72fYcWqwYEoGcwUq'
    })
    .then((response) => {
      res.json(response.items);
    });

But this seems to cause the client to crash and stop working.

Obviously I could just make 3 requests but this seems a little wasteful if I could do it in one. Any idea how I can achieve this?

Thanks,

Alex

Hi Alex!

I believe you could just change your query to use the [in] operator instead.

'sys.id[in]': '3Lxm3zFmkMe0qAuougiEIC,2pZvONhDmy0saKgqqi4E0W,5E26wo72fYcWqwYEoGcwUq'

You are correct in saying that all was the wrong choice, apologies I misread the docs. Having tried that it only returns one result (the first ID in the list).

Any other suggestions?

That sounds weird, are all of the entries of the questions content type? Otherwise, just remove that constraint and it should retrieve all the entries.

Another thing to check is that all the entries are published. The CDA will only return published entries.

Just confirmed that they are all published (they were already) and attempted removing the content_type prop but I still only get one response, the first ID in the list.

Any further suggestions?

hmm there’s nothing wrong with the syntax. I would test making a manual call to the CDN to try to figure out what’s going on.

Something like http://cdn.contentful.com/spaces/SPACEID/entries/?access_token=ACCESSTOKEN&sys.id[in]=3Lxm3zFmkMe0qAuougiEIC,2pZvONhDmy0saKgqqi4E0W,5E26wo72fYcWqwYEoGcwUq

The above is the call to the CDN your javascript code eventually results in. Does that also just give you a single entry back?

If it does, are the other entries included in the Includes object?

The CDN link also returns a single entry and the other fields are not in the includes prop. The includes has information about a linked file but not the other questions.

Do you want me to send you the link via some sort of private message so you can have a look yourself?

Sure, there seems to be no great way to do that on the forum, but feel free to reach out to me on our community slack, username Robban and we’ll get to the bottom of this.

https://www.contentful.com/slack/

Hey!

I was wondering if there was a solution found for this issue?
I’m countering the same problem at the moment…

Thank you,
Arne

Hey @arnevankauter,
Could you tell us what exactly is missing from your response?
I was able to perform this query and here’s a working example from our example CDA:

https://cdn.contentful.com/spaces/yadj1kx9rmg0/entries?access_token=fdb4e7a3102747a02ea69ebac5e282b9e44d28fb340f778a4f5e788625a61abe&sys.id[in]=1Rx34DbEYMywWmM6o8SCUi,11vnZ49Hj8aQy6S8EcSMsy

I was having the same issue using the Client on Javascript. I was adding spaces when separating with commas. If you add spaces it breaks and you’ll get only the first result.

1 Like

This is the answer right here when using getEntries in JavaScript/TypeScript! Spaces break the query and give you the first result only.