Jerry
Jerry

Reputation: 1007

Servicenow Rest API call to check if credentials are valid

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;
    }

Upvotes: 1

Views: 2053

Answers (1)

Tim Woodruff
Tim Woodruff

Reputation: 601

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.

Upvotes: 2

Related Questions