Reputation: 523
I have an API Proxy in Apigee which is authenticated with an API key. I'm passing the key with my HTTP request header using cURL, with this command:
curl -v -H "apikey: my_key" http://api_org-test.apigee.net/v1/helloapikey
I get this error:
Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the
"apikey: my_key" value of type "System.String" to
type "System.Collections.IDictionary".
When I modify my policy to look for the key in query parameter rather than the header, it works fine. Am I missing something here?
Upvotes: 37
Views: 144118
Reputation: 2118
PowerShell simply does not resolve the variable within your URL. You are trying to query the service at the URI http://$serverHost:1234/service
which won't work. You could do
$serverHost = "myHost"
$service = "http://$serverHost`:1234/service"
Invoke-WebRequest $service -Method Get
Upvotes: 1
Reputation: 1444
None of the above answers worked for me (I got an error -- parse error near }
).
This worked:
curl -X GET \
'http://api_org-test.apigee.net/v1/helloapikey' \
-H 'apikey: my_key'
Upvotes: 9
Reputation: 11
Just to add this to the discussion, I had to both hash the api key, but leave the token call key phrase rather than change it to 'apikey'. That's just what worked for me!
curl -v -H @{'X-API-TOKEN' = '[*insert key here*]'} '*datacenter_url*)'
Also noteworthy to PowerShell newcomers, -v stands for verbose. This switch gives you a Cyan-colored text under the command in PowerShell ise about the command PS is running. Almost like a play-by-play commentary. Useful enough I thought I'd mention it.
Upvotes: 1
Reputation: 3088
You could install curl: https://stackoverflow.com/a/16216825/3013633
Remove existing curl alias by executing this command:
Remove-item alias:curl
Then your command will work:
curl -v -H "apikey: my_key" http://api_org-test.apigee.net/v1/helloapikey
Upvotes: 15
Reputation: 58931
Try this:
curl -v -H @{'apikey' = 'my_key'} http://api_org-test.apigee.net/v1/helloapikey
Note:
curl
is an alias for the Invoke-WebRequest
cmdlet:
Get-Alias curl
output:
CommandType Name
----------- ----
Alias curl -> Invoke-WebRequest
Upvotes: 48