SOLVED

Re: Get Activities doesn't show Results

Go to solution
Anonymous
Not applicable

Get Activities doesn't show Results

Hi guys,

I'm trying to get Interesting Moments acitivities using the REST API. But the json response is not returning Results, can you guys help me please?

The activityType is 46, I have requested the types previously.

String url = host + "/rest/v1/activities.json?access_token=" + getToken() + "&activityTypeIds=" + activityType + "&nextPageToken=" + nextPageToken;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.Method = "GET";

request.ContentType = "application/json";

request.Accept = "application/json";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream resStream = response.GetResponseStream();

StreamReader reader = new StreamReader(resStream);

var result = reader.ReadToEnd();

And this is the response:

{"requestId":"271a#1632ca3a6a1","success":true,"nextPageToken":"4GAX7YNCIJKO2VAED5LH5PQIYO46Y4DV52DUUR5BJRFEATLBK2MA====","moreResult":true}

getToken()

private String getToken()

{

   String url = host + "/identity/oauth/token?grant_type=client_credentials&client_id=" + clientId + "&client_secret=" + clientSecret;

   String result = getData(url);

   Dictionary<String, String> dict = JsonConvert.DeserializeObject<Dictionary<String, String>>(result);

   return dict["access_token"];

}

nextPageToken

String pagingTokenObj = getPagingToken("2017-01-01T00:00:00-00:00");

private String getPagingToken(string sinceDatetime)

{

   String url = host + "/rest/v1/activities/pagingtoken.json?access_token=" + getToken() + "&sinceDatetime=" + sinceDatetime;

   String result = getData(url);

   return result;

}

getData()

private String getData(string url)

{

   String data = string.Empty;

try

{

   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

   request.Method = "GET";

   request.ContentType = "application/json";

   request.Accept = "application/json";

   HttpWebResponse response = (HttpWebResponse)request.GetResponse();

   Stream resStream = response.GetResponseStream();

   StreamReader reader = new StreamReader(resStream);

   var result = reader.ReadToEnd();

   if (response.StatusCode.ToString() == "OK")

   {

      data = result;

   }

   else

   {

      Console.WriteLine(response.StatusCode.ToString());

      data = "Status:" + response.StatusCode.ToString();

   }

}

catch (Exception ex)

{

   Console.WriteLine(ex.Message);

}

   return data;

}

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Get Activities doesn't show Results

Hi Sandford,

Thanks, I found out here (Get Lead Activities REST API is not returning any activities) that you must provide a close datestamp to get results. Since I put a very old date I didn't get any results. I changed it to this month and the 'result' came.

Thank you!

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Get Activities doesn't show Results

  1. Need to see the actual JSON you're putting on the wire, or at least the value of activityType and the response from your Describe Activities endpoint!
  2. moreResult:true and no data in the current page can occur even on the first grab, so you have to keep following the nextPageToken
Anonymous
Not applicable

Re: Get Activities doesn't show Results

Hi Sanford,

I have updated the post adding the calls. About your second point, if I'm evaluating the 'results' response and it doesn't exist, I will receive an error, so at least the 'results' response should appear as empty, right?

Regards,

Raul

SanfordWhiteman
Level 10 - Community Moderator

Re: Get Activities doesn't show Results

if I'm evaluating the 'results' response and it doesn't exist, I will receive an error, so at least the 'results' response should appear as empty, right?

You can't have your code be conditional only on the presence of the results property. It needs to check success and moreResult.

Anonymous
Not applicable

Re: Get Activities doesn't show Results

Hi Sandford,

Thanks, I found out here (Get Lead Activities REST API is not returning any activities) that you must provide a close datestamp to get results. Since I put a very old date I didn't get any results. I changed it to this month and the 'result' came.

Thank you!

SanfordWhiteman
Level 10 - Community Moderator

Re: Get Activities doesn't show Results

But your code can't depend the presence of results -- that's not how the API works. It's correctly telling you that there are more pages to come, even if the current page is empty, and you can't guarantee that won't happen even with a seemingly recent date.

I don't understand why you can't interpret the API response as documented?