Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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"
      }
    ]
  }
}



  • Anonymous's avatar
    Anonymous
    6 years ago

    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.

8 Replies

  • 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/GetPowerBIActivityEvent.cs

    ...

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

    ...

  • Anonymous's avatar
    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's avatar
      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.

      • Anonymous's avatar
        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

  • 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);
    }