question

eric-lisciandrello15585 avatar image
eric-lisciandrello15585 asked ·

String Error C# Call Log

Good evening,
Probably an absolute obvious answer and newb answer. But I am attempting to code our own call log pulls in C# but starting off with the tutorial version, and currently I am testing our API's out in the Console version. I am switching from Power BI to a WPF Application. As I go to pull our company call-logs, I am trying to specify the OUTBOUND direction only, but I keep receiving a "CS0029 - Cannot implicitly convert type 'string' to 'string[]'. Below is the code I am trying to alter.




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


namespace Read_CallLog
{
    class Program
    {
        const string RINGCENTRAL_CLIENTID = "MYID#";
        const string RINGCENTRAL_CLIENTSECRET = "MYSECRET";

        const string RINGCENTRAL_USERNAME = "12345678910";
        const string RINGCENTRAL_PASSWORD = "PASSWORD";
        const string RINGCENTRAL_EXTENSION = "EXTENSION";

        static void Main(string[] args)
        {
            Read_user_calllog().Wait();
            Console.ReadLine();
        }
        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);

            var mainAcct = rc.Restapi().Account();

            if (rc.token.access_token.Length > 0)
            {

                var resp = await mainAcct.CallLog().List(new LoadCompanyCallLogParameters
                {
                    perPage = 100,
                    direction = "Outbound",
                    type = "Voice"
                });

                foreach (CallLogRecord record in resp.records)
                {
                    if (record.direction == "Outbound")
                    {
                        Console.WriteLine("Call type: " + record.type + " / " + record.from.extensionNumber);
                    }
                }

            }
        }
    }
}
General Topic
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
brandon-hein avatar image
brandon-hein answered ·
Where's your error occuring? In the part where you're generating the request? Because I think the request parameters call for an array (due to having multiple cases) Setting a string array is pretty straight forward. Try this: new string[] { "Outbound" }; Now you wouldn't be able to do a string == string[] for a comparison because they're not the same type
5 comments
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.

Stack overflow and Google are your friends when you're self teaching yourself.  Great community like this one.  pretty simple to ask how to change a 'string' to a 'string array'.... will help find your answer and with threads... you can see with what works for you
1 Like 1 ·
It is in line 38 and line 39 - I've tried your recommendation placing that in the code and it does not help.

For reference - I'm self taught on being able to program APIs and so forth, so I may need a little extra point in the direction needed then most.
0 Likes 0 ·

This is what you're seeing Eric...

Looking at the RC Nuget library.  (Right click in visual studio and 'Go to Definition') 'direction' and 'type' are both array properties


I updated to pass in you parameters via an array vs your string... works fine.


class Program
{
const string RINGCENTRAL_CLIENTID = "MYID#";
    const string RINGCENTRAL_CLIENTSECRET = "MYSECRET";
    const string RINGCENTRAL_USERNAME = "12345678910";
    const string RINGCENTRAL_PASSWORD = "PASSWORD";
    const string RINGCENTRAL_EXTENSION = "EXTENSION";
    static void Main(string[] args)
    {
        Read_user_calllog().Wait();
        Console.ReadLine();
    }
    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);
        var mainAcct = rc.Restapi().Account();
        if (rc.token.access_token.Length > 0)
        {
            var resp = await mainAcct.CallLog().List(new CallLogPath.ListParameters()
            {
                perPage = 100,
                direction = new string[] { "Outbound" },
                type = new string[] { "Voice" }
            });
            foreach (CallLogRecord record in resp.records)
            {
                if (record.direction == "Outbound")
                {
                    Console.WriteLine("Call type: " + record.type + " / " + record.from.extensionNumber);
                }
            }
        }
    }
}
0 Likes 0 ·
Hi All,

Excellent answer from Brandon!  

I also recommend you to try latest .NET SDK if you haven't done so:  https://github.com/ringcentral/ringcentral.net
0 Likes 0 ·
Thank you both for your assistance.
0 Likes 0 ·

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.