Qiimiia
Qiimiia

Reputation: 607

how to send apikey when using IBM Cloud API?

I'm trying to call IBM cloud speech to text API directly from my angular project.

getAudioFile (text: string) {
    return this.http.post(this.apiUrl, {
        text: text
      }, {
        headers: {
          'Content-Type' : 'application/json',
          'Accept' : 'audio/wav',
          'authorization' : 'apikey:' + this.apiKey
        },
        params: {
          voice: 'en-US_AllisonV3Voice'
        }
      }).pipe(map(res => console.log(res)), catchError(this.handleError))
  }

I got the apiKey and apiUrl from the website specifically for my account (which works as a token). I'm just not sure if I'm sending it the right way. Please help me if you have done this before.

Upvotes: 1

Views: 192

Answers (1)

data_henrik
data_henrik

Reputation: 17118

See the API documentation and its authentication section. If you want to use the API key, then it is used with Basic access authentication. The username would be "apikey", the password the actual API key. The username and password are base64 encoded. Conceptually, your code would need to look like this:

'Authorization' : 'Basic ' + Base64Encoded("apikey"+this.apiKey)

Upvotes: 1

Related Questions