Table of Contents

Getting data from a public REST service

In this tutorial, we try to call a public REST service from a task in Bonita. The public service is available on https://www.boredapi.com/api/activity. This service returns a response in JSON format. We will create a business process (using Bonita) with a simple task. On this task, we create a connector that calls this service and parse the returned response.

Create business process to access the REST service and to process its response

  1. Using Bonita Studio, create a workflow as following.


  2. Set the details of the activities as following.

    Name Type
    Find something to do Service
    Get full response Human
    Get details Human
  3. Select the Pool. In Data tab, declare the following global process variables.

    Name Data type
    response Text
    activity Text
    type Text
    participants Integer
    price Double
    link Text
  1. At the Find something to do activity, select Execution→Connectors in.
  2. REST connector should already exist in your Bonita studio if you have already do the previous tutorial. If not, click on Access the bonita marketplace to install it.
  3. Once the installation is complete, click on Add. Select REST from the left panel and GET from the right panel, then Next.


  4. Name the connector as RestService_Connector, then Next.


  5. Set the GET URL to https://www.boredapi.com/api/activity, then Next.


  6. Keep clicking Next until reaching the Output Operations step shown below.


  7. Select the variable response from the first list to store the service response. Click on the pencil icon to edit the second list parameter.
  8. Set the script name to getResponse then add the following java code to the script editor.

    bodyAsObject.toString()
  9. Click OK.


  10. Select the variable activity from the first list. Click on the pencil icon to edit the second list parameter. Set the script name to getActivity and add bodyAsObject.activity to the script editor as following.


  11. By the same way, add the following parameters.

    First List Script name Java code to add in the script editor
    type getType bodyAsObject.type
    link getLink bodyAsObject.link
    price getPrice bodyAsObject.price
    participants getParticipants bodyAsObject.participants
  1. Click on Finish.


Design the UI forms of the "Response Processing" activities

  1. At the Get full response activity, we will design a simple form to visualize the service response. To do this, click on the activity, then Execution → Form. In Target Form, create a new Form called FullResponseForm.
  2. In the form page, drag and drop a Text area. Set its Label to Response as following.


  3. In the FullResponseForm page, click on create a new variable and fill the parameters as follows, then Save.


  4. Set the value of the Response text area to response.value.


  5. Save then close the form.
  6. At the Get details activity, we will design a simple form to visualize the service response in detail. Click on the activity, then Execution → Form. In Target Form, create a new Form called DetailsForm.
  7. In the form page, drag and drop 5 Text area labelled : Activity, Type, Participants, Price and Link.


  8. Select the Activity text area. Set its Value to activity.value.


  9. Select the Activity text area then create new variable. Fill in the parameters as follows, then Save.


  10. By the same way, change the Value and create new variable for each of the 4 other text areas. Follow the table below to set variable parameters.

    Text Area Value variable Name variable Type variable API URL
    Type type.value type External API ../API/bpm/caseVariable/{{task.caseId}}/type
    Participants participant.value participants External API ../API/bpm/caseVariable/{{task.caseId}}/participants
    Price price.value price External API ../API/bpm/caseVariable/{{task.caseId}}/price
    Link link.value link External API ../API/bpm/caseVariable/{{task.caseId}}/link
  1. Save the form, then close it.

Run the process

  1. Save the process, then Run.
  2. Start the Pool.
  3. Refresh the Task List. Now, you can see the service response in JSON format in the Response text area.
  4. Take the Get full response from your Task list, then submit.


  5. Now, you can see the service response in details.


  6. The service invited me to “Organize my pantry”, a “busy work” with only “one participant”. What about you! Which activity did it propose to you?