How do I query the Admin API in a specific language

Or rather how is multilang supposed to work when qerying data from the Admin API in general?

This is my specific usecase:

Suppose I’m only using a single Storefront with multiple languages. 

I’d like to select certain products that have some text in a specific language (in my case) in a translatable custom field. So far what I have achieved is getting the products when the entry in the (default?) English language matches:

    “filter”: [
            “type”: “equals”, 
            “field”: “customFields.my_custom_field”, 
            “value”:  “some_key_in_a_specific_language”

As mentioned, this returns matching producs that have “some_key_in_a_specific_language” in the english translation of that custom field.
Now, how can I perform the same request querying another language? I struggle to find any documentation on switching the context used when querying the Admin API.

Furthermore, how can I retrieve translations of products or other data in general through the API?

Writing translatable data seems to be no problem as different translations can be supplied within the payload used to create the product as described here:

Figured it out.

It’s possible to pass the ‘sw-language-id’ Header with a specified language id.

Magic happens in \Shopware\Core\Framework\Routing\ApiRequestContextResolver::getRuntimeParameters

Some documentation would have been nice here.

Note that specified unique id of the langauge must follow the Regex in \Shopware\Core\Framework\Uuid\Uuid::VALID_PATTERN, otherwise some validation check fails.

Hey @patchee500 Did you find a way to do the same thing when querying with DAL Requests? I need to update products using a specific language which is different from the main language of the shopware system.

Hello, what do you mean with DAL Requests? Normal PHP Updates as described here?

For that I assume the context you pass to the repository will be responsible for selecting the right language for you. Maybe you need to tweak that or try the default context from \Shopware\Core\Framework\Context::createDefaultContext.

If your question is about updating corresponding language data, you simply need to format your the data you send through accordingly. I can’t seem to find any documentation on this after the whole docs have been switched around (again) but you can stick to this explanation from the REST-API: Associations - Shopware Developer

Simply format the data you give the repository to write in DAL the same way, including the „translations“ object and the corresponding objects underneath specified via the language code (e.g. „de_DE“).

Yeah this is what I mean „normal update“.
See here as example :

$criteria->addFilter(new EqualsFilter(‚name‘, ‚Zilverkleur‘));
$lineInfo = $this->propertyGroupOptionRepository->search($criteria, Context::createDefaultContext())->first();

Currently, it’s only checking this value with language_id corresponding to English so it’s not able to find it and giving an error.

How should I do to filter on the language „dutch“ and only dutch ??

Well I think modifying the Context somehow to suit your case should work somehow.
But that could be rather complicated. Wouldn’t it be enough for you to add the ‚translations‘ association?
This might already give you the data that you need, but for all languages, I think.

$criteria->addFilter(new EqualsFilter(‚name‘, ‚Zilverkleur‘));
$lineInfo = $this->propertyGroupOptionRepository->search($criteria, Context::createDefaultContext())->first();

Sorry, I realized that I misinterpreted your question.
I’m also not sure right away what you’d need to do here. My guess would still be either modifying the context somehow or maybe specifying the language in the filter somehow. Something like $criteria->addFilter(new EqualsFilter('', 'Zilverkleur'));. But I’m not sure how/if something like this is supported. Guess, you’ll have to debug a bit to find out.