Outbound SFTP Integration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:39 AM
Hi Developers,
We need to do Outbound Integration for files from ServiceNow are being able to be picked up and sent to vendor via SFTP integration.
How we can achieve this?
Any helpful video or documentation is also much appreciated, Thanks in advance
Regards,
Krishnakant Yadav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 03:07 AM
I am also looking the videos or documentation if anyone have good guids on that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 03:29 AM
Hi @krishnakant,
Integrating ServiceNow with an outbound SFTP (Secure File Transfer Protocol) server involves setting up a secure connection to transfer files from ServiceNow to an external SFTP server. Here’s a step-by-step guide to achieve this integration:
Prerequisites
1. SFTP Server Details: Obtain the hostname, port, username, and password (or SSH key) for the SFTP server.
2. SSH Key Pair: If using SSH key-based authentication, ensure you have the private key ready.
Step 1: Install the SFTP Integration Spoke (Optional)
ServiceNow offers an IntegrationHub SFTP Spoke that simplifies SFTP operations. If you have IntegrationHub available, consider using it.
- Navigate to System Applications > All Available Applications > All
- Search for SFTP Spoke and install it.
Step 2: Create a Credential Record
1. Navigate to Connections & Credentials > Credential Aliases
2. Click New and create a new credential alias (e.g., `SFTP_Credential`).
3. Select the Credential Type: Choose either Basic Auth or *SH Key Auth based on your authentication method.
4. Fill in the Credential Details:
- For Basic Auth: Provide the username and password.
- For SSH Key Auth: Provide the username and upload the private key.
Step 3: Create an Outbound REST Message
1. Navigate to Outbound > REST Message
2. Click New to create a new REST message.
3. Fill in the details:
- Name: Give a meaningful name (e.g., `Outbound SFTP Integration`).
- Endpoint: Use the format `sftp://hostname:port/path/to/directory`.
Step 4: Add HTTP Methods for REST Message
1. Click on New under the HTTP Methods section.
2. Define HTTP Method Details:
- Name: e.g., `UploadFile`.
- HTTP Method: POST.
- Endpoint: `sftp://hostname:port/path/to/file`.
- Authentication Type: Select the previously created credential alias.
3. HTTP Request:
- Set the content type to `multipart/form-data` or `application/octet-stream` depending on the file type.
- Use the `request body` to pass the file content.
Step 5: Scripting the File Transfer
1. Navigate to System Definition > Script Includes
2. Create a New Script Include to handle file transfers.
Here is a script for uploading a file:
var SFTPIntegration = Class.create();
SFTPIntegration.prototype = {
initialize: function() {},
uploadFile: function(fileContent, fileName) {
var request = new sn_ws.RESTMessageV2('Outbound SFTP Integration', 'UploadFile');
request.setRequestBody(fileContent);
request.setStringParameter('fileName', fileName);
var response;
try {
response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info('File uploaded successfully. Response: ' + responseBody + ', Status: ' + httpStatus);
} catch (ex) {
var message = ex.getMessage();
gs.error('Error during file upload: ' + message);
}
}
};
Step 6: Testing the Integration
1. Upload a Test File:
- Use the Script Include or a Business Rule to trigger the file upload.
- Ensure the file content and file name are correctly passed to the script.
var sftp = new SFTPIntegration();
var fileContent = 'Sample file content';
var fileName = 'testfile.txt';
sftp.uploadFile(fileContent, fileName);
2. Check the Logs:
- Navigate to System Logs > System Log> All
- Verify the file upload status and troubleshoot any errors.
Considerations
- Error Handling: Implement comprehensive error handling to capture and log errors during file transfer.
- Security: Ensure credentials and sensitive information are securely managed.
- File Management: Consider file size limitations and ensure proper management of file transfers.
By following these steps, you can successfully integrate ServiceNow with an outbound SFTP server, enabling secure file transfers from your ServiceNow instance.
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 03:37 AM
Thanks for the reply , I am new to this integration , i want to know what all methods we can use for SFTP integration file transfer .
Is it via mid server , transform map , power shell etc @Yashsvi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 03:53 AM
Hi @Dimple1107,
Integrating ServiceNow with an SFTP server for file transfer can be achieved using several methods, depending on your specific requirements and the capabilities of your ServiceNow instance. Here are the main methods you can use:
- MID Server: Provides flexibility and can handle complex network scenarios.
- IntegrationHub and SFTP Spoke: Simplifies the process with out-of-the-box actions.
- Transform Map and Data Sources: Suitable for data import scenarios.
- PowerShell: Useful for leveraging existing PowerShell scripts and running them via MID Server.
Choose the method that best fits your use case, considering factors like network setup, existing infrastructure, and ease of implementation.
Thank you, please make helpful if you accept the solution.