Authentication
The FloatHub API uses bearer tokens to authenticate requests. So before you
can make any other calls to the API, you must first retrieve an
Authentication Token. This is done by calling the /token
method and
including your user credentials. So if your FloatHub username is Boaty
and your password is mcboatface
, your /token
call would look like
this:
curl --request POST -H "Content-Type: application/json" \
--data '{"username":"Boaty","password":"mcboatface"}' \
https://api.floathub.com/v2/token
If succesful, you will recevive back a JSON response that looks like this:
{"account":"Basic",
"email":"boatymcboatface@example.com",
"token":"eyJhbGciOiJIUzI1N...XosykYIc",
"username":"Boaty",
"valid":true,
"vessel":"SS Boaty McBoatface"}
except that the token
field will be much longer. Store this value, as
it is the Bearer Token you will need to authenticate all your subsequent
calls to the API. By default, the token should be valid for roughly 6
months, so you will only need to ask for a new one very infrequently. A
call to any other API endpoint with an expired token will result in an HTTP
error of 401 (“unauthorized”), in which case a new token should be retrieved
from the /token
method.