title |
---|
API keys |
Metabase can create API keys to authenticate programmatic requests to the API. To set the permissions for an API key, you can assign the key to a group.
We don't version the Metabase API. We rarely change API endpoints, and almost never remove them, but if you write code that relies on the API, there's a chance you might have to update your code in the future.
That said, there are times when it's nice to work with the API, like when managing permissions with a large number of people and groups, or bulk archiving, or content creation. So we added the ability to create API keys to authenticate your programmatic requests.
To create an API key:
If you're on a Pro or Enterprise self-hosted plan, you can create API keys via the configuration file.
To view and manage existing API keys:
To edit an API key, scroll to the key you want to edit and click on the pencil icon. Metabase will pop up an Edit API Key modal where you can edit:
You won't be able to recover a deleted API key. You'll have to create a new key.
To delete an API Key:
If you have API keys assigned to a group, but then someone deletes that group, the API keys will still work, but Metabase will reassign those keys to the All users group. If you want to change their group, you'll need to edit the keys manually.
GET
requestsHere are some example GET
requests that return the groups in your Metabase. These examples assume you're running Metabase locally on the default port: 3000.
curl
exampleReplace YOUR_API_KEY
with the API key you generated above.
curl \
-H 'x-api-key: YOUR_API_KEY' \
-X GET 'http://localhost:3000/api/permissions/group'
Assuming you've set your key as an environment variable like so:
export METABASE_API_KEY="YOUR_API_KEY"
Here's a basic GET
request using fetch
to get the list of groups. You can copy the code, save it as file (e.g., as api-test.js
), and run the code with node api-test.js
.
// Assuming you've set the key in process with
// `export METABASE_API_KEY="YOUR_KEY_HERE"`
const API_KEY = process.env.METABASE_API_KEY;
const init = {
headers: {
"Content-Type": "application/json",
"X-API-KEY": API_KEY,
},
};
const host = "http://127.0.0.1:3000";
async function getGroups() {
const response = await fetch(`${host}/api/permissions/group`, init);
return response.json();
}
getGroups().then(groups => console.log("Groups in your Metabase:", groups));
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )