How to use "visualization_settings" to create new graph via API?

Dear Metabase Team

I’ve successfully created a new card using your API via POST /api/card/ and the following json string:
json = {
“dataset_query”:
{
“database”: 2,
“native”:
{
“query”: query
},

        "type": "native"
    },
"display": "table",
"name": "api_test_card",
"collection_id": 59,
"visualization_settings": {}

}

query’s just a string of the form “SELECT * from (VALUES (1, 2, 3, 4, 5), (6, 7, 8, 9, 10)) t (c1, c2, c3, c4, c5);” as I’m still testing.

I’ll get the data displayed in table format, but what I want in the end is a bar chart of the following form:

  • c1 as x-axis (timeseries)
  • c2, c3, c4 as y-axis
  • x-axis named “date”
  • y-axis named “USD”
  • c2 datapoints colored green
  • c3 datapoints colored blue
  • c4 datapoints colored red

I’ve searched through your API docs, grepped your source code and also checked the metabase-api package. Unfortunately I couldn’t find the right information. Would you mind giving me a little hint how to figure out the settings? I assume I’ve got to find the appropriate values for key “visualization_settings” in the submitted json?

Your help is very much appreciated.

Thanks,
Raphaela

Hi @raphaelawagner
The best way to learn the API, is to just use Metabase while having your browser developer network-tab open and looking at the request, and what data is being send/received.
As for visualization_settings, it’s a JSON object that can become a little complex depending on which visualization you’re using and which settings you’re changing.

Hi @flamber
The best way to learn the API, is to just use Metabase while having your browser developer network-tab open and looking at the request, and what data is being send/received.

I know, that's what I've been doing (copy request as curl adress (posix)), however, I cannot see any data related to graph settings. However, what I just figured is that I have to change "display": "table" to "display":"bar". That worked. Any tips on how I can select the columns which should be plotted?

@raphaelawagner Make all the changes you want to a visualization and the save, then you’ll see everything being sent in the request - including columns, colors, or whatever you have changed.

Yay! Thank you so much, I've got it working now!