Welcome! Please see the About page for a little more info on how this works.

0 votes
in Syntax and reader by

I need to make an API call with http-kit in Clojure where it uses API-Key as authorization. That is, in Postman, you would usually have the option to add an api-key, api-value and the option to add it to header or query-params.

I know the following would be the way to go in case of basic-auth:

{:url "<api-url>"
 :method :post
 :headers {"Content-Type" "application/json"}
 :basic-auth [<username> <password>]
 :body <body>)}

I need to make an API call with http-kit in Clojure where it uses API-Key as authorization. That is, in Postman, you would usually have the option to add an api-key, api-value and the option to add it to header or query-params.

I know the following would be the way to go in case of basic-auth:

{:url "<api-url>" :method :post :headers {"Content-Type" "application/json"} :basic-auth [<username> <password>] :body <body>)}

But a similar variation isn't working with api-key version. So far, I have tried:

{:basic-auth [<api-key> <api-value>]}

{:query-params {<api-key> <api-value>}}

{:query-params {:key <api-key>, :value <api-value>}}

{:headers {"Content-Type" "application/json", 
                    <api-key> <api-value>}

{:api-key [<api-key> <api-value>]}

{:api-key {<api-key> <api-value>}

and other variations, but it doesn't seem to be working.

Note:
- The authorization works on postman but I couldn't test the full api call there because the body is too long and too complex to copy, and the authorization isn't working from the application.
- I keep getting a 401 error with all these different combinations, and some give typeerrors depending on where in the request they're placed.
- The documentation isn't really useful. Here is the link.

1 Answer

0 votes
by

If it's working in postman, my guess is that postman is sending your api key thru like this:

{:headers {"Authorization" "Bearer MyLongAndComplicatedAPIKeyValue"}}

There are other ways of passing the API key thru, but that's the one I'm most familiar with.

...