How to pass SQL query to Metabase using python and get the graph of data

I want to pass SQL query to the Metabase using python jwt and get the desired graph back to display it on my Django site. can you please help me? I know we can get the data by adding a question to Metabase itself and getting the data of the question to python but I want different graphs for each user which involves queries with different user_id so I want to pass different sql queries for each user to obtain their data.
PLEASE HELP!!

I also interested in.

Use parameters to pass the user id to the embedded question.

I have " select * from table_name where source = {{source}} " in my Metabase question
and in my python Im passing
payload = {
“resource”: {“question”: 11},
“params”: {
‘source’: ‘source_name’
}
}

It says “undefined parameter : source”

Sorry, can’t help with that. My code is all C# so I have to build up a JwtPayload with dictionaries. I never see the messy plumbing, just elegant code :wink:

Make sure your parameters are set to Locked and compare your code to that in the sharing section. I think you’ll need to share dashboards rather than questions to pass parameters too.

Yeah I figured that out. I was on the right track. All I needed was to change the settings of my variable “source” and make it editable and publish the question again. Once I did that it worked for me. Thanks for the help tho.

Hi @patelneal500,
Could you get the image of the graph data? If so how? I also interested in this.

Let me know where you are stuck and I’ll help you. Unfortunately I can’t show you the data as it is confidential.

In fact, I haven’t started yet but I’ve built an application by using rest API with C#. I think that Metabase API doesn’t support taking the image of the graphs. So how did you approach this problem? Which tools did you use? Did you use something like PhantomJS (Headless browser) to take images? I don’t need any data but some directions would be helpful.

Its not an image. when you embed some data Metabase creates an “iframe” link and you can use the iframe link in your application to display the graph. So the graph is live in your application as well.

If you have a code in C# I don’t think there is a library to directly access the Metabase data. You will have to build up the data using dictionary and pass it to Metabase as @AndrewMBaines said. Whereas if you are coding in Python/ NodeJS/Ruby Metabase has an easy graph sharing library for these languages.

here is the link - https://metabase.com/docs/v0.23.0/administration-guide/13-embedding.html