Skip to content

Magento 2: REST API Endpoint uses wrong locale

I’m implementing an endpoint where the users can create products from a CSV, using the same logic that Magento implements in the backend to import CSV seems to work great but I have a problem, the options for the attributes came in another language and the validation says that the value is wrong.

For example the visibility options are defined in here:

public static function getOptionArray()
{
    return [
        self::VISIBILITY_NOT_VISIBLE => __('Not Visible Individually'),
        self::VISIBILITY_IN_CATALOG => __('Catalog'),
        self::VISIBILITY_IN_SEARCH => __('Search'),
        self::VISIBILITY_BOTH => __('Catalog, Search')
    ];
}

When it returns to the validation function instead of saying “Catalog, Search” it says “Catálogo, Búsqueda” translating the value to es_ES when I need it in en_US which is the native option.

I tried setting in the URL the {{host}}/rest/all/V1/import/custom-products but keeps giving me the es_ES is the locale defined to the store view and not the global locale

Another thing that I tried was to set the store in the store management but didn’t work.

If I remove the translation of the value works, but now when I access to the backend and change the language has the wrong translation

Does any have an idea?