GitHub user Ruchitha598 created a discussion: Unable to Retrieve the query_context Through API After Chart Creation Without Loading Chart in UI?
Hi team, I’m working with the Superset REST API and facing an issue where the query_context is not available immediately after creating a chart via the API. Here's a step-by-step breakdown of my use case: Chart Creation I created a chart using the following API call: curl -X POST 'http://10.0.11.179:8089/api/v1/chart/' \ --header 'Authorization: Bearer <ACCESS_TOKEN>' \ --header 'Content-Type: application/json' \ --header 'x-csrftoken: <CSRF_TOKEN>' \ --header 'Cookie: session=<SESSION>' \ --data '{ "datasource_id": 1, "datasource_type": "table", "viz_type": "echarts_timeseries_bar", "slice_name": "Campaign_Bar_Chart_07", "params": "{\"viz_type\":\"echarts_timeseries_bar\",\"groupby\":[\"PROMOTION_DATE\"],\"metrics\":{\"expressionType\":\"SIMPLE\",\"column\":{\"column_name\":\"PUSHED_COUNT\"},\"aggregate\":\"SUM\",\"label\":\"SUM OF PUSHED COUNT\"},\"adhoc_filters\":[{\"expressionType\":\"SIMPLE\",\"subject\":\"PROMOTION_DATE\",\"operator\":\"==\",\"comparator\":\"2025-03-01\",\"clause\":\"WHERE\"}],\"show_legend\":true,\"show_labels\":true,\"color_scheme\":\"supersetColors\",\"time_range\":\"No filter\",\"x_axis_format\":\"%Y-%m-%d\",\"y_axis_format\":\",0f\",\"y_axis_label\":\"SUM OF PUSHED COUNT\",\"x_axis\":\"CAMPAIGN_NAME\"}" }' Response: {"id":629,"result":{"datasource_id":1,"datasource_type":"table","params":"{\"viz_type\":\"echarts_timeseries_bar\",\"groupby\":[\"PROMOTION_DATE\"],\"metrics\":{\"expressionType\":\"SIMPLE\",\"column\":{\"column_name\":\"PUSHED_COUNT\"},\"aggregate\":\"SUM\",\"label\":\"SUM OF PUSHED COUNT\"},\"adhoc_filters\":[{\"expressionType\":\"SIMPLE\",\"subject\":\"PROMOTION_DATE\",\"operator\":\"==\",\"comparator\":\"2025-03-01\",\"clause\":\"WHERE\"}],\"show_legend\":true,\"show_labels\":true,\"color_scheme\":\"supersetColors\",\"time_range\":\"No filter\",\"x_axis_format\":\"%Y-%m-%d\",\"y_axis_format\":\",0f\",\"y_axis_label\":\"SUM OF PUSHED COUNT\",\"x_axis\":\"CAMPAIGN_NAME\"}","slice_name":"Campaign_Bar_Chart_07 ","viz_type":"echarts_timeseries_bar"}} Issue: query_context is null Immediately after creating the chart, I try to retrieve the chart details via: curl -X GET 'http://10.0.11.179:8089/api/v1/explore/?form_data={"slice_id":629}' \ -H 'Authorization: Bearer <ACCESS_TOKEN>' But the response has query_context as null: { "result": { "dataset": { "always_filter_main_dttm": false, "cache_timeout": null, "catalog": null, "column_formats": {}, "columns": [ { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "PROMOTION_DATE", "description": "The date when the campaign was launched or when a specific transaction took place within the campaign. This could be the date the messages were sent or the campaign officially started.", "expression": null, "filterable": true, "groupby": true, "id": 1, "is_certified": false, "is_dttm": true, "python_date_format": null, "type": "DATE", "type_generic": 2, "verbose_name": "Transaction Date", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "YEAR", "description": "This extracts the year from the Transaction Date.", "expression": null, "filterable": true, "groupby": true, "id": 2, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "BIGINT", "type_generic": 0, "verbose_name": "Year", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "QUARTER", "description": "A quarter is a three month period in a calendar year", "expression": null, "filterable": true, "groupby": true, "id": 3, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "VARCHAR", "type_generic": 1, "verbose_name": "Quarter", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "MONTH", "description": "This extracts the month name from the Transaction Date. example February,March,etc", "expression": null, "filterable": true, "groupby": true, "id": 4, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "VARCHAR", "type_generic": 1, "verbose_name": "Month", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "CAMPAIGN_NAME", "description": "The specific name or title of the campaign associated with the transaction. It serves as an identifier for the campaign within the system", "expression": null, "filterable": true, "groupby": true, "id": 5, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "VARCHAR", "type_generic": 1, "verbose_name": "Campaign Name", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "SEGMENT_NAME", "description": "The unique name or identifier given to a specific segment within the campaign. A segment could refer to a targeted group of recipients based on certain characteristics or demographics.", "expression": null, "filterable": true, "groupby": true, "id": 6, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "VARCHAR", "type_generic": 1, "verbose_name": "Segment Name", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "PUSHED_COUNT", "description": "The total number of messages that were submitted or 'pushed' out as part of the campaign, regardless of whether they were successfully delivered. It shows the number of messages that were attempted to be sent.", "expression": null, "filterable": true, "groupby": true, "id": 7, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "BIGINT", "type_generic": 0, "verbose_name": "Submitted Messages", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "DEL_COUNT", "description": "The total number of messages successfully delivered to recipients as part of the campaign. This figure represents the actual successful deliveries out of the submitted messages.", "expression": null, "filterable": true, "groupby": true, "id": 8, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "BIGINT", "type_generic": 0, "verbose_name": "Delivered Messages", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "DEL_PERCENTAGE", "description": "The percentage of messages successfully delivered in relation to the total number of messages submitted for the campaign. This metric shows how effective the campaign's message", "expression": null, "filterable": true, "groupby": true, "id": 9, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "DECIMAL", "type_generic": 0, "verbose_name": "Delivery Success Rate", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "CHANNEL", "description": "The medium or platform through which the campaign's messages or transactions are delivered. Examples include SMS, email, push notifications, or social media.", "expression": null, "filterable": true, "groupby": true, "id": 10, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "VARCHAR", "type_generic": 1, "verbose_name": "Communication Platform", "warning_markdown": null }, { "advanced_data_type": null, "certification_details": null, "certified_by": null, "column_name": "LANGUAGE", "description": "The language in which the campaign transaction is conducted. This field indicates the primary language used for communication in the campaign (e.g., English, Spanish, etc.).", "expression": null, "filterable": true, "groupby": true, "id": 11, "is_certified": false, "is_dttm": false, "python_date_format": null, "type": "VARCHAR", "type_generic": 1, "verbose_name": "Communication Language", "warning_markdown": null } ], "currency_formats": {}, "database": { "allow_multi_catalog": false, "allows_cost_estimate": false, "allows_subquery": true, "allows_virtual_table_explore": true, "backend": "dremio", "configuration_method": "sqlalchemy_form", "disable_data_preview": false, "disable_drill_to_detail": false, "engine_information": { "disable_ssh_tunneling": false, "supports_dynamic_catalog": false, "supports_file_upload": true }, "explore_database_id": 1, "id": 1, "name": "Dremio", "parameters": {}, "parameters_schema": {}, "schema_options": {} }, "datasource_name": "CTD_COMMON", "default_endpoint": null, "description": "This table contains details about the different aspects of a campaign transaction, including the language, platform, message delivery statistics, and campaign-specific identifiers like segment and campaign names. It tracks the success of message deliveries and submissions, offering insights into campaign performance and effectiveness.", "edit_url": "/tablemodelview/edit/1", "extra": null, "fetch_values_predicate": null, "filter_select": true, "filter_select_enabled": true, "granularity_sqla": [ [ "PROMOTION_DATE", "PROMOTION_DATE" ] ], "health_check_message": null, "id": 1, "is_sqllab_view": false, "main_dttm_col": "PROMOTION_DATE", "metrics": [ { "certification_details": null, "certified_by": null, "currency": null, "d3format": null, "description": null, "expression": "COUNT(*)", "id": 1, "is_certified": false, "metric_name": "count", "verbose_name": "COUNT(*)", "warning_markdown": "", "warning_text": null } ], "name": "demo.CTD_COMMON", "normalize_columns": false, "offset": 0, "order_by_choices": [ [ "[\"CAMPAIGN_NAME\", true]", "CAMPAIGN_NAME [asc]" ], [ "[\"CAMPAIGN_NAME\", false]", "CAMPAIGN_NAME [desc]" ], [ "[\"CHANNEL\", true]", "CHANNEL [asc]" ], [ "[\"CHANNEL\", false]", "CHANNEL [desc]" ], [ "[\"DEL_COUNT\", true]", "DEL_COUNT [asc]" ], [ "[\"DEL_COUNT\", false]", "DEL_COUNT [desc]" ], [ "[\"DEL_PERCENTAGE\", true]", "DEL_PERCENTAGE [asc]" ], [ "[\"DEL_PERCENTAGE\", false]", "DEL_PERCENTAGE [desc]" ], [ "[\"LANGUAGE\", true]", "LANGUAGE [asc]" ], [ "[\"LANGUAGE\", false]", "LANGUAGE [desc]" ], [ "[\"MONTH\", true]", "MONTH [asc]" ], [ "[\"MONTH\", false]", "MONTH [desc]" ], [ "[\"PROMOTION_DATE\", true]", "PROMOTION_DATE [asc]" ], [ "[\"PROMOTION_DATE\", false]", "PROMOTION_DATE [desc]" ], [ "[\"PUSHED_COUNT\", true]", "PUSHED_COUNT [asc]" ], [ "[\"PUSHED_COUNT\", false]", "PUSHED_COUNT [desc]" ], [ "[\"QUARTER\", true]", "QUARTER [asc]" ], [ "[\"QUARTER\", false]", "QUARTER [desc]" ], [ "[\"SEGMENT_NAME\", true]", "SEGMENT_NAME [asc]" ], [ "[\"SEGMENT_NAME\", false]", "SEGMENT_NAME [desc]" ], [ "[\"YEAR\", true]", "YEAR [asc]" ], [ "[\"YEAR\", false]", "YEAR [desc]" ] ], "owners": [ { "first_name": "admin", "id": 1, "last_name": "admin", "username": "admin" } ], "params": null, "perm": "[Dremio].[CTD_COMMON](id:1)", "schema": "demo", "select_star": "SELECT *\nFROM demo.\"CTD_COMMON\"\nLIMIT 100", "sql": "", "table_name": "CTD_COMMON", "template_params": null, "time_grain_sqla": [ [ "PT1S", "Second" ], [ "PT1M", "Minute" ], [ "PT1H", "Hour" ], [ "P1D", "Day" ], [ "P1W", "Week" ], [ "P1M", "Month" ], [ "P3M", "Quarter" ], [ "P1Y", "Year" ] ], "type": "table", "uid": "1__table", "verbose_map": { "CAMPAIGN_NAME": "Campaign Name", "CHANNEL": "Communication Platform", "DEL_COUNT": "Delivered Messages", "DEL_PERCENTAGE": "Delivery Success Rate", "LANGUAGE": "Communication Language", "MONTH": "Month", "PROMOTION_DATE": "Transaction Date", "PUSHED_COUNT": "Submitted Messages", "QUARTER": "Quarter", "SEGMENT_NAME": "Segment Name", "YEAR": "Year", "__timestamp": "Time", "count": "COUNT(*)" } }, "form_data": { "adhoc_filters": [ { "clause": "WHERE", "comparator": "2025-03-01", "expressionType": "SIMPLE", "operator": "==", "subject": "PROMOTION_DATE" } ], "applied_time_extras": {}, "color_scheme": "supersetColors", "datasource": "1__table", "groupby": [ "PROMOTION_DATE" ], "metrics": { "aggregate": "SUM", "column": { "column_name": "PUSHED_COUNT" }, "expressionType": "SIMPLE", "label": "SUM OF PUSHED COUNT" }, "show_labels": true, "show_legend": true, "slice_id": 629, "time_range": "No filter", "url_params": {}, "viz_type": "echarts_timeseries_bar", "x_axis": "CAMPAIGN_NAME", "x_axis_format": "%Y-%m-%d", "y_axis_format": ",0f", "y_axis_label": "SUM OF PUSHED COUNT" }, "message": null, "metadata": { "changed_by": "admin admin", "changed_on_humanized": "a minute ago", "created_by": "admin admin", "created_on_humanized": "a minute ago", "dashboards": [], "owners": [ "admin admin" ] }, "slice": { "cache_timeout": null, "certification_details": null, "certified_by": null, "changed_on": "2025-08-19T12:53:48.678661", "changed_on_humanized": "a minute ago", "datasource": "demo.CTD_COMMON", "description": null, "description_markeddown": "", "edit_url": "/chart/edit/629", "form_data": { "adhoc_filters": [ { "clause": "WHERE", "comparator": "2025-03-01", "expressionType": "SIMPLE", "operator": "==", "subject": "PROMOTION_DATE" } ], "color_scheme": "supersetColors", "datasource": "1__table", "groupby": [ "PROMOTION_DATE" ], "metrics": { "aggregate": "SUM", "column": { "column_name": "PUSHED_COUNT" }, "expressionType": "SIMPLE", "label": "SUM OF PUSHED COUNT" }, "show_labels": true, "show_legend": true, "slice_id": 629, "time_range": "No filter", "viz_type": "echarts_timeseries_bar", "x_axis": "CAMPAIGN_NAME", "x_axis_format": "%Y-%m-%d", "y_axis_format": ",0f", "y_axis_label": "SUM OF PUSHED COUNT" }, "is_managed_externally": false, "modified": "<span class=\"no-wrap\">a minute ago</span>", "owners": [ 1 ], "query_context": null, "slice_id": 629, "slice_name": "Campaign_Bar_Chart_07 ", "slice_url": "/explore/?slice_id=629&form_data=%7B%22slice_id%22%3A%20629%7D" } } } But query_context is Populated After Opening the Chart in the UI If I manually open the chart in the Superset web UI, and then call the same /explore/ API, the query_context is correctly populated in the response. "query_context": "{\"datasource\":{\"id\":1,\"type\":\"table\"},\"force\":false,\"queries\":[{\"time_range\":\"No filter\",\"filters\":[{\"col\":\"PROMOTION_DATE\",\"op\":\"==\",\"val\":\"2025-03-01\"}],\"extras\":{\"having\":\"\",\"where\":\"\"},\"applied_time_extras\":{},\"columns\":[{\"columnType\":\"BASE_AXIS\",\"sqlExpression\":\"CAMPAIGN_NAME\",\"label\":\"CAMPAIGN_NAME\",\"expressionType\":\"SQL\"},\"PROMOTION_DATE\"],\"metrics\":[{\"aggregate\":\"SUM\",\"column\":{\"column_name\":\"PUSHED_COUNT\"},\"expressionType\":\"SIMPLE\",\"label\":\"SUM OF PUSHED COUNT\"}],\"orderby\":[[{\"aggregate\":\"SUM\",\"column\":{\"column_name\":\"PUSHED_COUNT\"},\"expressionType\":\"SIMPLE\",\"label\":\"SUM OF PUSHED COUNT\"},false]],\"annotation_layers\":[],\"series_columns\":[\"PROMOTION_DATE\"],\"series_limit\":0,\"order_desc\":true,\"url_params\":{},\"custom_params\":{},\"custom_form_data\":{},\"time_offsets\":[],\"post_processing\":[{\"operation\":\"pivot\",\"options\":{\"index\":[\"CAMPAI GN_NAME\"],\"columns\":[\"PROMOTION_DATE\"],\"aggregates\":{\"SUM OF PUSHED COUNT\":{\"operator\":\"mean\"}},\"drop_missing_columns\":true}},{\"operation\":\"flatten\"}]}],\"form_data\":{\"adhoc_filters\":[{\"clause\":\"WHERE\",\"comparator\":\"2025-03-01\",\"expressionType\":\"SIMPLE\",\"operator\":\"==\",\"subject\":\"PROMOTION_DATE\"}],\"color_scheme\":\"supersetColors\",\"datasource\":\"1__table\",\"groupby\":[\"PROMOTION_DATE\"],\"metrics\":{\"aggregate\":\"SUM\",\"column\":{\"column_name\":\"PUSHED_COUNT\"},\"expressionType\":\"SIMPLE\",\"label\":\"SUM OF PUSHED COUNT\"},\"show_labels\":true,\"show_legend\":true,\"slice_id\":629,\"time_range\":\"No filter\",\"viz_type\":\"echarts_timeseries_bar\",\"x_axis\":\"CAMPAIGN_NAME\",\"x_axis_format\":\"%Y-%m-%d\",\"y_axis_format\":\",0f\",\"y_axis_label\":\"SUM OF PUSHED COUNT\",\"force\":false,\"result_format\":\"json\",\"result_type\":\"full\"},\"result_format\":\"json\",\"result_type\":\"full\"}" My Question Is there a way to programmatically generate or retrieve the query_context via an API endpoint or backend method without: - Opening the chart manually in the Superset UI - Triggering the frontend rendering Essentially, I want to fully automate chart creation and subsequent data fetching via the API (including the query_context), without requiring any frontend interaction. Environment Details -Superset version: 4.1.2 Any guidance, suggestions, or workarounds would be appreciated. Thanks in advance! GitHub link: https://github.com/apache/superset/discussions/34750 ---- This is an automatically sent email for notifications@superset.apache.org. To unsubscribe, please send an email to: notifications-unsubscr...@superset.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org