Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Outbound Integration not working

sainath3
Giga Guru

Hi Everyone,

 

I am working on Outbound Integration.

Using OAuth2.0

 

For Grant_type Password: I clicked on Get OAuth Token --> I have entered correct UserName & Password, got the Access token & Refresh Token.

when am clicking on test: Am receiving error "Invalid username/password combo".

 

Can anyone Help me.

10 REPLIES 10

Hello, i think the issue is either with token or user/pass, try this script for token

getToken: function() {
        var oAuthClient = new sn_auth.GlideOAuthClient();

        var params = {
            'grant_type': 'password',
            'username': 'user',
            'password': 'password'
        };

        var json = new global.JSON();
        var text = json.encode(params);

        var tokenResponse = oAuthClient.requestToken('your_app_registry_name', text);
        var token = tokenResponse.getToken();
        var accessToken = token.getAccessToken();
        return accessToken;
    },

Hi @sainath3 

What is your outbound triggering scenario?

  1. Create Application Registries
  2. Create Oauth entity profile for the same Application Registries
  3. Under Oauth profile or Registries add Oauth entity scop name and ouath scope(if already there than check the value either its matching with the end user or not). 
    • Based on the Grant type you need to check it.
  4. Access Token vs. Test Credentials

    • The "Get OAuth Token" step uses the credentials to get a token — if that worked, the credentials are likely correct.
    • The "Test" button in the Outbound REST Message might be using different credentials or not using the token properly.
  5. Verify REST Message Configuration

    • Go to System Web Services > Outbound > REST Message.
    • Open your message and check:
      • Authentication type is set to OAuth 2.0.
      • The correct OAuth Profile is selected.
      • No conflicting Basic Auth headers are present.
  6. Check the Token Scope

    • Some APIs require specific scopes in the token.
    • If the token lacks required scopes, the API may reject it with a misleading error like "Invalid username/password".
  7. In the header of HTTP method you can just pass the content type.
  8. Under The method related link you can click on the "Set HTTP log level" and select all.
    • This is to check what data are you sending to the end url.
    • You can open outbound http request from the system log and check.
  9. In BR the script syntax:
try {
        var r = new sn_ws.RESTMessageV2('Rest message name', 'Method'); // provide your rest message name and the method type like POST
        r.setEndpoint('your endpoint'); // set your end point
        r.setRequestBody(JSON.stringify(body)); // which data do you want to send you can pass it

        var response = r.execute();
        //response.waitForResponse(5);
        var responseBody = response.getBody();
        var httpStatus = response.getStatusCode();
        outputs.responsebody = responseBody;
    } catch (ex) {
        var message = ex.message;
    }
  • please check with the bracket open and close.
  • In the script no need to pass the access token again as in ServiceNow while calling the endpoint it will append it automatically.
  • Now you can check it.

In the test run generally it will take your login credential from the system

Try Manual Test with Postman

  • Use the same token in Postman to test the API call.
  • If it works in Postman but not in ServiceNow, the issue is likely in how ServiceNow is sending the request.
Your feedback makes the community stronger! If you found this helpful, marking it as the correct answer helps others.
Stay awesome,
Roshnee Dash

Hi @sainath3 
If you found my response helpful, please mark it as correct and close the thread so others can benefit from it too.

Your feedback makes the community stronger! If you found this helpful, marking it as the correct answer helps others.
Stay awesome,
Roshnee Dash

Abhijeet_Pawar
Tera Guru
Tera Guru

Hello @sainath3 
Could you please check if your endpoint is correct? I faced a similar issue last time and discovered that the endpoint was slightly incorrect. Kindly cross-check it once  I believe this might resolve your issue.

Thank You