1. Home
  2. Docs
  3. CloudPanel API
  4. Getting Started
  5. Example

Example

using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudPanel.Demo.Api.Client
{
    // This is the class you bind to your request using
    // RestSharp. This example returns a list of users which
    // sends back integer values draw, recordsTotal, recordsFiltered
    // (which are jQuery DataTables values) and a list of user
    // objects in value 'data'
    public class Users
    {
        public int draw { get; set; }
        public int recordsTotal { get; set; }
        public int recordsFiltered { get; set; }
        public List<UserObject> data { get; set; }
    }

    // Class containing SOME of the values returned by
    // CloudPanel. All values not shown in example.
    public class UserObject
    {
        public Guid UserGuid { get; set; }
        public string CompanyCode { get; set; }
        public string DisplayName { get; set; }
    }

    class Program
    {
        const string BaseUrl = "http://server/CloudPanel";
        static string ApiKey = "Af4tA4];%d)!Q7`geQ6V71";

        static void Main(string[] args)
        {
            GetUsers();
            Console.ReadKey();
        }

        static void GetUsers()
        {
            var client = new RestClient(BaseUrl);
            var request = new RestRequest("company/COM2/users", Method.GET);
            request.AddQueryParameter("ApiKey", ApiKey); // API Key can be form or query value

            var response = client.Execute<Users>(request);
            foreach (var u in response.Data.data)
            {
                Console.WriteLine(u.DisplayName);
            }
        }
    }
}
Was this article helpful to you? Yes No

How can we help?