Help Guide : http://demo.techcello.com/help

Download Link : Web API Sample using key authentication


CelloSaaS offers a Web APIs that allows the customers to retrieve information about their account such as Tenant, Users, Package, Events, Notification, Tenant Settings, Roles, Billing and other information. 


Rest calls via Rest Client from trusted web application


CelloSaaS provides a REST API client (CelloSaaS.RestApiSDK.dll) which is available in Package. Using this you can consume the CelloSaaS web API.


  Sample Code:


using System;
using CelloSaaS.RestApiSDK;
namespace WebApiSDKUnitTest
{
  class UserDetailsClientTest
    {
        static void Main()
        {
            try
            {
                using (var client = GetClient())
                {
                    var users = client.GetAllUsers();                  
                }
            }
            Catch(Exception ex)
            {
		Console.WriteLine(ex.Message)
            }
        }
        private static UserDetailsClient GetClient()
        {
            var client = new UserDetailsClient(
                baseAddress: "http://localhost:50707/api/users/",
                username: "b590cd25-3093-df11-8deb-001ec9dab123/admin@company.com",
                api_key: "UBd2DX9xIPprqtB7D0yb0w==");
            return client;
        }
    }
} 

  

Rest calls via Http Client from trusted web application:


 

using System;
using System.Globalization;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using CelloSaaS.RestApiSDK;

namespace RestConsoleTest
{
    class Program
    {
        private static string baseAddress = "https://localhost/api";
        private static string username = "b590cd25-3093-df11-8deb-001ec9dab123/admin@company.com";
        private static string api_key = "UBd2DX9xIPprqtB7D0yb0w==";
        private static Guid? tenantId = Guid.Parse("b590cd25-3093-df11-8deb-001ec9dab123");

        static void Main(string[] args)
        {
            HttpClient _client = new HttpClient();
            _client.BaseAddress = new Uri(baseAddress);

            var encoding = Encoding.GetEncoding("iso-8859-1");
            var key = string.Format(CultureInfo.CurrentCulture, "{0}:{1}", username, api_key);
            var parameter = Convert.ToBase64String(encoding.GetBytes(key));
            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", parameter);
            _client.DefaultRequestHeaders.Accept.Clear();
            _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var uri = tenantId.HasValue ? "get_all_users?tenant_id=" + tenantId.Value.ToString() : "get_all_users";

            var response = _client.GetAsync(uri).Result;

            if (response.IsSuccessStatusCode)
            {
                var users = response.Content.ReadAsAsync<UserDetailsDTO[]>().Result;
            }

            throw new Exception(response.Content.ReadAsStringAsync().Result);
        }
    }
}

 

Authentication


Each API requires an authentication. You must send the following parameters on your API calls.


username: tenantid/username is the context of the user in which the call is made. Tenant id is obtained from tenant management page.


api_key : An Encrypted key used to authenticate the Rest API calls. This is the master key set at the product level and can be configured as a part of web configuration. See below.


Common API key:


It is set in appsettings.config file in Rest API Application.

 

  

 <add key="UseCommonAPIKey" value="True"/>

  <!-- common api key to use for all WCF calls and rest API calls-->
 <add key="CommonApiKey" value="UBd2DX9xIPprqtB7D0yb0w=="/> 

  


Note: If you need more security, Instead of common API key, wcfshared key can be used for each tenant