Having fun with Metabase API
What's an API and what's the point of using one?
That's probably the most legitimate question here. Well so far you know the GUI of Metabase but the thing is that the IT guys within your organization are going to be tired of clicking here and there in order to access the data that you are referring to.
In fact they would rather prefer to automate the tasks and make what you need in the minimum amount possible of time. This is what an API is about the possibility to interact directly through commands with Metabase in order to do things quicker. The full documentation of Metabase API is located here:
https://github.com/metabase/metabase/blob/master/docs/api-documentation.md
let's see how that works.
Querying the Metabase API
So as all APIs, in order to query it, you need some credentials, probably for some security reasons, you need to query the API in order to get it, from their documentation here is the request you need to perform:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"username": "cam@metabase.com", "password": "myPassword"}' \
http://localhost:3000/api/session
This is generate a result which will be the API token, in my case it was 3933c771-4dd7-43ea-bddc-5cd1a12e117c, unless you regenerate it, it will be the same all the time. Now you can query the database.
The list of the different methods you can call are listed on https://github.com/metabase/metabase/blob/master/docs/api-documentation.md. So to say, let's imagine that you would like to know the list of all the collections that you have within Metabase, you will perform the following request:
curl -X GET \
-H "Content-Type: application/json" \
-H "X-Metabase-Session: 3933c771-4dd7-43ea-bddc-5cd1a12e117c" \
http://localhost:3000/api/collection
and got the following results:
[{"name":"Our analytics","id":"root","parent_id":null,"effective_location":null,"effective_ancestors":[],"can_write":true},{"description":null,"archived":false,"slug":"ronan_root_s_personal_collection","color":"#31698A","can_write":true,"name":"Ronan Root's Personal Collection","personal_owner_id":1,"id":1,"location":"/"}]
Oh... but this is unreadable !!! not really, as the Metabase documentation is mentioning it, it uses only json results, Json is a structured format in IT in order to display data according to a certain logic. Your developer is able to take the results out of this format.
Note that the API is not only about extracting data, you can also control any features of Metabase such as creating pulse, collection, adding a new user...
Give an example down below.