C# Example

  Example generic function to handle the calls to the API:

private string Submit(string url, string method, string contentType = "application/json", string data = null) 
{ 
    string sUrl = string.Format("https://app.waytobi.com/api{0}", url);
    string auth = "APIToken"; //Replace APIToken with the token from your account 
    string sHtml = ""; 
    var wReq = (HttpWebRequest)WebRequest.Create(sUrl); 
    
    wReq.ContentType = contentType; 
    wReq.Accept = contentType; 
    wReq.UserAgent = "Generic Agent"; 
    wReq.Timeout = 45 * 1000; // milliseconds 
    wReq.AllowAutoRedirect = false; 
    wReq.Method = method; 
    wReq.AutomaticDecompression = DecompressionMethods.GZip; 
    wReq.Headers.Add("Authorization", "BASIC " + auth); 
    try 
    { 
        if (!string.IsNullOrWhiteSpace(data)) 
        { 
            wReq.ContentLength = data.Length; 
            var sReq = new StreamWriter(wReq.GetRequestStream()); 
            sReq.Write(data); 
            sReq.Flush(); 
            sReq.Close(); 
        } 
        var sResp = new StreamReader(wReq.GetResponse().GetResponseStream()); 
        sHtml = sResp.ReadToEnd(); 
        sResp.Close(); 
        return sHtml; 
    } 
    catch (WebException ex) 
    { 
        if (ex.Response != null) 
        { 
            var sResp = new StreamReader(ex.Response.GetResponseStream()); 
            sHtml = sResp.ReadToEnd(); 
            sResp.Close(); 
        } 
        else 
        { 
            sHtml = ex.Message; 
        } 
         
        return sHtml; 
     } 
}

 

   Usage of the function:

var html = Submit("/Groups", "GET");
Console.WriteLine(html );

Unable to find an answer?

Looking for anything specific article which resides in general queries? Just browse the various relevant folders and categories and then you will find the desired article.

Contact Us