Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
MS translator request not authorized

I have this simple code to get translation:

    var apiurl = 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0';
    var my_token = 'xxxxxx'; // my sekret key
        jQuery.ajax({
            url: apiurl,
            dataType: "json",
            jsonp: "oncomplete",
            crossDomain: true,
            context: this,
            data: {
                text: 'Test simple text',
                from: 'en',
                to: 'de'
            },
            beforeSend: function (xhr) {
                xhr.setRequestHeader('Ocp-Apim-Subscription-Key', my_token);
                xhr.setRequestHeader('Content-type', 'application/json; charset=UTF-8');
                xhr.setRequestHeader('X-ClientTraceId', uuid());
                xhr.setRequestHeader('Ocp-Apim-Subscription-Region', 'westeurope');
            },
            contentType: "application/json; charset=UTF-8",
            type: 'POST',
            success: function (msg) {
                console.log(msg);
            },
            complete: function (msg) {
            },
            error: function (e) {
                console.log(e);
            }
        });

But I got always error 401000 The request is not authorized because credentials are missing or invalid.

I used secred ID from picture. enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your screenshot shows an app registration configuration page in Azure Active Directory - this is something entirely different. What you want is creating a Translator resource and then take one of the keys from the "Keys and Endpoints" menu:

enter image description here

about 4 years ago · Juan Pablo Isaza Report

0

With the following adjustments, the code should work:

  • use in my_token one of the subscription keys under "Azure portal > Translator resource > Keys and Endpoint > Key 1 or Key 2"
  • check the region for Ocp-Apim-Subscription-Region (also required for authentication), use the term under "Azure portal > Translator resource > Keys and Endpoint > Region"
  • insert in apiurl: &from=en&to=de
  • change data in: JSON.stringify([{ 'text': 'Test simple text' }])

var apiurl = 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=de';
var my_token = 'xxxxxx'; // subscription key
jQuery.ajax({
    url: apiurl,
    dataType: "json",
    jsonp: "oncomplete",
    crossDomain: true,
    context: this,
    data: JSON.stringify([{ 'text': 'Test simple text' }]),
    beforeSend: function (xhr) {
        xhr.setRequestHeader('Ocp-Apim-Subscription-Key', my_token);
        xhr.setRequestHeader('Content-type', 'application/json; charset=UTF-8');
        xhr.setRequestHeader('X-ClientTraceId', uuid());
        xhr.setRequestHeader('Ocp-Apim-Subscription-Region', 'westeurope');
    },
    contentType: "application/json; charset=UTF-8",
    type: 'POST',
    success: function (msg) {
        console.log(msg);
    },
    complete: function (msg) {
    },
    error: function (e) {
        console.log(e);
    }
});

function uuid() {
  return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
    (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
  );
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!