Forum Discussion
Power BI Rest API continuation token is corrupted
- Anonymous6 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.
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);
}