getByUID must specify language option?

Hi folks,

In a blog project, I'm trying to use the getByUID to get an article.
const article = await $prismic.api.getByUID('article', params.uid)

It works fine when the requested article is in default locale (en-eu in our case) ;
however, when the article is in any other language, the above query will not work any more. When I pass the {lang: 'locale'} option, the query returns the correct article.

This is not coherent with the documentation on query by uid

Did this helper method change ? (I'm using the SDK @nuxtjs/prismic)

In my use case, I do not want to pass the { lang } option, because of complex fallback logics. And I'm pretty sure that the UIDs are not repetitive across locales.

Hi @Jennie_Q

Welcome to the Prismic community,

I'm not sure I found what is not consistent with t documentation.
As far as I know, when you don't specify the lang then the API will only return the documents in your master locale, and if you would like to get documents in all locales, then you can pass the widecard * such as

api.getByUID('page', 'about-us', { lang : '*' }).then(function(document) {});

Looking forward to your reply,
Fares

Hey Fares,

Thanks a lot for your prompt reply!!

I tried again querying without the helper function, it does work, so my pb is solved :pray:

      const article = await $prismic.api.query(
        $prismic.predicates.at('my.article.uid', params.uid),
        { lang: '*' }
      )

However, getByUID() didn't return anything in my case, when passing a wildcard option { lang: '*' }.

const article = await $prismic.api.getByUID('article', params.uid, { lang: '*' })

I might have done sth wrong above, or mis-understood the note in the doc:

Note that if you don't specify the language or if you specify the wildcard value '*', the oldest document with this UID value will be returned.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.