Automate field filter creation

Hi,
I have a dashboard with more than 20 native-query cards and I often need to add new field filters on all of them. It's quite a tedious task so I would like to automate it using the Metabase API. I have analyzed how my browser communicates with the back-end when I add a new filter and I found that it sends a PUT request with the updated card. The new field filter is contained in the template-tags array of the JSON, in the following way:

   "new_filter": {
        "default": null,
        "dimension": [
            "field",
            9264,
            null
        ],
        "display-name": "New Filter",
        "id": "b058958c-1a32-c356-053d-e219754c2715",
        "name": "new_filter",
        "type": "dimension",
        "widget-type": "category"
    }

In the above example, 9264 is the field ID, which can be found in the data model, but I don't understand what is the id b0589.... What is strange is that it does not seem to be an ID previously loaded from the API. Is it a random ID generated on the browser side ?
How can I fill this ID to use the API to automate the field filter creation ?

Thanks !

Here is my diagnostic info if needed :

{
"browser-info": {
"language": "fr-FR",
"platform": "MacIntel",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36",
"vendor": "Google Inc."
},
"system-info": {
"file.encoding": "UTF-8",
"java.runtime.name": "OpenJDK Runtime Environment",
"java.runtime.version": "11.0.13+8",
"java.vendor": "Eclipse Adoptium",
"java.vendor.url": "https://adoptium.net/",
"java.version": "11.0.13",
"java.vm.name": "OpenJDK 64-Bit Server VM",
"java.vm.version": "11.0.13+8",
"os.name": "Linux",
"os.version": "4.14.219-164.354.amzn2.x86_64",
"user.language": "en",
"user.timezone": "GMT"
},
"metabase-info": {
"databases": [
"postgres",
"bigquery-cloud-sdk",
"h2"
],
"hosting-env": "unknown",
"application-database": "postgres",
"application-database-details": {
"database": {
"name": "PostgreSQL",
"version": "11.9"
},
"jdbc-driver": {
"name": "PostgreSQL JDBC Driver",
"version": "42.2.23"
}
},
"run-mode": "prod",
"version": {
"date": "2021-12-10",
"tag": "v1.41.4",
"branch": "release-x.41.4",
"hash": "471cfb9"
},
"settings": {
"report-timezone": "Europe/Berlin"
}
}
}
1 Like

Hi @AnatoleC
The "id" is just a UUID generated in the frontend.
You might also be interested in reading this: https://github.com/metabase/metabase/issues/19330

Thanks @flamber !