Giter Site home page Giter Site logo

Comments (4)

jmol123 avatar jmol123 commented on May 25, 2024

Nevermind! I was able to figure this out. The code below will pull the first 2500 extensions of the account (sorted by ext #) and output to a text file with Ext: # and ID: # so that a call can be made directly to one extension by using var extension = rc.Restapi().Account().Extension("ID#)

var extensions = rc.Restapi().Account().Extension().List(new { perPage = 2500 }).Result.records;
        var count = 0;
        string path = @"PATH TO FILE";
        while (count < 2500)
        {
            foreach (var extension in extensions)
            {
                //Console.WriteLine(count.ToString());
                //Console.WriteLine(extension.extensionNumber);

                if (count.ToString() == extension.extensionNumber)
                {
                    string field = "Ext: " + extension.extensionNumber + " ID: " + extension.id;
                    Console.WriteLine(field);

                    
                    // This text is added only once to the file.
                    if (!File.Exists(path))
                    {
                        // Create a file to write to.
                        using (StreamWriter sw = File.CreateText(path))
                        {
                            sw.WriteLine("Hello");
                        }
                    }

                    // This text is always added, making the file longer over time
                    // if it is not deleted.
                    using (StreamWriter sw = File.AppendText(path))
                    {
                        sw.WriteLine(field);
                    }
                }

            }
            count = count + 1;
        }`

from ringcentral-csharp-client.

tylerlong avatar tylerlong commented on May 25, 2024

Awesome!

Actually I am not sure whether you are able to fetch as many as 2500 records with one request. Because some of RingCentral's API endpoints only allow 1000 as maximum perPage limit. You will be fine if your account has fewer than 1000 extensions. But if there are 1000+ extensions, you can do pagination like this:

var extensions = rc.Restapi().Account().Extension().List(new { perPage = 1000, page = 2 }).Result.records;

Code above returns page 2 of the results.

from ringcentral-csharp-client.

jmol123 avatar jmol123 commented on May 25, 2024

My company only has ~160 extensions but the actual extension numbers range from 2 to ~2000 so that is why I made the range so wide. I actually also meant to put perPage = 1000 in the code I pasted above, but Copy/Pasted the wrong version of the code. Whoops!!

from ringcentral-csharp-client.

tylerlong avatar tylerlong commented on May 25, 2024

If there are only ~160 extensions, pagination is not needed. As I said you could fetch as many as 1000 records with single request. All seem fine to me now. 👍

from ringcentral-csharp-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.