1

I am calling ServiceNow Rest API for tables in my application. I allow the user to enter their servicenow instance credentials and domain url in my application.

I want to know if there is a Simple API call which I can make to ensure that the credentials entered are valid.

Currently I am making a call to get sys_user table and making the check.

This call seems to take more time. Is there a simpler REST URL which I can use here?

public static HttpConnectionResponse checkConnection(String host, String username, String password) {
        String CHECK_URL = "/api/now/table/sys_user";
        HttpConnectionResponse response = new HttpConnectionResponse();
        String completeUrl = "https://"+host+CHECK_URL;
        HashMap<String, String> requestHeaders = ConnectionUtils.getDefaultInputHeader();
        Credential credential = ConnectionUtils.populateCredentials(username, password);
        try{
            response = HttpConnectorClient.getMethod(completeUrl, requestHeaders, credential);
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return response;
    }
Jerry
  • 840
  • 1
  • 13
  • 36
  • 1
    Hello, I'm looking to do that too. Problem with @TimWoodruff 's answer is that I don't now which table will be used, I have 0 control over ServiceNow Instance so I can't create create scripts/pages. I must use what is available by default in the Rest API. Did you find an answer ? – ewald Mar 24 '20 at 09:08
  • 1
    No I went with what I posted, the API which I have given as CHECK_URL is an api to get the user from their instance. It's a standard URL , hopefully you can also use the same. Same question I had asked in their community as well. Din't find any other way – Jerry Mar 24 '20 at 11:56
  • Ok thank you. I resorted do that too because there was no other options. But it bothers me to check connection to a table I am not 100% sure that I have access to. – ewald Apr 01 '20 at 13:17

1 Answers1

2

Why not just use any table or record that you've set to be accessible to any authenticated user, then make a REST API call with their credentials as the basic authentication credentials, to that resource? If you get the record rather than "access denied", the creds are valid. :-) You could even make a simple UI page, or better yet, a Processor, just for that purpose.

Tim Woodruff
  • 560
  • 3
  • 8
  • That's what I am doing currently, looking for a record from sys_user_set with sysparm_limit=1. I wanted to know if there is some method just for this purpose – Jerry Sep 25 '17 at 05:59