Poll a Directory Using a Trigger Task from ServiceNow

In this example, you call a Trigger Task from ServiceNow to poll a directory for files of a specific type.

Download this Pipeline

To make this example work, you must perform the following tasks:

  1. Create a pipeline that receives specifications from ServiceNow on the file type for which you want to poll a directory.
  2. Create a Trigger Task that will make the pipeline available as a REST API.
  3. Create a REST call in ServiceNow that will trigger the Task created in Step 2 above.

Create the File Poller Pipeline

You design a pipeline containing the following Snaps:
  • CSV Parser : Parses the data coming in from ServiceNow as a CSV document.
  • Mapper: Makes the contents of the input CSV document available as a parameter.
  • File Poller : Polls a specific directory for files matching the pattern specified in the parameter received from the Mapper Snap.

You will note that the File Poller has open input and output views. This is because it receives data from the Trigger Task associated with it and returns processed data back to the same Trigger Task.

CSV Parser : Use the CSV Parser Snap with the default settings:



Mapper: Configure the Mapper Snap to receive the parsed CSV data and map the message in the CSV document to the $msg variable:



File Poller : Configure the File Poller Snap to poll the /QA/Documentation/File Poller/ directory for all files that match the pattern contained in the $msg variable, which you use as a file filter parameter:

Create a Trigger Task for the File Poller Pipeline: Save the pipeline, click the button, and configure the Trigger Task:

Click Update to complete setting up the task; then navigate to the Manager to view the Trigger Task's properties:

You copy the Cloud URL and authorization bearer token, and navigate to ServiceNow to set up the API call.

Create a REST call in ServiceNow:Create a REST Call in ServiceNow by appending the authorization token to the Cloud URL that you copied in the previous step:
<Cloud_URL>?bearer_token=<Bearer_Token>


For details on how to set up REST calls using ServiceNow, see ServiceNow documentation.

While configuring the REST call, ensure that:
  • HTTP Method is POST.
  • Endpoint contains the Cloud URL concatenated with the bearer token.
  • HTTP Parameters > Content contains the variable and extension value that you want to use.
You click Test to check the REST call. For a successful execution, the pipeline returns a list of files whose extension matches the value in the Content field:

Downloads

Note: To successfully reuse pipelines:
  1. Download and import the Pipeline into SnapLogic.
  2. Configure Snap accounts as applicable.
  3. Provide Pipeline parameters as applicable.