Getting results in all languages

Hi all :wave: !
I'm trying to query the API to retrieve all documents of type Blog article in all languages.
I manage to get all the documents in the master language (french) but I cannot get the other languages.
I've read this doc but I cannot manage to write the query properly.
Here is the link to browse the API on our project : https://payfit.prismic.io/api
Here is the query I'm trying to do:
query = '[[at(document.type, "blog_article")]]'
lang='*'
url = f"https://payfit.cdn.prismic.io/api/v2/documents/search?ref={ref}&access_token={prismic_token}&q={query}&lang={lang}"

Do you know what I'm doing wrong ?
Thanks ! :pray:

Hi @sarah.ledu, I just tested this query on your API and it appears to be working just fine for me:
https://payfit.cdn.prismic.io/api/v2/documents/search?ref=XvS5BhIAAB8Avu9V&q=[[at(document.type,%20%22blog_article%22)]]&lang=*

Thanks @Levi for your time and answer. Do you have a way to see how many articles the above request gives you ? On my side I can only retrieve 184 of them, (which is the same amount of articles I get without adding "lang=*" to the query) The thing is we have more than 250 on Prismic. And articles in other languages than french are not popping up in these 184 (we have at least 40 articles in english).
Thanks

That’s strange. Using the query I sent you above, I’m receiving 313 total items and the very first document is in the “en” language:

Are you seeing something different when you click on that link?

@Levi, yes I have the 313 as well by following your link ! Which is really reassuring :pray:
However, in the lambda I’m calling it from, I still get 184 results. When I change it to lang=en, I get the 184 results as well, as if it was not “reading” the lang parameter in the url.
Any idea about that ?
Thanks !

@sarah.ledu Can you share with me the code you’re using to make your query as well as the final query string that is constructed when you make your call to the API?

@Levi, here is the code :
query = '[[at(document.type, "blog_article")]]'
url = f"https://payfit.cdn.prismic.io/api/v2/documents/search?ref={ref}&q={query}&lang=*"

articles_request = requests.get(url)
response = json.loads(articles_request.content)
results = response['results']

while response.get('next_page'):
    articles_next_page = requests.get(response['next_page'])
    response = json.loads(articles_next_page.content)
    results = results + response['results']
else:
    print(len(results))
    return results

Thanks a lot

@sarah.ledu Okay I think I can see what the issue is here. When you’re dealing with multi-language content, you can’t use the next_page url. It doesn’t take into account the lang attribute so after the first page, you will only receive documents in your main language.

In order to get around this issue, you’ll need to paginate the original url with &page=2 and so on until you’ve retrieved all the pages.

Give that a try and let me know if it solves this issue for you.

1 Like

Yes that’s it !!! :tada: :tada: :tada:
Thank you so much !

You’re very welcome :grinning: