Calculator - Profile chain time-driven with HTTP output

Up to this point, the data has been received and processed via the integrated HTTP server. In the next example, the goal is to trigger a time-controlled, static request via JSON to the calculator service. The JSON response of the calculator service is processed and converted into a CSV.

Step 1 - Adjust "Main settings"


You are welcome to clone an existing profile again. The following settings must be made in the "Main settings":


  • Document type: "JSON".

  • Encoding: "UTF-8".

  • Mapping type: "Mapping".

  • Adjust the profile name, e.g. "Lobster_Tutorial_HTTP_calculator_cron_json".

images/download/attachments/137305192/ex4_basis_data-version-2-modificationdate-1686650164663-api-v2.png

Step 2 - Configure phase 1


images/download/attachments/137305192/ex4_phase1-version-2-modificationdate-1686650197822-api-v2.png


  • Input Agent: Scheduled HTTP

  • URL of profile Lobster_Tutorial_HTTP_calculator_json_body, e.g. http://localhost:80/dw/Request/calculator_json_body

  • HTTP method: POST

  • Mime type: application/json

  • Data in body of POST request.


Body of request
{
"OP1": 42,
"OP2": 24,
"OPR": "+"
}


In phase 1 of the time-controlled HTTP Input Agent, MSG_CALL variables can be used to design requests dynamically, e.g. the query part of the URL or in the header or body of the data.

In particular, dates ('from' or 'to') must occasionally be specified. Unfortunately, the current date cannot be defined as a system constant. Placeholders, such as <yyyy>, do not lead to substitution in the scheduled HTTP Input Agent (status version 4.1). Alternatively, this information can be calculated in a preceding profile via functions and stored and passed on in MSG_CALL variables.

Step 3 - Mapping


The source structure consists of a single field. Using a 1:1 mapping, a Created_TopLevel_Node with a RESULT field below it is created in the target structure.


images/download/attachments/137305192/ex4_phase3-version-2-modificationdate-1686650237644-api-v2.png

Step 4 - Integration Unit in phase 5


An Integration Unit is not required in this profile. It can therefore be deactivated in phase 5.

Step 5 - Configure Response in phase 6


The Response saves the file as received as a backup. You can see the result in the log overview of the Control Center.


Output - for the record
{
"RESULT": "66"
}

Notes - Dynamic request in cron job


For experts.

In this example, a simple case with a static HTTP request was considered first. In other cases, variable values are expected in a scheduled HTTP job, either as query parameters or in the body.

Let's assume you need a GET call (for the POST method this is similar in principle) in the form https://some.rest.api/myquery?customerFrom=....&customerTo=.... where the values of the parameters customerFrom and customerTo depend on different conditions for each call. You can solve this with a profile chain:


  • Create a profile with the corresponding conditions for the values.

  • Phase 1: Scheduled Input Agent - Custom class DummyDataCron.

  • Phase 3: Create the variables var_customerfrom and var_customerto (please adapt names to requirements) and assign them with the values (e.g. by means of functions) that are needed for the call.

  • Phase 6: Response of type "Message" witch Content "Trigger profile" specifying the profile to be called (in this case the scheduled profile with the HTTP Input Agent)


The called profile is configured or adjusted as follows:


  • Main settings: Encoding: UTF-8

  • Phase 3: Creation of two new variables with the prefix "MSG_CALL_" and the names assigned in the parent profile, in this case MSG_CALL_var_customerfrom and MSG_CALL_var_customerto.

  • Phase 1: Adapt URL https://some.rest.api/myquery?customerFrom=@MSG_CALL_var_customerfrom@&customerTo=@MSG_CALL_var_customerto@


The parent profile can be configured in phase 1 with the times at which the process should run. When the cron profile is triggered, the HTTP response is processed.