question

keith-stephens avatar image
keith-stephens asked ·

C# get names and call count from call logs

I got a c# web app, which I am now getting call logs returned to me but how do I loop through the results and just get the name of the person who made the call and a count of how many calls they made.
Here is my code so far.

 rc = new RestClient(appKey, appSecret, isProduction);
            await rc.Authorize(userName, "", password);
            var mainAccount = rc.Restapi().Account();
            DateTime input = DateTime.Today;
            int delta = DayOfWeek.Monday - input.DayOfWeek;
            DateTime monday = input.AddDays(delta);
           
            var extension2 = rc.Restapi().Account().Extension();
            var callLogs = await mainAccount.CallLog().List(new { dateFrom = monday.ToString("yyyy-MM-dd") });
            string id = string.Empty;
            var query = callLogs.records.SelectMany(x => x.from.name)
                .GroupBy(s => s)
                .Select(g => new { Name = g.Key, Count = g.Count() });
            //var query = callLogs.records.SelectMany(x => x.id)
            //   .GroupBy(s => s)
            //   .Select(g => new { Name = g.Key, Count = g.Count() });
            foreach (var result in query)
            {
                Console.WriteLine("Name: {0}, Count: {1}", result.Name, result.Count);
            }

Thanks for helping,
Keith.

topic-default
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

· Write an Answer
Phong Vu avatar image
Phong Vu answered ·
Hi Keith,

The name will not be shown if the call is not from the same the account. See more from API reference.
Symbolic name associated with a party. If the phone does not belong to the known extension, only the  location is returned, the  name is not determined then.
If you want to get the name of a user, you have to call the company directory contact list and match the number with the number from the contact list to identify the name. To specify only users (extensions from your account) who made outgoing calls, you can shorten the call log result by set the direction to OutBound.

Hope this helps!
+ Phong
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.