Document toolboxDocument toolbox

Send requests with C#

Introduction

After authorizing API requests as required and setting up a C# environment, you can use the script below to send API requests using C#:

using System.Security.Cryptography; using System.Text; namespace Devo {     class Program     {         public void callDevoAPI()         {             String key = "YOUR-DEVO-API-KEY-GOES-HERE";             String secret = "YOUR-DEVO-API-SECRET-GOES-HERE";             String cloud = "us";             String query = "from box.unix select *";             String body = "" +                 "{\"from\": \"2h\", " +                 "\"to\": \"now\", " +                 "\"query\":\"" + query + "\"," +                 "\"limit\": 10, " +                 "\"mode\": { \"type\":\"csv\"}}";             var httpclient = new HttpClient();             httpclient.Timeout = TimeSpan.FromMinutes(9999);             String queryEndpoint = "https://apiv2-" + cloud + ".devo.com/search/query";             var webRequest = new HttpRequestMessage(HttpMethod.Post, queryEndpoint)             {                 Content = new StringContent(body, Encoding.UTF8, "application/json")             };             String unixTimestamp = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds.ToString();             unixTimestamp = unixTimestamp.Substring(0, unixTimestamp.IndexOf("."));             String data = key + body + unixTimestamp;             byte[] byteArrayData = Encoding.UTF8.GetBytes(data);             byte[] byteArraySecret = Encoding.UTF8.GetBytes(secret);             var hash = new HMACSHA256(byteArraySecret);             byte[] byteSigned = hash.ComputeHash(byteArrayData);             var hexString = BitConverter.ToString(byteSigned);             String sign = hexString.Replace("-", "").ToLower();             httpclient.DefaultRequestHeaders.Add("x-logtrust-apikey", key);             httpclient.DefaultRequestHeaders.Add("x-logtrust-timestamp", unixTimestamp);             httpclient.DefaultRequestHeaders.Add("x-logtrust-sign", sign);             try             {                 var response = httpclient.Send(webRequest);                 Console.WriteLine(response.Content.ReadAsStringAsync().Result);             }             catch (Exception ex)             {                 Console.WriteLine("Exception occured: " + ex.Message);             }         }         public static void Main(string[] args)         {             Program p = new Program();             p.callDevoAPI();         }     } }

Parameters

Replace the following parameters in the script using your own information:

key

Enter the API key of your Devo domain. To get it, access Devo and go to Administration → Credentials → Access Keys. Learn more in this article.

secret

Enter the API secret of your Devo domain. To get it, access Devo and go to Administration → Credentials → Access Keys. Learn more in this article.

cloud

Specify the Devo cloud of your domain. The available options are us, eu, es, ca and saas

query

Enter the query you want to run.

body

Specify the body of your requests, following the format of the script above.