Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
KristinePowerBI
New Member

API SDK: Passing a Parameter with dropdown values specified by a query for a Paginated Report

Hello All,

I am properly stumped and would be overjoyed if someone could help me solve this puzzle or let me know if it is not supported currently in the api. Was not able to find too much about this is the documentation or prior posts.

 

Developer Tool: Power BI API SDK v4.16

Error Message: RootActivityId(2ac22f10-46b4-4e15-bfed-330412c421c3): Some parameters do not have valid values. Values provided for participantId that are not valid include a939e322-9134-48ad-ae96-afa4017322e5."

 

Repro Steps:

  1. Set up Parameter Dropdown to use query. This query uses a string value for the Vaue and Key. The value is eventually changed to a UNIQUEIDENTIFIER but I have tried using just strings/different data types with the same resulKristinePowerBI_0-1703013060837.png
  2. Run report within report builder using default value (A939E322-9134-48AD-AE96-AFA4017322E5) for sake of example. Notice it  completes successfully
  3.  Run the report using the api
  4. Receive the following error:
    1. {"code":"rsParametersNotSpecified","message":"RootActivityId(2ac22f10-46b4-4e15-bfed-330412c421c3): Some parameters do not have valid values. Values provided for participantId that are not valid include a939e322-9134-48ad-ae96-afa4017322e5.","details":[]},"percentComplete":0,"expirationTime":"0001-01-01T00:00:00Z"}
  5. Change the Parameter so that it is free text (just change radio to none in screenshot above)
  6. Run the report using the exact same code
  7. Report completes successfully

I've sanity checked the following

  1. the value I am passing for the parameter exists in the drop down
  2. Behavior is the same whether multiselect or single select
  3. Behavior is the same whether allowing or not allowing null values

I've spent more time than I care to admit on this and was wondering if anyone has solved something similar in the past?


Relevant Code :

 

 

 

 async Task<Document> ExportPowerBIPaginatedReport(PowerBIReport powerBIReport)
        {
            var exportId = await PostExportRequest(powerBIReport.WorkspaceId.Value, powerBIReport.ExternalReportId.Value, powerBIReport.TenantId);
            var export = await PollExportRequest(powerBIReport.ExternalReportId.Value, powerBIReport.WorkspaceId.Value, exportId);
            var exportedFile = await GetExportedFile(powerBIReport.ExternalReportId.Value, powerBIReport.WorkspaceId.Value, export);

            //save to temp for now, eventually would just return and save to documents like in SSRSReportManager
            using (FileStream fileStream = new FileStream("C:\\temp\\tester.pdf", FileMode.Create, FileAccess.Write))
            {
                // Write the bytes to the file
                fileStream.Write(exportedFile.Content, 0, exportedFile.Content.Length);
            }

            return exportedFile;
        }

        private async Task<string> PostExportRequest(Guid groupId, Guid reportId, Guid tenantId)
        {

            using (var client = await GetPowerBiClient())
            {
                var testGuid = new Guid("A939E322-9134-48AD-AE96-AFA4017322E5");
                var paginatedReportExportConfiguration = new PaginatedReportExportConfiguration()
                {
               
                    ParameterValues = new List<ParameterValue>()
                    {
                        { new ParameterValue() {Name = "tenantId", Value = tenantId.ToString() } },
                       
                        { new ParameterValue() {Name = "participantId", Value = testGuid.ToString() } },
                        { new ParameterValue() {Name = "asOfDate", Value = DateTime.Now.ToString() } },
                    },
                };

                var exportRequest = new ExportReportRequest
                {
                    Format = FileFormat.PDF,
                    PaginatedReportConfiguration = paginatedReportExportConfiguration,
                };

                var export = await client.Reports.ExportToFileInGroupAsync(groupId, reportId, exportRequest);

                // Save the export ID, you'll need it for polling and getting the exported file
                return export.Id;
            }
           
        }

        private async Task<Export> PollExportRequest(Guid reportId, Guid groupId, string exportId)
        {
            using (var client = await GetPowerBiClient())
            {
                Export exportStatus = null;
                DateTime startTime = DateTime.UtcNow;
                const int secToMillisec = 1000;
                HttpOperationResponse<Export> httpMessage;
                do
                {
                    //eventually we'd want to set a timeout here and potentially the ability to cancel
                    /*if (DateTime.UtcNow.Subtract(startTime).TotalMinutes > timeOutInMinutes || token.IsCancellationRequested)
                    {
                        // Error handling for timeout and cancellations
                        return null;
                    }*/

                    httpMessage = await client.Reports.GetExportToFileStatusInGroupWithHttpMessagesAsync(groupId, reportId, exportId);

                    exportStatus = httpMessage.Body;
                    if (exportStatus.Status == ExportState.Running || exportStatus.Status == ExportState.NotStarted)
                    {
                        // The recommended waiting time between polling requests can be found in the RetryAfter header
                        // Note that this header is only populated when the status is either Running or NotStarted
                        var retryAfter = httpMessage.Response.Headers.RetryAfter;
                        var retryAfterInSec = retryAfter.Delta.Value.Seconds;

                        await Task.Delay(retryAfterInSec * secToMillisec);
                    }
                }
                // While not in a terminal state, keep polling
                while (exportStatus.Status != ExportState.Succeeded && exportStatus.Status != ExportState.Failed);

                if (exportStatus.Status == ExportState.Failed)
                {
                    // Error handling for failure, set the failure message of the report history
                    var content = httpMessage.Response.Content;
                    var error = await content.ReadAsStringAsync();
                    var test = httpMessage.Response;
                    //pause here to see error message
                }

                return exportStatus;

            }
        }

        private async Task<Document> GetExportedFile(Guid reportId, Guid groupId, Export export)
        {
            using (var client = await GetPowerBiClient())
            {
                if (export.Status == ExportState.Succeeded)
                {
                    byte[] content;
                    var httpMessage =
                        await client.Reports.GetFileOfExportToFileInGroupWithHttpMessagesAsync(groupId, reportId, export.Id);

                   
                    using (MemoryStream newMemoryStream = new MemoryStream())
                    {
                        httpMessage.Body.CopyTo(newMemoryStream);
                        content = newMemoryStream.ToArray();
                    }

                    return new Document
                    {
                        Content = content,
                        Name = export.ReportName,
                        FileType = export.ResourceFileExtension,
                    };
                }

                return null;
            }
        }

 

 

 

 

0 REPLIES 0

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.