Dictionary lookup bad request 400

I’m using dictionary lookup for finding alternative translations.

dictionaryLookupMS = async (data) => {
    const key = "myKey";
    const endpoint = `https://api.cognitive.microsofttranslator.com/dictionary/lookup?api-version=3.0&from=${data.originLanguageCode}&to=${data.translationLanguageCode}`;
    const location = "westeurope";
    const text = data.text;

    try {
      const response = await axios({
        baseURL: endpoint,
        method: "post",
        headers: {
          "Ocp-Apim-Subscription-Key": key,
          "Ocp-Apim-Subscription-Region": location,
          "Content-type": "application/json",
          "X-ClientTraceId": uuidv4().toString(),
        },
      ,
        data: [{
          "text": text,
        }],
        responseType: "json",
      });
      return response.data;
    } catch (error) {
      logger.onError(error, operationTypes.dictionaryLookupMS, `${data.originLanguageCode} -> ${data.translationLanguageCode}: ${data.text}`);
      return [];
    }
  };

When origin language code is for example us and target is uk everything works fine. I get that I want.
But when the origin language code is es and and target is ru I get an error:

AxiosError: Request failed with status code 400
...
code: 'ERR_BAD_REQUEST',
>    config: {
>      transitional: {
>        silentJSONParsing: true,
>        forcedJSONParsing: true,
>        clarifyTimeoutError: false
>      }
...

It means that the code works fine, but something wrong with es code at endpoint.
In docs there are information that requested languages support dictionary lookup.
May be anyone can try this language pair and check if it work?
Any suggestions?

Try to get translations but get a bad request error

Leave a Comment