question

eric-lisciandrello15585 avatar image
eric-lisciandrello15585 asked eric-lisciandrello15585 commented

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);

}

}


}

}

}

}

getting started
1 |3000

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

1 Answer

brandon-hein avatar image
brandon-hein answered eric-lisciandrello15585 commented
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 |3000

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

brandon-hein avatar image brandon-hein commented ·
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 ·
eric-lisciandrello15585 avatar image eric-lisciandrello15585 commented ·
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 ·
brandon-hein avatar image brandon-hein commented ·

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 ·
Tyler Liu avatar image Tyler Liu ♦ commented ·
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 ·
eric-lisciandrello15585 avatar image eric-lisciandrello15585 commented ·
Thank you both for your assistance.
0 Likes 0 ·

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys