curl,

How to Pass Api Key Header in Curl

Dec 13, 2022 · 1 min read · Post a comment

Most of the API proxy services like AWS Gateway API are used to secure some requests with a level of authentication. To achieve that you can use either Bearer tokens or API Keys. Here I’m going to show you how to pass an API key with an HTTP header using curl.

Prerequisites

  • Curl
  • sudo access

Solution

  • Try the following curl syntax to pass the API key header in the request.
    curl -v -H "apikey: your-api-key" https://domain.com/json/element
    
  • If you get an error from the above curl request, you can try to specify the HTTP method you need.
    curl -X GET \
    'https://domain.com/json/element' \
    -H 'apikey: your-api-key'
    

Conclusion

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.