Pass userid into Application sharing code


I have a web portal where I store information about have multiple physical sites. I have many users who are restricted to operate one or multiple sites. I want to create a dashboard that would restrict user access only to their sites.

I had an idea if it would be possible to pass programmatically userid from my portal where I embed the dashboard into Metabase custom SQL query. This query would look up sites available to user and would limit the data only to what access the user has. Is there a way to pass a filter param from my portal into custom SQL of the metabase?
Can I use param in the Sharing ->Application code to resolve this?
var payload = {
resource: { dashboard: 1 },
params: {}

Yes, using params is one way to do it, since it is where filters would be placed.
More info about embedding:
Code examples for a few languages:

Thanks for this.
One more related question, is there a way to limit the list of values in the Field Filter? I.e. I have the list of many sites, but I want user see in the filter dropdown box only sites the user has access to?

You should embed the cards (the questions) and control them with a your own select-options.
If you want a final solution, then Metabase Enterprise has feature called Sandboxing, which sounds to do what you’re looking for.

Hi @flamber. If I want to develop the solution on my own, do I code the select filters separately and then pass the values into Metabase? In this case every time the value changes, I would pass it as param into Metabase and force a refresh. In the free version, I can’t restrict the values in my list?

Correct, you need to code the select filters separately (outside of Metabase) and pass the values.