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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Power BI Rest API continuation token is corrupted

Hi,
When running the Get Activity Events API Call, it returns a few activities and a continuation token. When trying to use the token to contionue the call, i get the following error: 

 

{

  "error": {

    "code""InvalidRequest",

    "message""Looks like that continuation token is corrupted. Replace it with the same continuation token that was sent back in the previous API response, and try again"

  }
}

I get this error when i have single quotations around the token. if i do not have any quotations i get the following error:

{
  "error": {
    "code": "BadRequest",
    "message": "Bad Request",
    "details": [
      {
        "message": "Expected literal type token but found token 'LDIwMjAtMDQtMDZUMDA6MDA6MDEsMjAyMC0wNC0wNlQyMzo1OTo1OSwxLCw'.",
        "target": "continuationToken"
      }
    ]
  }
}



1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

Yes, yous should not use the continuationToken, but the continuationUri, and use it to make a new get request. 

The documentation for this API is poor and outdated, unfortunately.

Let me know if you need further assistance.

View solution in original post

7 REPLIES 7
allenwilson
New Member

For anyone who runs across this thread later on, I wanted to share a solution.  I never got this to work with the SDK - as I believe there is a bug in the way it escapes/handles the continuationToken.  But, to bypass the SDK and use the API directly was straightforward, and I was able to reuse my existing (Service Principal) Access Token, which was great. 

 

Below is a code example that works - I hope it helps someone else.

 


public static JObject GetActivityEvents(string startDateTime = default, string endDateTime = default, string continuationToken = default)
{
// Note: This function is necessary because of the bug in the SDK which causes use of the continuationToken to throw an error
// To work around this issue, the function was created to grab next records. Once SDK is fixed, this can be eliminated.

// Get HttpClient
var accessToken = AadService.GetAccessToken();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);

// Set Url
string serviceUrl = string.Concat(ConfigSettings.PbiServiceApiUri, "v1.0/myorg/admin/activityevents");
serviceUrl += (string.IsNullOrEmpty(continuationToken))
? string.Concat("?startDateTime=", startDateTime, "&endDateTime=", endDateTime, "&$filter=Activity eq 'viewreport'")
: string.Concat("?continuationToken='", continuationToken, "'");

// Get Response
HttpResponseMessage response = client.GetAsync(serviceUrl).Result;

//If Unsuccessful, raise exception
response.EnsureSuccessStatusCode();

// Return results
string content = response.Content.ReadAsStringAsync().Result;
return JObject.Parse(content);
}

maril
New Member

Hi,

I got the same error when building PowerAutomate Flow to retreive PBI activity events using custom connector based on Swagger https://github.com/microsoft/powerbi-rest-api-specs/blob/master/swagger.json

Turned out that the continuation token needs to be decoded for the 'Returns a list of audit activity events for a tenant' step to work properly.

In MS Flow - Parse the continuation token from Json, then decode with function decodeUriComponent() and finally wrap the expression in single quotes. 

eg. 'decodeUriComponent(body('Parse_JSON')?['continuationToken'])'

 

PowerShell does it behind the scene like this:

https://github.com/microsoft/powerbi-powershell/blob/master/src/Modules/Admin/Commands.Admin/GetPowe...

...

 string formattedContinuationToken = $"'{WebUtility.UrlDecode(response.ContinuationToken)}'";
response = client.Admin.GetPowerBIActivityEvents(null, null, formattedContinuationToken, null);

...

Anonymous
Not applicable

Hi,

 

Did you manage to get this fixed?

I have tried using the token but keep getting the same errors as you. I have put single quotes around the token, double quotes as well.

 

Cheers,

liljath

Anonymous
Not applicable

Hi @Anonymous 

Yes, yous should not use the continuationToken, but the continuationUri, and use it to make a new get request. 

The documentation for this API is poor and outdated, unfortunately.

Let me know if you need further assistance.

Hi.

 

I'm having the same issue with the SDK and have been unable to figure out how to use the continuationUri that you mentioned with the SDK.   The SDK works quite well for all of the various pieces of data that I am consuming, and it even works fine for activities too provided I ignore the continuation token.  Every attempt to use that so far has failed.

 

Do you have an example of using the continuationUri with the SDK specifically?

Anonymous
Not applicable

Hi @Anonymous ,

 

Thank you for this 🙂 it's been driving me crazy lol

Do you know if it possible to use the powerbiclient from the package Microsoft.PowerBI.Api?

I am using pbiClient.Admin.GetActivityEvents(startdate, enddate) to get the first call but when I put the continuationtoken in there it just doesn't work.

I was thinking maybe something like powerbiclient.httpclient ... but have tried this with a 403 result.

Do you call the api with this client or a normal httpclient?

 

cheers,

liljath

Anonymous
Not applicable

Hi @Anonymous 

 

I am currently using Power Automate to pull the data one a day. You can read more about the general idea here:
https://medium.com/@Konstantinos_Ioannou/refresh-powerbi-dataset-with-microsoft-flow-73836c727c33
It is an old article showing you how to refresh a dataset uding Power Automate (this article is from before it was possible with a simple connector)

If you are using Powershell you can use the PBI Cmdlets (read more here). Once that is installed you can run requests from Powershell. Here is an example, where the logs are saved in .json files for each individual day:

Login-PowerBI
$date = [datetime]'07/10/2020'

$array =
do {
$date.ToString('yyyy-MM-dd')
$date2 =(Get-Date $date -Format 'yyyy-MM-dd')
$begindate=-join($date2,'T00:00:00')
$enddate =-join($date2,'T23:59:59')
$paths =-join('C:\audit\',$date2,'.json')
$activities = Get-PowerBIActivityEvent -StartDateTime $begindate -EndDateTime $enddate | Out-File $paths
$date = $date.AddDays(1)
}

until ($date -gt [datetime]'07/14/2020')

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.