String Error C# Call Log

  • 1
  • Problem
  • Updated 1 month ago
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);
                    }
                }

            }
        }
    }
}
Photo of Eric Lisciandrello

Eric Lisciandrello

  • 92 Points 75 badge 2x thumb

Posted 1 month ago

  • 1
Photo of Brandon Hein

Brandon Hein

  • 468 Points 250 badge 2x thumb
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
Photo of Eric Lisciandrello

Eric Lisciandrello

  • 92 Points 75 badge 2x thumb
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.
Photo of Brandon Hein

Brandon Hein

  • 468 Points 250 badge 2x thumb

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);
                }
            }
        }
    }
}
Photo of Brandon Hein

Brandon Hein

  • 468 Points 250 badge 2x thumb
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
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,828 Points 5k badge 2x thumb
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
Photo of Eric Lisciandrello

Eric Lisciandrello

  • 92 Points 75 badge 2x thumb
Thank you both for your assistance.