Servicenow Rest API调用以检查凭据是否有效

时间:2017-09-22 06:33:05

标签: rest servicenow servicenow-rest-api

我正在为我的应用程序中的表调用 ServiceNow Rest API 。我允许用户在我的应用程序中输入他们的servicenow实例凭证和域URL。

我想知道是否有简单API调用,我可以确保输入的凭据有效

目前我正在打电话来获取 sys_user 表并进行检查。

此电话似乎需要更多时间。我可以在这里使用更简单的REST URL 吗?

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

1 个答案:

答案 0 :(得分:2)

为什么不使用任何经过身份验证的用户可以访问的表或记录,然后使用其凭据作为基本身份验证凭据进行REST API调用?如果您获得记录而不是&#34;访问被拒绝&#34;,则信用证有效。 :-) 您甚至可以为此目的创建一个简单的UI页面,或者更好的是处理器。

相关问题