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;
    }
3
  • 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 ? Commented Mar 24, 2020 at 9: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 Commented Mar 24, 2020 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. Commented Apr 1, 2020 at 13:17

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.