How to pass Basic Auth credentials to SOAP envelope

mballinger
Mega Guru

Hello,

 

I have a SOAP integration setup and all works well. My issue is, I am trying to pass Basic Auth credentials to the envelope. How can I do this? 

 

Also, I would like to use basic auth credentials via script when making this reference in a flow I have configured.

 

Thanks!

1 ACCEPTED SOLUTION


To pull the password from the basic auth profile instead of hardcoding it, you can use the setAuthenticationProfile method instead of setBasicAuth. Here's how you can do it:

- First, ensure that you have an authentication profile set up in ServiceNow. You can do this by navigating to System Web Services > Outbound > Basic Auth Profile.
- Create a new record and fill in the necessary details such as Name, Username, and Password.
- Once the profile is set up, you can use the setAuthenticationProfile method in your script. Here's an example:

javascript
try {
var s = new sn_ws.SOAPMessageV2('DAM', 'login');
// Use authentication profile
s.setAuthenticationProfile('basic', 'your_auth_profile_name'); // 'your_auth_profile_name' is the name of the basic auth profile you created
var response = s.execute();
var responseBody = response.getBody();
var status = response.getStatusCode();
} catch(ex) {
var message = ex.message;
}


In summary:

- Create a Basic Auth Profile in ServiceNow with the required credentials.
- Use the setAuthenticationProfile method in your script, passing 'basic' as the first argument and the name of your auth profile as the second argument.
- This method will automatically use the username and password from the specified auth profile, eliminating the need to hardcode these values in your script.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

View solution in original post

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@mballinger You can use setBasicAuth(String userName, String userPass) method to set the credentials on the SOAP envelope.

 

For more information, please refer to https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server/sn_ws-namespace/c_SOAPMessa...

@Sandeep Rajput Thank you for your response! My issue is the vendor I am trying to hit needs a username password to be passed.