Skip to main content

I am currently creating a Windows Application in C#. Its super basic and "dirty". Requirements:

1. Download all extensions and put in an xls file. 2. Download all call-forwarding and put in an xls file. 3. Upload changes from 2 above 4. Download all caller id and put in an xls file. 5. Upload changes from 4 above. #1 is completed and works marvelously. Here is the basic code:

RestClient rc = new RestClient(_clientId, _clientSecret);             await rc.Authorize(_username, _extension, _password);             var rcClient = rc.Restapi().Account();             var extensions = await rcClient.Extension().List();                List<ExtensionsClass> exts = new List<ExtensionsClass>();             for(int i=0;i<extensions.records.Count();i++)             {                 ExtensionsClass ext = new ExtensionsClass();                 ext.id = extensions.records[i].id;                 ext.extensionNumber = extensions.records[i].extensionNumber;                 ext.name = extensions.records[i].name;                 exts.Add(ext);             }             DataTable dt = new DataTable();  

#2 however I use the following code and the forwarding number always comes back null:

RestClient rc = new RestClient(_clientId, _clientSecret);  await rc.Authorize(_username, _extension, _password);  var rcClient = rc.Restapi().Account("~");     List<CallFwdRecord> exts = new List<CallFwdRecord>();  foreach (DataRow dr in dt.Rows)  {      var extn = await rcClient.Extension(dr["id"].ToString()).ForwardingNumber().Get();            //var extensions = await rcClient.Extension(dr["id"].ToString()).ForwardingNumber().Get();      CallFwdRecord ext = new CallFwdRecord();      IList<string> features = new List<string>();      //features = rcClient.F;      //ext.features = features;      //ext.flipNumber = extensions.records[0].flipNumber;      //ext.id = extensions.records[0].id;      //ext.label = extensions.records[0].label;      //ext.phoneNumber = extensions.records[0].phoneNumber;      //ext.uri = extensions.records[0].uri;      exts.Add(ext);   

}


Ideas?


TIA

Hi Corey,

Basically, the forwarding-number/{forwardingId} end point returns a list of forwarding numbers. You can parse the response from that API the same way you parsed the extension list. I am not sure about the name of the class but you can look for the class from the SDK. Maybe something like this ForwardingNumber().List

You then have to check if the list is empty or not. Also, make sure that forwarding number is defined for that extension (for sandbox https://service.devtest.ringcentral.com or for production https://service.ringcentral.com)

I will check 3., 4. and 5. and update you later.

Phong is correct. If you want the list of forwarding numbers, you need to .ForwardingNumber().List() instead of .ForwardingNumber().Get()

Thank you for your responses.  I had tried List() but get the following error:

An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in mscorlib.dll but was not handled in user code

Additional information: Unexpected character encountered while parsing value: [. Path 'records[0].features', line 8, position 18.



It is caused by type mismatching.  It is defined as string in C# code: https://github.com/ringcentral/ringcentral-csharp-client/blob/master/RingCentral/Definitions/Forward...

But the server returns an array of strings for it. That's why a JsonReaderExcepetion was thrown.

The C# code was generated according to swagger spec. I think there is a bug in the swagger spec. I have created an issue for the spec and I will follow up.

For now, a workaround is to get the json string and parse the string youself:
var response = await rc.Get(extension.ForwardingNumber().Endpoint(false)); 
var jsonString = await response.Content.ReadAsStringAsync(); // parse the jsonString to get what you want

Tyler this worked good.... now to try and update them.

Reply