How to Add a New Dataset to an Existing QuickSight Analysis Using API?

Hi everyone,

I’m facing an issue while adding a new dataset to an existing QuickSight analysis. I’m using the UpdateDataSet API, but I ran into the following error:

1 validation error detected: Value null at 'sourceEntity.sourceTemplate.dataSetReferences' failed to satisfy constraint: Member must not be null (Service: QuickSight, Status Code: 400, Request ID: b40cf9c7-2a95-44ff-98b8-afc82a99e116)
software.amazon.awssdk.services.quicksight.model.QuickSightException: 1 validation error detected: Value null at 'sourceEntity.sourceTemplate.dataSetReferences' failed to satisfy constraint:

I’m not sure if I’m on the right track. I aim
1 to add a new dataset to the existing analysis without overwriting the current setup.
2 to replace an old with a new dataset

Could someone guide me on how to achieve this properly, or is there a better approach I should be using?

Hi @maxim

Welcome to the community!

The error you’re encountering seems related to the dataSetReferences section in the sourceTemplate structure of the UpdateDataSet API call. This error suggests that a required reference to the dataset is missing or improperly configured, resulting in a failure.

To add a dataset to an existing analysis, you can use the UpdateAnalysis API to add a new dataset to an existing analysis. The UpdateAnalysis API allows you to update several aspects of an analysis, including adding datasets.

Steps to Add a Dataset to an Existing Analysis Using UpdateAnalysis API:

  1. Describe the Analysis: First, use the DescribeAnalysis API to get the current configuration of your analysis, including the list of datasets being used.
  2. Modify the DatasetArn: In the response from DescribeAnalysis, note the existing datasets in the SourceEntity.Arn field. When you call the UpdateAnalysis API, you need to pass both the existing datasets and the new dataset in the SourceEntity.Arn array to ensure you don’t overwrite the current datasets.
  3. Update the Analysis: Use the UpdateAnalysis API to add the new dataset. In the SourceEntity of the request, include the new dataset reference along with the existing ones.

Example UpdateAnalysis API Request:


{
    "AwsAccountId": "your-aws-account-id",
    "AnalysisId": "your-analysis-id",
    "Name": " Analysis Name",
    "SourceEntity": {
        "SourceTemplate": {
            "Arn": "arn:aws:quicksight:region:account-id:template/your-template-id",
            "DataSetReferences": [
                {
                    "DataSetArn": "arn:aws:quicksight:region:account-id:dataset/existing-dataset-id",
                    "DataSetPlaceholder": "ExistingDataSetPlaceholder"
                },
                {
                    "DataSetArn": "arn:aws:quicksight:region:account-id:dataset/new-dataset-id",
                    "DataSetPlaceholder": "NewDataSetPlaceholder"
                }
            ]
        }
    }
}


Please refer the below documentation this might be helpful for you.

1 Like

Thank you very much for your helpful response! I will certainly give the UpdateAnalysis API a try.

To provide more context, in our current workflow, I first export the data, then import it, and afterwards, I aim to update or replace datasets within the analysis. I don’t typically work with templates, so it was a bit confusing when I tried using the UpdateAnalysis API and was required to specify the template. Previously, I had only worked with the analysis, datasource and dataset and hadn’t configured templates, so it seems like an extra step just to update the datasets.

Additionally, there doesn’t seem to be an option to migrate the template smoothly. When updating the analysis after migration, specifying the template is mandatory, which feels a bit unusual for our use case. Could you clarify if there’s a specific reason for requiring the template when updating the analysis or if there’s a simpler approach we might be overlooking?

Hi @maxim

Apologies for the delayed response.

Templates as a base structure for analyses. A template defines the layout and configuration of an analysis (charts, fields, datasets, etc.), which allows for reusability across multiple analyses. When you are updating an analysis programmatically, QuickSight expects a reference to the template to ensure that the analysis remains consistent with its original design.

However, if you’re not explicitly using templates, the UpdateAnalysis API can still require you to reference the SourceTemplate when updating datasets. This is because the underlying structure of the analysis may still rely on a template behind the scenes, even if you don’t directly manage it.

For simpler updates (such as replacing or adding datasets), using the QuickSight UI can be the most straightforward approach. You can manually add new datasets to an analysis, replace existing datasets, or modify data sources without dealing with templates or API.

Can you please try the following approach

  • If you want to avoid dealing with templates programmatically, you can use the current analysis configuration as a “template” indirectly, without creating a new template from scratch.

  • Use the DescribeAnalysis API to extract the current configuration of your analysis, including all datasets already linked to it. This gives you the current structure of the analysis, including dataset references and layout, without needing to interact with templates.

  • When you call the UpdateAnalysis API, you can simply reuse the information from the DescribeAnalysis API and add the new dataset references. This effectively “skips” dealing with templates directly, since you’re just passing the existing structure back in.

1 Like

Thank you for your response. I wanted to clarify a few points regarding the process you mentioned about reusing the information from the DescribeAnalysis API.

When I call describeAnalysis, I receive a DescribeAnalysisResponse that contains an Analysis object. However, when I need to update the analysis using updateAnalysis, the workflow isn’t as straightforward as reusing this Analysis object and simply adding the new dataset references.

Specifically, when constructing an UpdateAnalysisRequest, I can’t directly pass the Analysis object from the DescribeAnalysisResponse. To update datasets, the UpdateAnalysisRequest requires a sourceEntity, which has a specific structure and mandatory parameters for overriding datasets. According to the documentation, I have to manually create the sourceEntity with the necessary datasetReferences (including ARNs and placeholders). Furthermore, there is no method in the DescribeAnalysisRequest that allows me to extract or reuse the sourceEntity from the Analysis object directly. As a result, I have to manually rebuild this part of the request when preparing the UpdateAnalysisRequest. UpdateAnalysisRequest.

It’s unclear what you mean by “simply reuse the information from the DescribeAnalysis API and add the new dataset references,” as there doesn’t appear to be a direct mechanism for reusing the existing structure without rebuilding parts of it. Could you clarify how this is meant to be achieved without dealing with templates? Could you clarify what part of the existing structure I should reuse or how I could bypass the need to reconstruct the sourceEntity for the UpdateAnalysisRequest? It feels like I’m still required to rebuild this portion of the request manually.

Hi @Xclipse ,

I hope you’re doing well. I wanted to follow up on my previous question regarding your last response. I’m still working through the issue and would really appreciate any further clarification or guidance you can provide.

Thank you in advance for your help!

Hi @maxim, I’m looking into this issue and testing on my system, this may take a few days. I will respond in a few days. In the meantime, I would also recommend filing a case with AWS Support where they can dive into the details so that they can help you further. Here are the steps to open a support case. If your company has someone who manages your AWS account, you might not have direct access to AWS Support and will need to raise an internal ticket to your IT team or whomever manages your AWS account. They should be able to open an AWS Support case on your behalf. Hope this helps!

2 Likes

Hi @Xclipse ,

I hope you’re doing well! I wanted to follow up regarding the issue I raised. I understand you mentioned that testing might take some time, so I was wondering if there are any updates you could share.

If there’s anything else I can do to help resolve this, please let me know. I appreciate your help and look forward to hearing from you.

Thank you again for your support!

1 Like

Hi @maxim,
It’s been awhile since last communication took place in this thread, did you have any remaining questions or were you able to find a work around for your case?

If we do not hear back within the next 3 business days, I’ll close out this topic.

Thank you!