Hi Team, I'm attempting to export a visualization ...
# gooddata-cloud
v
Hi Team, I'm attempting to export a visualization as a CSV via the API, using the following endpoint: GoodData API Tabular Export. I retrieved the execution result ID from the response of the following API endpoint:
<https://sustain360-dev.cloud.gooddata.com/api/v1/actions/workspaces/{workspace_id}/execution/afm/execute>
. The response includes the following "links" section:
Copy code
"links": {
     "executionResult": "bd0da5fe01cd7652a8978f82653279f0bb5ef29c:3193346d2e2b604ba8f4aee81b8cb0202a1e29894eeed4d3f515687149fa39e7"
}
I used
bd0da5fe01cd7652a8978f82653279f0bb5ef29c
as the execution result ID and attempted to hit the endpoint below (I also tried using
3193346d2e2b604ba8f4aee81b8cb0202a1e29894eeed4d3f515687149fa39e7
):
Copy code
curl $HOST_URL/api/v1/actions/workspaces/<workspace_id>/export/tabular \
-H 'Authorization: Bearer $API_TOKEN' \
-H 'Content-Type: application/json' \
-X POST \
-d '{
    "format": "<CSV|XLSX|PDF|HTML>",
    "fileName": "<tabular_export_file_name>",
    "<executionResult|visualizationObject>": "<execution_result_id|visualizationObjectId>"
}
'
However, I am receiving the following error response:
Copy code
{
  "detail": "Server-side problem. Contact support.",
  "status": 500,
  "title": "Internal Server Error",
  "traceId": "25ba5d80228dbb90fdef85a572fd3b46"
}
Could you please confirm if I am using the correct process?
m
Hi Vikraman, in our logs we see the error message “Result not found in result cache” (HTTP 404) which suggests that the execution result ID used for the export is no longer available or you have not put the correct execution result ID -Please try passing the entire string, not just one of the values:
"executionResult": "bd0da5fe01cd7652a8978f82653279f0bb5ef29c:3193346d2e2b604ba8f4aee81b8cb0202a1e29894eeed4d3f515687149fa39e7"
v
Hi @Michael Ullock and Team, I'm trying to export data in tabular format for a non-admin user. Based on your inputs I used the entire string as execution Result ID from afm/execute response, and I was able to export the visualization as csv. This worked fine only for the admin user, but it failed when I try to do the same for the non-admin user. I made sure that the user had workspace access and export permission. I'm attaching the error response
Copy code
{
  "detail": "Server-side problem. Contact support.",
  "status": 500,
  "title": "Internal Server Error",
  "traceId": "6d59dc1a381c40c7f9d9090aab6ebc4f"
}
Also, I have one more doubt as well. I'm attaching the screenshots of file exported as csv directly from UI and through export tabular data API Data exported through export tabular data API has the header information to be the db column name. Is it possible to modify this so that I get the same response as that of export csv?
m
Hi Vikraman, from our logs I see the following error:
Copy code
error message "Result not found in result cache" (HTTP 404
If the non-admin user gets a 404 Not Found error when exporting, it usually means: They don’t have the required permissions to access or export data, or the execution result ID is missing or expired. Can you please check the permissions once againf or his user and verify the have have the correct permissions set? Also, can you please verify that the execution results didn’t expire and run the
/execution/afm/execute
just before the export request to ensure the result is fresh. https://www.gooddata.com/docs/cloud/manage-organization/manage-permissions/set-permissions-for-workspace/#permissions-json-structure
Regarding the header details and the export tabular data via API - Unfortunately, this cannot be modified. You will need to modify the file manually after the export to display the same as the CSV file, etc
v
Hi Michael! I’ll look into it, thanks. I believe I can identify the issue. I tried generating the
resultId
for a non-admin user while using the admin user's token to create the data. But Is it scalable to have separate tokens for all users in the workspace to generate this tabular data? Additionally, I noticed that I can use visualization object IDs to generate tabular data. Is it possible to retrieve visualization object IDs for a specific dashboard? I know I can get all object IDs for a workspace, but having the ability to get them for a particular dashboard would be more convenient for my use case.
m
Yes, separate tokens for all users is the best approach. And you can retrieve visualization object for a specific dashboards using our API here: https://www.gooddata.com/docs/cloud/api-and-sdk/api/api_reference_all/#operation/getEntity@AnalyticalDashboards
v
Thanks, @Michael Ullock! That makes sense. So, what you're suggesting is that for each user, we need to generate access tokens either manually or via an API, store those tokens in the database, and use them to access the export tabular data. Is that correct? It would be great if there's an existing endpoint for generating token for a user—if so, could you share it? Also, if we are using visualization object IDs the report generated will be static without any filters I believe. Please correct me if I'm wrong.
Also @Michael Ullock! If I plan to rely on
afm/execute
and
executionResultId
for tabular data export, how should the payload for the
afm/execute
endpoint be structured? From what I've observed, it seems the payload includes local identifiers and column name references from the LDM, based on applied filters. If I'm manually calling the API, is there a way to retrieve the filters applied to the report displayed via the iframe and use them as the payload to obtain the
executionResultId
? Any guidance on this would be greatly appreciated.
m
Hi Vikraman, our apologies for the delay in getting back to you. The following is an example of how the payload should look like:
Copy code
{
  "executionResponse": {
    "dimensions": [
      {
        "headers": [
          {
            "attributeHeader": {
              "localIdentifier": "a_customer_created_date.month",
              "label": {
                "id": "customer_created_date.month",
                "type": "label"
              },
              "labelName": "Customer created date - Month/Year",
              "attribute": {
                "id": "customer_created_date.month",
                "type": "attribute"
              },
              "attributeName": "Customer created date - Month/Year",
              "granularity": "MONTH",
              "primaryLabel": {
                "id": "customer_created_date.month",
                "type": "label"
              },
              "format": {
                "locale": "zh-Hans",
                "pattern": "y年M月"
              },
              "valueType": "TEXT"
            }
          },
          {
            "attributeHeader": {
              "localIdentifier": "a_order_status",
              "label": {
                "id": "order_status",
                "type": "label"
              },
              "labelName": "Order status",
              "attribute": {
                "id": "order_status",
                "type": "attribute"
              },
              "attributeName": "Order status",
              "granularity": null,
              "primaryLabel": {
                "id": "order_status",
                "type": "label"
              },
              "valueType": "TEXT"
            }
          }
        ],
        "localIdentifier": "dim_0"
      },
      {
        "headers": [
          {
            "measureGroupHeaders": [
              {
                "localIdentifier": "m_runsum",
                "format": "#,##0.00",
                "name": "Runsum"
              }
            ]
          }
        ],
        "localIdentifier": "dim_1"
      }
    ],
    "links": {
      "executionResult": "ba3cc6f4296f4c2d39c2ec9ab2b92eace4e8e300:eef17355465eff27da56f04b1ad94ab43e5a0f1a62c3a0ba26deb4e2f3823114"
    }
  }
}
If you are still not fully accustomed with the structure, I recommend placing the insight you wish to export via the API in a dashboard and then grab the payload from the dev console. The whole structure is under the "execute" call. Regarding your second question, I am afraid I don't follow. The entire visualization definition include the filter applied to it when getting the executionResultId. I recommend going through the following documentation that explains the topic in detail: https://www.gooddata.com/docs/cloud/api-and-sdk/api/access_raw_data_through_api/