Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing API key with HTTP header in cURL

Tags:

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?

like image 488
kuk_94 Avatar asked Nov 28 '16 06:11

kuk_94


People also ask

How do I pass HTTP headers in curl?

To send an HTTP header with a Curl request, you can use the -H command-line option and pass the header name and value in "Key: Value" format. If you do not provide a value for the header, this will remove the standard header that Curl would otherwise send. The number of HTTP headers is unlimited.

How do I pass a header to API key?

You can pass in the API Key to our APIs either by using the HTTP Basic authentication header or by sending an api_key parameter via the query string or request body. If you use our client library CARTO. js, you only need to follow the authorization section and we will handle API Keys automatically for you.

How do I pass a header to a postman API key?

In the request Authorization tab, select API Key from the Type list. Enter your key name and value, and select either Header or Query Params from the Add to dropdown list. You can store your values in variables for additional security.

What is the curl option that allows passing HTTP header variables?

curl command provides the -H option in order to provide HTTP headers.


1 Answers

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  
like image 63
Martin Brandl Avatar answered Sep 17 '22 17:09

Martin Brandl