1

I am trying to call bing text to speech azure services but i keep getting this error on getting the access token , although the subscription key is provided

function requestAudio(text,lang)
{
    nameLanguage = "Microsoft Server Speech Text to Speech Voice (en-GB, Susan, Apollo)";
    language = lang;
    textToSpeak = text;
    $.ajax(
    {
        type: 'POST',
        url: tokenURL,
        data: 
        {  
            'Ocp-Apim-Subscription-Key': 'xxxxxxf8cc34d08b646de1bc54c950d'
        }
    }).done(function(data) 
    { 
        token = data.access_token;
        sendAudioRequest();
    });
}

The error exactly from fiddler is

{ "statusCode": 401, "message": "Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API." }

and the url i am calling is

https://api.cognitive.microsoft.com/sts/v1.0/issueToken
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Mazen Abu Taweelih
  • 637
  • 1
  • 9
  • 24
  • Related posts - [API management URL is giving Missing subscription key Issue](https://stackoverflow.com/q/51519687/465053)] & [Azure Api management Is it possible to disable Subscription Key](https://stackoverflow.com/q/51376248/465053) – RBT Sep 30 '21 at 14:23

1 Answers1

5

I'm pretty sure you have to set those in the header, not in the body.

beforeSend: function(request) {
  request.setRequestHeader("Ocp-Apim-Subscription-Key", 'xxxxxxf8cc34d08b646de1bc54c950d');
},

Reference: https://msdn.microsoft.com/en-us/library/mt712546.aspx

4c74356b41
  • 69,186
  • 6
  • 100
  • 141