Reputation: 11
I'm trying to use a GET request using clj-http.client from ShipStation and getting a 401 error,
they have lots of examples of different languages of how to do this. Javascript seems easy:
var myHeaders = new Headers();
myHeaders.append("Host", "ssapi.shipstation.com");
myHeaders.append("Authorization", "username:password");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://ssapi.shipstation.com/orders/orderId", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Here is my clojure client/get code which works fine without headers and using {:async? true} from other websites such as jsonplaceholder:
(client/get "https://ssapi.shipstation.com/shipments?shipDateStart=2023-01-05&shipDateEnd=2023-01-05"
{:header { "Host" "ssapi.shipstation.com" "Authorization" "username:password"}}
(fn [response] (println "hello" (get response :body)))
(fn [exception] (println "exception message is: " (.getMessage exception))))
can someone help me with the format of this GET request?
Upvotes: 0
Views: 211
Reputation: 5877
As per the docs it looks like you want:
(client/get "https://ssapi.shipstation.com/shipments"
{:async? true
:basic-auth "username:password"
:query-params {:shipDateStart "2023-01-05" :shipDateEnd "2023-01-05"
:as :json}
(fn [response] (println "hello" (get response :body)))
(fn [exception] (println "exception message is: " (.getMessage exception))))
That presumes that Basic-Auth is in play which is what the endpoint and api docs suggest but I'm not a shistation user
Upvotes: 0
Reputation: 11
Found the answer to calling shipstation api in clj-http: https://stackoverflow.com/a/25794180/21046503
(clj-http.client/get "http://my.domain.com"
{:basic-auth [username password]})
Upvotes: 1