Get Activities doesn't show Results | Community
Skip to main content
May 4, 2018
Solved

Get Activities doesn't show Results

  • May 4, 2018
  • 1 reply
  • 3248 views

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;

}

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by

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.


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!

1 reply

SanfordWhiteman
New Participant
May 4, 2018
  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
May 4, 2018

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
New Participant
May 4, 2018

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.