code 404 (Not Found) at c#

  • 1
  • Problem
  • Updated 2 months ago
  • (Edited)
I can't get any of the API calls to answer me. it always returns as 404 Not found 
Im using the nugget C# library

im using the following code

using RingCentral; 

####

  string appKey = "MYKEY";
            string appSecret = "MYSECRET";
            string phoneNumber = "+15178853031";
            string password = "MYPASSWORD";
            string country = "44";
            rc = new RestClient(appKey, appSecret);

            await rc.Authorize(phoneNumber, "101", password);

            var tokenString = rc.token.access_token;

            var extension = rc.Restapi("v1.0").Account("15178853031").Extension("101");

            var requestBody = new
            {
                country = new { id = country },
                from = new { phoneNumber = phoneNumber },
                to = new object[] { new { phoneNumber = "+4407922204537" } },
                playPrompt = "true",

            };

            var response = await extension.RingOut().Post(requestBody);


what I get is that :
Call failed with status code 404 (Not Found): POST https://platform.devtest.ringcentral.com/restapi/v1.0/account/15178853031/extension/101/ring-out

even using the API page to TRY now, returns that if i set the values for Account and Extension.

any ideas?
Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
  • frustrated

Posted 2 months ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,568 Points 5k badge 2x thumb
The issue is accountId and extensionId. If you don't know what they are, use "~" as ID. "~" means the currently authorized user.

And to get the IDs, you can rc.Restapi("v1.0").Account("~").Extension("~").Get() and check the response. ID is not number, 101 is extension number.



Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
using ~ dont work either, it return this:

{"Call failed with status code 400 (Bad Request): POST https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/ring-out"}

it does successfully retrieve a token if you are wondering.

 
Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
this method
rc.Restapi("v1.0").Account("~").Extension("~").Get() 
returns this

Id = 79, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,568 Points 5k badge 2x thumb
You need to add await at the beginning of this line. I forgot that.  Everything HTTP Call is async. So you need to await them to get something meaningful.
Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
Yeah but that also returns

{"Call failed with status code 404 (Not Found): GET https://platform.devtest.ringcentral.com/restapi/V1.0/account/~/extension/~"}

for this method

  var id = await rc.Restapi("V1.0").Account("~").Extension("~").Get();
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,568 Points 5k badge 2x thumb
V1.0 should be v1.0
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,568 Points 5k badge 2x thumb
Or you can just

var r = await rc.Restapi().Account().Extension().Get();
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,568 Points 5k badge 2x thumb
Here is the doc for this method: https://github.com/ringcentral/RingCentral.Net/blob/master/samples.md#load-extension-info

The returned type is not an ID. You can find the type definition in the link above.
Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
tested that, returns the same thing 404 USING method not working tho. since its not dependent from IDisposable. 

also using the API reference returns the same thing

Photo of Tyler Long

Tyler Long, Official Rep

  • 9,568 Points 5k badge 2x thumb
101 is not the exension ID so it is not found.  Please use "~" instead if you don't know the ID.
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,568 Points 5k badge 2x thumb
Do you mind trying something new? 
https://medium.com/ringcentral-developers/new-ringcentral-sdk-for-net-a43417b2538c

We are going to announce it today.

It has way better exception reporting mechanism.  Try it and you will know the root cause of "{"Call failed with status code 400 (Bad Request)"
Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
gonna go to lunch and have a look at that after that.
Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
What version of .Net is that aimed at?

error:

 Could not install package 'RingCentral.Net 0.6.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information,
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,568 Points 5k badge 2x thumb
It is .NET standard 2.0.  https://devblogs.microsoft.com/dotnet/announcing-net-standard-2-0/

You need to use 
  • .NET Framework 4.6.1
Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
No solution so far, guess I will have to develop for nextiva instead.
T_T
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,486 Points 5k badge 2x thumb
Both the new and the old package can solve the issue.

Please read my comments above and get the IDs issue fixed. As I said if you don't know the IDs, just use "~" as the ID. 
Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
like i said, using ~ wont work. give error 404 not found.
Photo of Phong Vu

Phong Vu, Devangelist

  • 5,016 Points 5k badge 2x thumb
Create a .Net Core app (Core 2.1) and copy paste this code and try it. It should work

using System;
using System.Threading.Tasks;
using RingCentral;
namespace Call_Ringout
{
    class Program
    {
          const string RECIPIENT = "<ENTER PHONE NUMBER>";
          const string RINGCENTRAL_CLIENTID = "<ENTER CLIENT ID>";
          const string RINGCENTRAL_CLIENTSECRET = "<ENTER CLIENT SECRET>";
          const string RINGCENTRAL_USERNAME = "<YOUR ACCOUNT PHONE NUMBER>";
          const string RINGCENTRAL_PASSWORD = "<YOUR ACCOUNT PASSWORD>";
          const string RINGCENTRAL_EXTENSION = "<YOUR EXTENSION, PROBABLY ";
          static void Main(string[] args)
          {
              call_ringout().Wait();
          }
          static private async Task call_ringout()
          {
              RestClient rc = new RestClient(RINGCENTRAL_CLIENTID, RINGCENTRAL_CLIENTSECRET, false);
              await rc.Authorize(RINGCENTRAL_USERNAME, RINGCENTRAL_EXTENSION, RINGCENTRAL_PASSWORD);
              if (rc.token.access_token.Length > 0)
              {
                  var parameters = new MakeRingOutRequest();
                  parameters.from = new MakeRingOutCallerInfoRequestFrom { phoneNumber = RINGCENTRAL_USERNAME };
                  parameters.to = new MakeRingOutCallerInfoRequestTo {  phoneNumber = RECIPIENT } ;
                  parameters.playPrompt = false;
                  var resp = await rc.Restapi().Account().Extension().RingOut().Post(parameters);
                  Console.WriteLine("Call Placed. Call status" + resp.status.callStatus);
              }
          }
      }
}

Remember to install the RingCentral SDK using NuGet package RingCentral.Client (3.0.0) SDK

Hope this helps,
Photo of Murylo Batista

Murylo Batista

  • 152 Points 100 badge 2x thumb
Thank you! can i ask you where exactly did you take MakeRingOutRequest() documentation from? i haven't
 seen it anywhere and that looks like solved the issue.