Hello, first time user here. I'm trying to test the most basic code sample for C# but it isn't working and it's throwing a very vague exception. Code and exception below. I replaced the sensitive variables with comments describing what they had been set to.
using System;
using System.Threading.Tasks;
using RingCentral;
using DotNetEnv;
namespace Call_Ringout
{
class Program
{
static RestClient restClient;
static void Main(string[] args)
{
restClient = new RestClient(
/*Client ID*/,
/*Client Secret*/,
"https://platform.devtest.ringcentral.com");
restClient.Authorize(
/*Username*/,
/*Extension*/,
/*Password*/;
call_ringout().Wait();
}
static private async Task call_ringout()
{
var parameters = new MakeRingOutRequest();
parameters.from = new MakeRingOutCallerInfoRequestFrom
{
phoneNumber = /*From Number*/
};
parameters.to = new MakeRingOutCallerInfoRequestTo
{
phoneNumber = /*To Number*/
};
parameters.callerId = new MakeRingOutCallerInfoRequestTo
{
phoneNumber = /From Number/
};
parameters.country = new MakeRingOutCoutryInfo
{
id = "1"
};
parameters.playPrompt = false;
//var resp = await restClient.Restapi().Account().Extension().RingOut().Post(parameters);
//Console.WriteLine("Call Placed. Call status" + resp.status.callStatus);
var _1 = restClient.Restapi();
var _2 = _1.Account();
var _3 = _2.Extension();
var _4 = _3.RingOut();
try
{
var resp = await _4.Post(parameters);
Console.WriteLine("Call Placed. Call status" + resp.status.callStatus);
}
catch(Exception e)
{
Console.WriteLine(e.InnerException);
Console.WriteLine(e.Message);
Console.WriteLine(e.ToString());
}
}
}
}
I broke up the line
var resp = await restClient.Restapi().Account().Extension().RingOut().Post(parameters);
Into its component parts to see where the problem is. It is in the last part, which is why I put the try block around it alone.
Here is the error I'm getting:
Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at RingCentral.RestClient.Request(HttpRequestMessage httpRequestMessage, Int32 retriedTimes, Nullable`1 cancellationToken)
at RingCentral.RestClient.Request(HttpMethod httpMethod, String endpoint, Object content, Object queryParams, Nullable`1 cancellationToken)
at RingCentral.RestClient.Request[t](HttpMethod httpMethod, String endpoint, Object content, Object queryParams, Nullable`1 cancellationToken)
at RingCentral.RestClient.Post[t](String endpoint, Object content, Object queryParams, Nullable`1 cancellationToken)
at RingCentral.Paths.Restapi.Account.Extension.RingOut.Index.Post(MakeRingOutRequest makeRingOutRequest, Nullable`1 cancellationToken)
at Call_Ringout.Program.call_ringout() in C:Userswscheffeysource
eposCall_RingoutCall_RingoutProgram.cs:line 55
C:Program Filesdotnetdotnet.exe (process 28572) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
Any help greatly appreciated.