Bosch IoT Device Management - will be discontinued by mid 2024

Groovy HTTP Scripting API example

This page provides a real-life example of a rule which demonstrates a simple use case of our Groovy HTTP Scripting API.

The purpose of the action script is to send a GET request to an external endpoint and report the response as part of the rule's partial execution status.

Create the rule

You can learn the full rule creation possibilities from our Create a rule page. In this case you need to:

  1. Open Rules from the left navigation on the Bosch IoT Suite UI.

  2. Click the + icon on the right of the header bar.

  3. Type in a user-friendly name.

  4. To achieve the desired outcome, you need to execute the rule's groovy action script in the context of device scope. In the Type field select Device.

  5. The optimal approach to prevent unnecessary executions would be to use Device selection by ID. Select it and pick just one device from the Select devices blade that opens from the right.

  6. No specific Execution options are required.

  7. Click Next.

  8. Click the + icon in the Triggers blade.

  9. For simplicity, add a Manual Fire trigger and click Save. Again, proceed by clicking Next.

  10. On the Action step enter the Groovy script you intend to execute and click Finish.
    You can directly copy the Groovy script we use in this example:

    // define the basic HTTP request
    def httpRequest = httpClient.buildHttpRequest(HttpMethod.GET, '');
    // The request can include whatever is needed for your scenario such as:
    // httpRequest.putHeader('Content-Type','application/json')
    // httpRequest.timeout(6000)
    // etc...(see Java API documentation)
    // then you need to define the async processing of the response
    Closure processResponse = {result,error ->
    if (error != null) {
    throw new Exception(error)
    HttpResponse res = result as HttpResponse
    // you can add a DI method and execute a command on a device
    return 'http response code is: ' + res.statusCode()
    // you can send the request with a response handling callback
  11. Click Enable rule.


  12. Fire the rule.


See the result

To observe the result of your execution in detail:

  1. Once the value of Finished with success has increased, you can click on the link.

  2. This will open up the Executions UI feature, where you need to expand the execution to observe the partial executions.


    These partial execution statuses represent:

    • The execution state of the whole script.

    • The state of the specific REST call.

    • The state of the Closure.

  3. Furthermore you can open each partial execution to observe more details about it. Opening the last partial execution status i.e. the Closure one, will show you the response value we programmed in case of success. We can see that the code is 200:


Visit our Java API documentation for more technical information.