Open balena internal API for login, getting a valid token internally

Hi there guys,

I am trying to make a login via a console application, while trying to make the API with the curl inside the openbalena-api container, and for every request I get a redirect to my public redirect API_HOST, which has been set in environment variable.

On the official documentation page, I could not find the proper information.

Tried different approaches: API Key as Bearer token and Service tokens.

Here is an output of what I’m getting when trying to login via curl on the same container of the API:

root@538ed6bca06c:/usr/src/app# curl -i -L -X GET --location 'http://localhost/device' --header 'AdminBalenaAPIKey: MY_API_KEY_HERE'

HTTP/1.1 301 Moved Permanently


Vary: Accept

Content-Type: text/plain; charset=utf-8

Content-Length: 72

Date: Wed, 13 Dec 2023 15:39:37 GMT

Connection: keep-alive

Keep-Alive: timeout=5

HTTP/1.1 404 Not Found

X-Frame-Options: DENY

X-Content-Type-Options: nosniff

Content-Security-Policy: default-src 'none'

Content-Type: text/html; charset=utf-8

Content-Length: 145

Vary: Accept-Encoding

Date: Wed, 13 Dec 2023 15:39:37 GMT

Keep-Alive: timeout=5

<!DOCTYPE html>

<html lang="en">


<meta charset="utf-8">




<pre>Cannot GET /device</pre>




Does anyone have an example of a curl request to OpenBalena API? I am looking for login request example, getting a token and revalidate it.

Thanks, looking forward!

@elsevero where do you get your token from?

On the other hand, did you try this? Postman


Any particular reason you’re not just using the public API url?
I think running it from within the container will only make things more complicates because of the redirects. They turn POST requests automatically into GET requests.

WIth the public url you can get a session token this way:

curl  -X POST \
  '' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "username": "<username>",
  "password": "<password>"

And then verify the user with something like this:

curl  -X GET \
  '' \
  --header 'Authorization: Bearer <session-token>
1 Like