Get shop's locale for admin graphql api for transactional email

Hi,
my app is sending a transactional emails to users of the app. I can get the user shop’s email via the graphql query shop.email. However I was not able to find a way to get the locale of the user to know in which language I should use for the email.

Note that I know how to get the locale in the context of an embedded app, but the email is sent by a background task triggered by a webhook.

Any idea?

Thanks

Sorry, I might not be following completely but are you looking for this:

With this graphQL query you can get a list of locals and see which is the stores “Primary”

Then you can use this information to adjust language settings.

@Drew Thanks for your response, and sorry if my initial message wasn’t clear.

What I’m trying to do is send an email to the person who installs and uses our app, and I’d like that email to be in their preferred language.

To give you an example:
Imagine you’re browsing the Shopify App Store and find an amazing app. You install it from your Shopify admin, and then you receive a welcome email from the app. Ideally in the same language you’ve set in your Shopify settings (which is also the language the app interface displays in).

But in my case I do that in a webhook, so I don’t have access to the admin’s configured locale.

If that’s not easily available, I think using the shop’s primary language would also be safe to use.

If you’re sending transactional emails from a background task (like a webhook handler) and not from the embedded UI, you can still get the shop’s locale using the Admin GraphQL API with the shopLocales query.

query {
  shopLocales {
    locale
    primary
    published
  }
}

This will return something like:

{
  "shopLocales": [
    {
      "locale": "en",
      "primary": true,
      "published": true
    },
    {
      "locale": "fr",
      "primary": false,
      "published": true
    }
  ]
}

From that, you can:

  • Detect the primary locale (primary: true)
  • Or choose a preferred language if the shop has multiple published ones

Make sure your app has the read_locales or read_markets_home access scope enabled.

1 Like