question

corey-tenney avatar image
corey-tenney asked ·

ForwardingNumber always come back as null

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
topic-default
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.

Phong Vu avatar image
Phong Vu answered ·
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.
Share
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.

Tyler Liu avatar image
Tyler Liu answered ·
Phong is correct. If you want the list of forwarding numbers, you need to .ForwardingNumber().List() instead of .ForwardingNumber().Get()
Share
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.

corey-tenney avatar image
corey-tenney answered ·
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.


2 comments Share
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.

Let me have a try and update you later.
0 Likes 0 · ·
I can reproduce the issue
0 Likes 0 · ·
Tyler Liu avatar image
Tyler Liu answered ·
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
1 comment Share
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.

Tyler, thanks for that.  I will work on that soon.
0 Likes 0 · ·
corey-tenney avatar image
corey-tenney answered ·
Tyler this worked good.... now to try and update them.
Share
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.

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.