Skip to main content

So I’ve just started out using the RC api, and I’ve got a project going, just a simple little console app to automate user creation and eventually deletion. After going over the documentation, I have a slice of code that it seems should be working, but I’m getting a null reference exception when I actually try to make the api call. Here’s my code: 

using System;
using RingCentral;

class Test1
{
static string accountId = "fakeID";

static RestClient rc = new RestClient(
"fakeid",
"fakesecret",
"https://platform.devtest.ringcentral.com"
);

static ExtensionCreationRequest extensionCreationRequest = new ExtensionCreationRequest
{
contact = new ContactInfoCreationRequest
{
firstName = "Test",
lastName = "Sam",
jobTitle = "Test",
email = "test.sam@fakeplace.org",
emailAsLoginName = true,
department = "Test"
},
extensionNumber = "1234",
password = "*****",
type = "User"
};
public static void Main(stringi] args)
{
Response();
Console.ReadLine();
}
private static async void Response()
{
var r = await rc.Restapi().Account(accountId).Extension().Post(extensionCreationRequest);
Console.WriteLine(r.status);
}
}

 I’ve scoured the internet looking for more examples of this sort of thing, but there’s not much out there. I can’t figure out what I’m doing wrong.

Your code is weird and is not reusable.


...
static RestClient restClient;
static async Task Main(string[] args)
{
restClient = new RestClient(
Environment.GetEnvironmentVariable("RC_APP_CLIENT_ID"),
Environment.GetEnvironmentVariable("RC_APP_CLIENT_SECRET"),
Environment.GetEnvironmentVariable("RC_SERVER_URL"));
await restClient.Authorize(Environment.GetEnvironmentVariable("RC_USER_JWT"));
await create_user_extension();
}

static private async Task create_user_extension()
{
var bodyParams = new ExtensionCreationRequest
{
contact = new ContactInfoCreationRequest
{
firstName = "Tester",
lastName = "Fake",
jobTitle = "Test",
email = "test.fake@whatever.org",
emailAsLoginName = true,
department = "Test"
},
extensionNumber = "1234",
password = "****",
type = "User"
};

var resp = await restClient.Restapi().Account().Extension().Post(bodyParams);
Console.WriteLine(JsonConvert.SerializeObject(resp));
}
...

 


Reply