cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 7

Using Orion SDK

I'm brand new to Solar Winds and to using the Orion SDK.  As a POC, I'm trying to run a query via the API.  My initial request (which uses code I copied from GitHub) is as follows:

https://myserver:17778/SolarWinds/InformationService/v3/Json/

My result contains a Status Code of 403 (forbidden).  Here's my code, in C#, and yes I'm passing in valid credentials and hostname:

        private static void Main()

        {

                var swisClient = new SwisClient(Hostname, Username, Password);

                 const string query = @"SELECT TOP 1 AlertObjectID

                     FROM Orion.AlertActive

                     WHERE ISNULL(Acknowledged,0)!=1

                     ORDER BY TriggeredDateTime DESC";

                 JToken queryResult = swisClient.QueryAsync(query).Result;

                

                 var alertObjectId = (int)queryResult["results"][0]["AlertObjectID"];

        }

        public Task<JToken> QueryAsync(string query, object parameters = null)

        {

            return SwisCallAsync(client =>

            {

                var request = new JObject();

                request["query"] = query;

                if (parameters != null)

                    request["parameters"] = JObject.FromObject(parameters);

                HttpContent content = new StringContent(request.ToString(), Encoding.UTF8, "application/json");

                return client.PostAsync("Query", content);

            });

        }

private async Task<JToken> SwisCallAsync(Func<HttpClient, Task<HttpResponseMessage>> doRequest)

        {

            var handler = new WebRequestHandler

            {

                Credentials = new NetworkCredential(_username, _password),

                PreAuthenticate = true,

                ServerCertificateValidationCallback = ValidateServerCertificate

            };

            using (var client = new HttpClient(handler))

            {

                client.BaseAddress = new Uri(string.Format("https://{0}:17778/SolarWinds/InformationService/v3/Json/", _hostname));

                HttpResponseMessage response = await doRequest(client);

     // response variable (above line) ends up containing a json string with a StatusCode of 403

                var result = JToken.Load(new JsonTextReader(new StreamReader(await response.Content.ReadAsStreamAsync())));

                if (!response.IsSuccessStatusCode)

                {

                    throw new ApplicationException(string.Format("Server returned error: {0} {1}{2}{3}", (int)response.StatusCode,

                        response.ReasonPhrase, Environment.NewLine, result));

                }

                return result;

            }

        }

Any help would be appreciated.

Thanks!

0 Kudos
0 Replies