C# retrieve calllogs example using client api

  • 1
  • Idea
  • Updated 16 hours ago
// Hope this helps someone I know I struggled with using the api initially.

// Import the Ring Central Client api into VS using nuget first.

using System;
using System.Linq;
using RingCentral;

namespace ringCentralLogs
{
    class Program
    {
        static void Main(string[] args)
        {
            Conn();
            Console.ReadLine();
        }

        static async void Conn()
        {
            try
            {

                RestClient rc = new RestClient("ClientId", "ClientSecret");

                // Authorize the user.
                await rc.Authorize("Sandbox User ID", "", "Password");
 
               // Get the main account.
                var account = rc.Restapi().Account();

               // Retrieve the call log records using some selection criteria.
                var callLogs = await account.CallLog().List(new { direction = "Outbound", type = "Fax", dateFrom = "2018-03-10T18:07:52.534Z"});

                Console.WriteLine("Print the call log");

                // Convert the callLogs.records to a list.
                var query = callLogs.records.ToList();

                // Iterate over the list printing properties.
                foreach (var result in query)
                {
                    Console.WriteLine("StartTime: {0}  To: {1}  Direction: {2}  Type: {3}  Result: {4}",result.startTime,result.to.phoneNumber, result.direction, result.type, result.result);
                }

                // Revoke the token.
                await rc.Revoke();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return;
        }
    }
}

Photo of Alan LaPenn

Alan LaPenn

  • 90 Points 75 badge 2x thumb

Posted 2 weeks ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,374 Points 5k badge 2x thumb
What is the issue? Did you encounter any errors? Could you please post more detail?
Photo of Alan LaPenn

Alan LaPenn

  • 90 Points 75 badge 2x thumb
No Issue at all it was working fine. However when calling async you must use thread.sleep or the app exits before the retrieval of the logs completes.
(Edited)
Photo of David Southern

David Southern

  • 70 Points
One question I have is this:  Is the array of objects returned from the call log a strongly typed list?  In other words, in this line here:

 var query = callLogs.records.ToList();

Is query a list<callLogRecord> or something of that nature?
Photo of Alan LaPenn

Alan LaPenn

  • 90 Points 75 badge 2x thumb
Yes, I it is a list of call log records and I iterate over the list using foreach (var result in query), where result is a single call log record. The properties of which are accessed using  dot notation., from my example code I use result.startTime to get the start time from the log record. all of the properties can be accessed this way. There are call log properties which are subordinate so the must be accessed by further dot notation like result.to.phoneNumber and result.to.name.

Hope this helps.
Photo of David Southern

David Southern

  • 70 Points
That sounds nice.  I was afraid the data would come back in raw json and I'd have to build poco classes to deserialize it to.  

Thanks!
Photo of John Wang

John Wang, Official Rep

  • 5,446 Points 5k badge 2x thumb
This SDK has model classes that are auto-generated from our OpenAPI / Swagger spec. It is built using "rc-codegen" project here:

https://github.com/tylerlong/rc-codegen