barrycarey / SnipeSharp

A c# wrapper for the Snipe IT API
25 stars 30 forks source link

Question: Quick way to check if API/URL is valid and can connect. #13

Open azmcnutt opened 5 years ago

azmcnutt commented 5 years ago

Hi Barry and the group. I was just curious if there was a quick way with SnipeSharp to verify that the API and URL settings are valid, and the server is reachable?

cofl commented 5 years ago

One quick way would be to submit a junk query, like this:

try
{
    if(snipe.AssetManager.FindAll(new SearchFilter { Limit = 0 }).Total == 0)
    {
        // token is wrong, or URL might be wrong, assuming you have assets in your system.
    }
} catch(JsonReaderException ex)
{
    // base url is really wrong, no idea about the token
}