Idea

alan-lapenn11149 avatar image
alan-lapenn11149 suggested Justin Stimson commented

C# retrieve calllogs example using client api

// 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;
        }
    }
}

topic-default
1 |1000

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

7 Comments

·
Tyler Liu avatar image
Tyler Liu commented
What is the issue? Did you encounter any errors? Could you please post more detail?
1 |1000

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

alan-lapenn11149 avatar image
alan-lapenn11149 commented
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.
1 comment
1 |1000

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

Tyler Liu avatar image Tyler Liu commented ·
It is the expected behavior. Because the SDK is async. It won't block or stop your app from quitting.

You can add Console.ReadLine(); at the end to prevent it from quitting.
0 Likes 0 ·
david-southern11373 avatar image
david-southern11373 commented
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?
1 comment
1 |1000

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

Tyler Liu avatar image Tyler Liu commented ·
Here is the code of that method:  https://github.com/ringcentral/ringcentral-csharp-client/blob/master/RingCentral/Paths/CallLogPath.c...

You can see the the returned value is of type ExtensionCallLogResponse
0 Likes 0 ·
alan-lapenn11149 avatar image
alan-lapenn11149 commented
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.
1 |1000

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

david-southern11373 avatar image
david-southern11373 commented
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!
2 comments
1 |1000

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

John Wang avatar image John Wang ♦♦ commented ·
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
0 Likes 0 ·
Tyler Liu avatar image Tyler Liu commented ·
You don't have to deserialize it yourself. There are predefined classes:  https://github.com/ringcentral/ringcentral-csharp-client/blob/master/RingCentral/Definitions/Extensi...
0 Likes 0 ·
robert-eckman15237 avatar image
robert-eckman15237 commented
This code doesn't work anymore for the new C# SDK of Ring Central.  for example, the line

 var callLogs = await account.CallLog().List(new { direction = "Outbound", type = "Voice", dateFrom = "2019-03-10T12:00:00.000Z" });  

Gives me an error:
Severity Code Description Project File Line Suppression State
Error CS1503 Argument 1: cannot convert from '<anonymous type: string direction, string type, string dateFrom>' to 'RingCentral.LoadCompanyCallLogParameters' RC datafetch test C:\Users\Robert.Eckman\source\repos\RC datafetch test\RC datafetch test\Program.cs 39 Active

I'm not really a developer, but an analyst, and I don't know how to get past this.
2 comments
1 |1000

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

Phong Vu avatar image Phong Vu ♦♦ commented ·
Hi Robert,

To use the new .Net SDK, please look at this quick start for sample code to call the call log endpoint:

https://developers.ringcentral.com/guide/call-log/quick-start/c-sharp
0 Likes 0 ·
alan-lapenn11149 avatar image alan-lapenn11149 commented ·
And here is the same example I posted using the  new .Net SDK

using System;
using System.Threading.Tasks;
using RingCentral;

namespace getFaxLog
{
    class Program
    {
        const string RECIPIENT = "";
        const string RINGCENTRAL_CLIENTID = ";
        const string RINGCENTRAL_CLIENTSECRET = "";

        const string RINGCENTRAL_USERNAME = "";
        const string RINGCENTRAL_PASSWORD = "";
        const string RINGCENTRAL_EXTENSION = "";

        static void Main(string[] args)
        {
            Read_user_calllog().Wait();
        }
        static private async Task Read_user_calllog()
        {
            RestClient rc = new RestClient(RINGCENTRAL_CLIENTID, RINGCENTRAL_CLIENTSECRET, true);
            await rc.Authorize(RINGCENTRAL_USERNAME, RINGCENTRAL_EXTENSION, RINGCENTRAL_PASSWORD);
            if (rc.token.access_token.Length > 0)
            {
                var parameters = new LoadUserCallLogParameters();
                parameters.view = "Simple";
                parameters.dateFrom = "2019-03-10T18:07:52.534Z";
                parameters.direction = new string[] { "Outbound" };
                parameters.type = new string[] { "Fax" };

                var resp = await rc.Restapi().Account().Extension().CallLog().List(parameters);
                foreach (CallLogRecord record in resp.records)
                {
                    Console.WriteLine("type: {0}", record.type);
                    Console.WriteLine("phone number: {0}", record.to.phoneNumber);
                    Console.WriteLine("name: {0}", record.to.name);
                    Console.WriteLine("startTime: {0}", record.startTime);
                    Console.WriteLine("action: {0}", record.action);
                    Console.WriteLine("result: {0}", record.result);
                }
                Console.ReadLine();

            }
        }
    }
}


0 Likes 0 ·
Justin Stimson avatar image
Justin Stimson commented

This is exactly what I needed and the documentation is utterly cryptic. You are a deity.

1 |1000

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

Write a Comment

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

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.