Skip to content

Unable to Generate a Filtered Screenshots of Dashboard Charts #32037

Closed

Description

@juliacebria

Discussed in #32036

Originally posted by juliacebria January 30, 2025
I have a dashboard with multiple charts, each showing data for different counties. I need to generate a PDF for each county with the relevant filtered data.

If generating a filtered PDF is not possible, I want to capture a screenshot of each chart individually with the county filter applied. However, when using GET /api/v1/chart/{pk}/cache_screenshot/, the API does not allow filtering.

Is there a way to pass filters when generating a screenshot via API, or an alternative method to schedule or generate a filtered PDF of the dashboard?

Activity

  1. added
    alert-reportsNamespace | Anything related to the Alert & Reports feature
    on Jan 30, 2025
  2. dosubot commented on Jan 30, 2025

    @dosubot

    Hello @juliacebria! I'm here to help you with any bugs, questions, or contributions you have.

    There is a way to pass filters when generating a screenshot via the API in Apache Superset. You can use the DownloadScreenshot component, which utilizes the dataMask from the Redux state to include the current filter state of the dashboard. This dataMask is part of the jsonPayload in the POST request to the /api/v1/dashboard/${dashboardId}/cache_dashboard_screenshot/ endpoint, ensuring that the screenshot reflects the current filters applied to the dashboard [1].

    Additionally, you can generate a PDF of the dashboard with the applied filters. The process involves caching the screenshot and then retrieving it in PDF format using functions like cache_dashboard_screenshot and build_pdf_from_screenshots, which ensure that the PDF reflects the current state of the dashboard, including any filters [2].

    To continue talking to Dosu, mention @dosu.


    Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

  3. dosubot commented on Jan 30, 2025

    @dosubot

    A 404 Not Found response when accessing the /api/v1/dashboard/{dashboard_id}/cache_dashboard_screenshot/ endpoint can occur for several reasons:

    1. Dashboard Not Found: Ensure that the dashboard_id (in your case, 2) corresponds to an existing dashboard. If the dashboard does not exist, a 404 response will be returned [1].

    2. Feature Flags Disabled: The endpoint requires the THUMBNAILS and ENABLE_DASHBOARD_SCREENSHOT_ENDPOINTS feature flags to be enabled. If either of these flags is disabled, the endpoint will return a 404 response [1].

    3. Incorrect Payload Structure: The payload structure you are using seems incorrect. The expected payload should be a JSON object with the following structure:

      {
          "dataMask": {},
          "activeTabs": [],
          "anchor": "",
          "urlParams": []
      }

      Ensure that your payload matches this structure. The dataMask should be directly within the main JSON object, not nested under jsonPayload [1][2].

    Please verify these aspects to resolve the 404 error.

    To continue talking to Dosu, mention @dosu.


    Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

  4. juliacebria commented on Jan 30, 2025

    @juliacebria
    Author

    Thank you! That worked and now I get Status Code: 202 and the cache_key.

    No obstant, I'm encountering a 404 Not Found error when trying to retrieve a cached screenshot using the following API endpoint:

    GET http://localhost:8088/api/v1/dashboard/2/screenshot/{cache_key}/

    The cache_key I received from a previous API call is bed09521aa9f663df42b625577cff7b5. I correctly replace {cache_key} with the actual value, but I still get the 404 Not Found error, with the following response:

    {
    "message": "Not found"
    }

  5. dosubot commented on Jan 30, 2025

    @dosubot

    A 404 Not Found error when trying to retrieve a cached screenshot using the cache_key can occur for a couple of reasons:

    1. Dashboard Does Not Exist: Ensure that the dashboard with the specified ID (in your case, 2) actually exists. If the dashboard does not exist, a 404 response will be returned.

    2. Screenshot Not in Cache: Even if the dashboard exists, the screenshot might not be available in the cache. The cache might not have been set correctly, or it might have expired or been cleared.

    Make sure that the cache_key is valid and that the cache is properly configured and operational. If the cache key was set with a timeout, it might have expired, leading to the screenshot not being found in the cache [1].

    To continue talking to Dosu, mention @dosu.


    Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

  6. juliacebria commented on Jan 30, 2025

    @juliacebria
    Author

    @dosu
    I am able to successfully post to the cache dashboard screenshot API endpoint (/api/v1/dashboard/2/cache_dashboard_screenshot/) and receive a 202 Accepted status with a valid cache_key in the response.

    However, when I try to fetch the screenshot using the generated cache_key with the following endpoint:

    GET http://localhost:8088/api/v1/dashboard/2/screenshot/{cache_key}/
    

    I get a 404 Not Found error with the response message "Not found", even though the dashboard exists and the cache key seems correct.

  7. grc-harsh-agarwal commented on Jul 24, 2025

    @grc-harsh-agarwal
  8. dosubot commented on Jul 24, 2025

    @dosubot

    A 404 when retrieving a dashboard screenshot with a cache key usually means the screenshot isn't available in the cache yet. This can happen if the async screenshot task hasn't finished, if the cache is misconfigured, or if there was an error during screenshot generation. Here’s what you can check:

    1. Wait a few seconds after POSTing to /cache_dashboard_screenshot/ before trying the GET, since screenshot generation is async and handled by Celery.
    2. Check your Superset and Celery logs for errors or warnings related to screenshot generation or caching—look for issues with WebDriver, cache backend, or task failures.
    3. Make sure both the THUMBNAILS and ENABLE_DASHBOARD_SCREENSHOT_ENDPOINTS feature flags are enabled, and that your THUMBNAIL_CACHE_CONFIG is set to a real cache backend (like Redis or Memcached), not NullCache.
    4. Confirm your cache timeout and error TTL settings are reasonable, so screenshots don’t expire before you fetch them.
    5. Double-check that your cache key parameters (dashboard state, window size, thumb size, permalink key) match between POST and GET requests—any mismatch can cause a cache miss and a 404.

    If the cache is not set or misconfigured, screenshot generation will be skipped and retrieval will always fail with a 404. If there’s a WebDriver or screenshot error, the cache payload will be in ERROR status and not retrievable until the error TTL expires. All of this is by design in the Superset screenshot API logic (source, source, source).

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about superset with Dosu Add Dosu to your team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    alert-reportsNamespace | Anything related to the Alert & Reports feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions