0
votes

I am trying to connect to Azure Machine Learning Web service using Invoke-WebRequest in PowerShell. after bellow command I will get an error that "Request is unauthorized to access resource.":

Invoke-WebRequest -Uri $Url -Method POST -Body $body

As I know, you can connect to a Machine Learning Web service using any programming language that supports HTTP request and response. read more about it here.
Seems I need to pass API Key with my request. I have tried this two types of command, but the error was same:

Invoke-WebRequest -Uri $Url -Method POST -Body $body -Headers @{'apikey' = $API_key}

and

Invoke-WebRequest -Uri $Url -Method POST -Body $body -Header @{ "X-ApiKey" = $API_key }

Can you please guide me how I can pass API Key to the Azure Machine Learning Web service using PowerShell?

2
Have you read their documentation? - Maximilian Burszley
If you look at that doc you linked: -Headers @{ Authorization = "Bearer " + $apiKey } - Maximilian Burszley

2 Answers

0
votes

Per TheIncorrigible's comment, try this:

Invoke-WebRequest -Uri $Url -Method POST -Body $body -Headers @{ Authorization = "Bearer " + $API_key }

You are passing a JSON string, so you could also just use the ConvertTo-Json command to create your true API key. For info on that check this out: using powershell with JSON data

0
votes

You should use this:

Invoke-WebRequest -Uri $Url -Method POST -Body $body -Headers @{ 'Content-Type' = 'application/json'; 'Authorization' = "Bearer " + $API_key }