Jump to content

Authentication issues with this baseline C# API Code


DeWaynes

Recommended Posts

Posted (edited)

Hi,

I need assistance with getting this c# code to authenticate and list all devices.

I tried it with the username/password combo AND the token id/secret combo (token permissions are fully open)

I get the same error on both as seen here

{
  "Data": null,
  "Meta": {
    "TotalCount": 0,
    "ResponseCode": 403,
    "ErrorMessage": "A delegate registered to create instances of 'MM.Monitor.Application.ApiTokens.Services.Interfaces.IApiTokensDataService' returned null."
  }
}

Here's the Class in C#

using Newtonsoft.Json;
using RestSharp.Authenticators;
using RestSharp;
using System;


namespace Pulseway_Helper
{
    internal class GetDevices
    {
        private const string ENDPOINT = "https://api.pulseway.com/v3";
        private const string TOKEN_ID = "api_token_id_generated_in_pulseway";
        private const string TOKEN_SECRET = "api_token_secret_generated_in_pulseway";

        static void Main(string[] args)
        {
            // Create RestClientOptions and set the Authenticator
            var clientOptions = new RestClientOptions(ENDPOINT)
            {
                Authenticator = new HttpBasicAuthenticator(TOKEN_ID, TOKEN_SECRET)
            };

            // Initialize the RestClient with the options
            var client = new RestClient(clientOptions);

            // Create the request
            var request = new RestRequest("devices", Method.Get);

            // Add parameters to the request
            request.AddParameter("$top", "50");
            request.AddParameter("$skip", "0");

            // Execute the request
            var response = client.Execute(request) as RestResponse;

            // Get the content of the response
            var content = response.Content;

            // Deserialize the content
            dynamic result = JsonConvert.DeserializeObject(content);

            // Output the result (for demonstration purposes)
            Console.WriteLine(result);
        }
    }

}



 

ConsoleApp.cs

Edited by DeWaynes
Link to comment
Share on other sites

  • Administrators

Hey @DeWaynes

Thanks a mill for reaching out. 

Seeing as your request has a good bit of code, I'm going to open a support ticket for you so that our techs can review it better, so if it's not too much hassle please forward me your Pulseway email id so that I can CC you in the ticket and get your issue resolved!

Thanks 
Stefan 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...