Where could i lookup my AccountID and ExtensionID

  • 1
  • Question
  • Updated 1 year ago
  • Answered
  • (Edited)
Here's one of our developers with a question on how to retrieve accountId and extensionId from your RingCentral account.


"Parameter accountId is required in most of the API resources, may I know what is the account Id in sandbox account? Or where is it found?"


--------------------------------------------------------------------------------------------------------------------------------

The RingCentral service allows its customers to create and register an account that is usually associated with the customer's company. After registering the account with the company main number the user can create extensions of different types and functionality. The extensions can further be assigned with the phone numbers and phone devices.

All the account related link could be looked up in the "Exploring Account and Extension settings" section of our Developers guide here 

https://developer.ringcentral.com/api-docs/latest/index.html#!#ExploringAccount.html

Photo of AK

AK, Official Rep

  • 4,402 Points 4k badge 2x thumb
  • informative

Posted 3 years ago

  • 1
Photo of Anton Nikitin

Anton Nikitin, Official Rep

  • 2,904 Points 2k badge 2x thumb
In most cases API users do not need to know account ID and extension ID, because API supports simplified syntax if one needs just to refer to the account/extension of logged in user. Tilda "~" character can be used instead these IDs like in the example below:

GET https://platform.ringcentral.com/restapi/v1.0/account/~/extension/~/messsage-store
More details can be found here: http://developer.ringcentral.com/api-docs/latest/index.html#!#Resources.html
Photo of Admin Account

Admin Account

  • 106 Points 100 badge 2x thumb
Quick question, I have written an interface for a company I am working with that uses the C# SDK to connect to the APIs.  The code I've written depends on having the account ids to cycle through each user's call log, messages and attachments.  Is there a way to get the account id's for each user that I need to do this for so that I can cycle through the accounts and collect the information we need?  I tried going to the Online Portal for the RC app I have moved to production and attempted to download a user list in excel format and attempted to use the Mailbox IDs to iterate through the users I need to grab info for but this did not work.  Is there a way to get the internal RC account identifiers for users in a list format?
(Edited)
Photo of AK

AK, Official Rep

  • 4,402 Points 4k badge 2x thumb
You can retrieve all the user's ( extensions ) within the account using the :

Get Extensions ( API Endpoint ) 

This API returns the list of extensions created for a particular account. All types of extensions are included in this list. Every extension is associated with a parameter named id, for more information you can take a look at the sample request and response here:
https://developer.ringcentral.com/api-docs/latest/index.html#!#RefExtensionList.html
Photo of Admin Account

Admin Account

  • 106 Points 100 badge 2x thumb
Does this API endpoint grab all extensions and account id's for all rc users or is it for the user logged in?  It seems that it works on a per/user basis since the main argument is the tilde which, as I understand it, is only for the currently logged in user.  Therefore, if I understand the endpoint summary correctly, it will grab all extensions and the account id for the logged in user but not all users.  Is that the case?
Photo of AK

AK, Official Rep

  • 4,402 Points 4k badge 2x thumb
Does this API endpoint grab all extensions and account id's for all rc users or is it for the user logged in?  
One or more extensions exist under an Account. Lets say you have an Account named 'A' and all the extensions under this account would look like as below :

Account A
  • Ext 101 or User 1
  • Ext 102 or User 2
  • Ext 103 or User 3 etc
So irrespective of the User that you are authorizing as, the Get Extensions ( API Endpoint ) would retrieve all the extensions which belong to the account ( Account A )
 
Below is the sample API Request and response :

API Request

GET /v1.0/account/{accountId}/extension
Note: The {accountId} == ~ would refer to the account to whihc the extension belongs to.

API Response

{
  "uri": "https://platform.ringcentral.com/restapi/v1.0/account/1234567/extension?page=1&perPage=100&quo...;,
  "records": [
    {
      "uri": "https://platform.ringcentral.com/restapi/v1.0/account/1234567/extension/1024935020";,
      "id": "<<extensionID for 101>>",
      "extensionNumber": "101",
      "contact": {
        "firstName": "Extension number 101",
        "email": "sample.test@company.com",
        "pronouncedName": {
          "type": "Default"
        }
      },
      "name": "Message-Only-Extension",
      "type": "Voicemail",
      "status": "Enabled",
      "permissions": {
        "admin": {
          "enabled": false
        },
        "internationalCalling": {
          "enabled": false
        }
      },
      "profileImage": {
        "uri": "https://platform.ringcentral.com/restapi/v1.0/account/1234567/extension/1024935020";
      }
    },
    {
      "uri": "https://platform.ringcentral.com/restapi/v1.0/account/1234567/extension/1024935020";,
      "id": "<<extensionID for 102>>"
      "extensionNumber": "102",
      "contact": {
        "firstName": "Extension name for ",
        "lastName": "Notification",
        "company": "RC",
        "email": "sample.test@company.com",
        "emailAsLoginName": true,
        "pronouncedName": {
          "type": "TextToSpeech"
        }
      },
      "name": "AWS Notification",
      "type": "User",
      "status": "Enabled",
      "permissions": {
        "admin": {
          "enabled": false
        },
        "internationalCalling": {
          "enabled": true
        }
      },
      "profileImage": {
        "uri": "https://platform.ringcentral.com/restapi/v1.0/account/1234567/extension/1024935020";,
      }
    },
}
Photo of Admin Account

Admin Account

  • 106 Points 100 badge 2x thumb
Thanks for the detailed response.  If I understand you correctly, and what I assumed, was that the api will retrieve all extensions for a single user, respectively the one logged in and running the get extension api call.  

Here is my scenario:  I have written an automated process that will need to go and check each of our ring central users one by one and all their associated extensions for messages and attachments and download them to our servers here locally for use in our business processes.  This automated process would need to cycle through all user accounts to do this so no one individual will be logged in.  Rather a super account would be running this process and retrieving the data.  Is it possible to do this?  All I need are all the account ids for each of our uses but in order to do this it seems that I'd have to run the api (via the code I've written as and installed service on each system) from each users machine under their id to get that account.  All I need is a list of the account ids to have my automated process cycle through and retrieve the data but it doesn't seem to be possible unless I have the process run from each user's machine under their id and retrieve that data.
Photo of AK

AK, Official Rep

  • 4,402 Points 4k badge 2x thumb
Based on what you wrote above, it seems like you have an app that connects to multiple RingCentral and you want to retrieve data for each account.

To this you need the following at a high level:
  • A public app as a private app can only connect to the owner's account, not other accounts. In the Developer Portal, ensure your app's scope is set to Public.
  • A UI that uses RingCentral's 3-legged OAuth 2.0 authorization flow, either the Authorization Code or Implicit Grant flow. To retrieve data for all users in an account, you either need (a) an admin to authorize your app for each account or (b) each user to authorize your app.
  • After the user authorizes the account, you will receive an access token representing that user's authorization of your app. At this point you can retrieve a list of all user extensions from the account extension endpoint: /restapi/v1.0/account/~/extension . Technically, you do not need to explicitly use the accountId in API calls since the "~" shorthand notation will represent the current account for the access token, but if you want it, you can retrieve the accountId from the /restapi/v1.0/account/~ endpoint.
  • With an access token for each account, just cycle through the accounts and each account's extensions.
Here are some more detailed steps on how to accomplish this : 

  • Authorization Code Flow using OAuth2.0 : 
          The app would need to support the OAuth2.0 Authentication flow by which you           can authenticate users on your app. To know more on how to implement the              Authorization Code Flow inside your application read below :

https://devcommunity.ringcentral.com/ringcentraldev/topics/using-oauth-2-0-          authorization-code-grant-...
  • Get Accound ID :
          Get Company Info ( API Endpoint )

          Per this API endpoint, you would need to provide tilde (~) to get the account                 information as below :

          /v1.0/account/{accountId}
  • Get all Extensions under the account :
         Once you have the accountId, you can obtain the all the extensions that belong          to that account using the :

         Get Extensions ( API Endpoint ) 

Benefits of Implementing this architecture :
  • No need to run the process from each users machine
  • A consistent and trusted UI
  • Integrated password reset
  • Integrated single sign-on (SSO) via SAML support
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,652 Points 5k badge 2x thumb
"Account" in RingCentral typically means a company, "Extension" typically means an user. If your app processes data for one company at a time, there is no need to know the account id at all, because there is only one single account and you are implicitly using it already.  To list all of the users, you just to list all of the extensions: https://developer.ringcentral.com/api-docs/latest/index.html?_ga=2.13227319.1817969349.1506220194-10...

Please clarify your situation and your question if you need further help.
Photo of Admin Account

Admin Account

  • 106 Points 100 badge 2x thumb
Thanks for the help guys.  Your assistance as usual, has been invaluable.  I was successfully able to iterate through all the extensions per both of your instructions and have been able to hit the required endpoints that I needed to hit.  I'm running into a new situation now and wanted to see if either of you could leave me some ideas of what I may be doing wrong.

Here is what my error log is indicating:
2017-09-27 14:06:47,478 [10] ERROR PRIS.RingCentral.MessagesService - Message:
Request rate exceededSource:
RingCentralMethod Causing Error:
Void .ctor(System.Net.Http.HttpResponseMessage, System.Net.Http.HttpRequestMessage)Stack Trace:
   at RingCentral.Http.ApiResponse..ctor(HttpResponseMessage response, HttpRequestMessage request)
   at RingCentral.Platform.Send(HttpMethod httpMethod, Request request)
   at RingCentral.Platform.Get(Request request)
   at PRIS.RingCentral.MessagesService.GetAttachmentContent(ParamsForContentDownloads downloadParams, String& result) in c:\Projects\DotNet\PRIS-Framework\PRIS-Framework\PRIS.RingCentral\Services\MessagesService.cs:line 106


Here is where I make the call in MessagesService.cs:line 106
var txtToBytes = Encoding.UTF8.GetBytes(string.Format("{0}:{1}", Settings.AppKey, Settings.AppSecret));
string encodedText = Convert.ToBase64String(txtToBytes);

// Create request with proper authorization.
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, downloadParams.Attachment.Uri);
request.Headers.TryAddWithoutValidation("Content-Type", @"application/x-www-form-urlencoded;charset=UTF-8");
request.Headers.Add("Authorization", string.Format("Basic {0}", encodedText));

// Handle response
var response = Client.RcPlatform.Get(new Request(request.RequestUri.AbsolutePath));

// Get extension type
result = ExtensionHelpers.GetDefaultExt(response.Headers.ContentType.MediaType);

// Get the binary
return Encoding.ASCII.GetBytes(response.Body);

What is strange is that I get a file with varying sizes in kb, but there is not content.  For example when I open a pdf, it's blank or if I attempt to open a sound file, it doesn't play anything.  Am I handling this correctly?
(Edited)
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,652 Points 5k badge 2x thumb
"Request rate exceeded" means you need to slow down your app. You will encounter this error if you  call the API too fast.
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,652 Points 5k badge 2x thumb
It seems that you are not using the recommended C# Client to access the platform API. Please take a look at the official way to download binary: https://github.com/ringcentral/ringcentral-csharp-client/blob/master/RingCentral.Test/BinaryTest.cs