Invoking Web services

You can invoke Web services in one of the following ways:

  • By using the Query Web services visualization

  • By using advanced watchers in Siren Alert.

  • Programmatically, by using scripts. Scripts can then be used in dashboards, as contextual actions on the graph, and for other purposes.

Using the Query Web services visualization

The Query Web services visualization can be used to invoke more than one service at a time. When all requests are resolved, a filter is applied to the dashboard to only show only the resulting documents.

image

Using advanced watchers in Siren Alert

Advanced watchers can be used to invoke a single service, periodically. To configure this method, you must add a web_service object to the condition object of the advanced watcher.

Specify the following details.

  • group: The name of the Web service group, for example, 'webhose'.

  • service: The name of the Web service (within the group) that you wish to invoke, for example, 'news'.

  • params: The parameters (mandatory and optional) that are required by the specified Web service, for example, query and language.

  • store: A boolean value that determines whether or not to store the invocation results in Elasticsearch

The following code is an example of how to write the web_service object in an advanced watcher:

"condition": {
  "web_service": {
      "group": "webhose",
      "service": "news",
      "params": "{ \"query\": \"Galway city\", \"language\": \"german\" }",
      "store": true
    },
    ...
}

For more examples of advanced watchers, see this link

Periodic invocation of Web services by using watchers works only without security.

Using scripts

You can invoke some Web services by using the Siren API.

In particular, variable-response Web services can only be invoked this way.

Create a script and add a specific function that you can call from any scripting context. For example, specify a function that is similar to the following:

// sirenAPI.invokeWebService(groupName, serviceName, params, [options])
await sirenapi.invokeWebService('webhose', 'news', { query: 'brexit' }, { storeData: false, returnData: true })

To invoke variable-response Web services, the invocationsOptions parameter must be set to { storeData: false, returnData: true }. While normal Web services can be instructed during invocation to store or not store the returned data in Elasticsearch, variable-response Web services can never have their data stored - only returned.