• v7.5.0
    • v7.11.0 (latest)
    • v7.10.0
    • v7.9.0
    • v7.8.0
    • v7.7.0
    • v7.6.0
    • v7.5.0
    • v7.3.0
    • v7.2.0
    • v7.1.1
    • v7.1.0
    • v7.0.8
  • Services & Support
  • Devo.com
  • Contact
    • Contact Us
    • Request a Demo
    • Partner Inquiry
  • Log In
    • USA Devo
    • EU Devo
PREVIOUS
Send requests with Postman
NEXT
Job requests

API reference / Query API / Running queries with the Query API / Send requests with C#

Download as PDF

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:

keyEnter the API key of your Devo domain. To get it, access Devo and go to Administration → Credentials → Access Keys. Learn more in this article.
secretEnter the API secret of your Devo domain. To get it, access Devo and go to Administration → Credentials → Access Keys. Learn more in this article.
cloudSpecify the Devo cloud of your domain. The available options are us, eu, es, ca and saas
queryEnter the query you want to run.
bodySpecify the body of your requests, following the format of the script above.
Download as PDF

PREVIOUS
Send requests with Postman
NEXT
Job requests

Export

See what Devo can do for you. Request a demo!
Discover what's new (Release notes)
  • v7.5.0
    • v7.11.0 (latest)
    • v7.10.0
    • v7.9.0
    • v7.8.0
    • v7.7.0
    • v7.6.0
    • v7.5.0
    • v7.3.0
    • v7.2.0
    • v7.1.1
    • v7.1.0
    • v7.0.8
  • Services & Support
  • Devo.com
  • Contact
    • Contact Us
    • Request a Demo
    • Partner Inquiry
  • Log In
    • USA Devo
    • EU Devo
  • +1 888 6830910 (USA)
  • +34 900 838 880 (Spain)
Copyright © 2019 Legal Terms Privacy Policy Cookies Policy

Powered by Confluence and Scroll Viewport