Update currency exchange rates with web service integration
Creatio uses a special business process element to call web services and parse their response.
Create a business process that will obtain currency exchange rates from the http://api.fixer.io/ web service and update exchange rates on the Currency rate detail of the Currencies lookup.
Detailed instructions on setting up integration with the http://fixer.io/ web service are available in a separate article.
Business process diagram (Fig. 1) elements:
-
Business process custom parameter: "Base currency," which contains the current value of the Base currency system setting.
-
Timer start event: "Start every night" – the process starts daily, at the specified time.
-
Read data system action: "Read base currency" – the process obtains the current base currency name.
-
Call web service system action: "Get currency exchange rate from the Fixer web service" – the process calls web service request method "latest" to obtain exchange rates for the current base currency. The element has 2 outgoing conditional flows:
- "Success:" the process proceeds to updating the exchange rates if response from the web service has been received.
- "Error:" the process will terminate if web service call resulted in error or timed out.
-
Add data system actions: add one for each currency whose rate must be modified. For example, "Add EUR exchange rate" – The process adds a record on the Currency rate detail for each currency whose rate must be updated. The Exchange rate field for each record contains the corresponding exchange rate received from the web service.
-
Parallel gateway AND : this gateway will ensure that the process will end only after all currency rates have been updated.
Before using the Call web service element, make sure that you set up integration with the needed web service, using the Web services section in the Studio workplace. Learn more about adding the http://fixer.io/ web service integration in the Getting started with low-code web service integration article.
To configure the process:
-
Use a custom parameter to pass the current "Base currency" system setting value to the business process.
-
Click , then click Parameters tab and Add parameter button. Select "Lookup" parameter type (Fig. 2).
-
Populate parameter properties (Fig. 3):
- Populate Title and Code properties.
- In the Lookup field, select the Currency lookup.
- In the Value field, click > System setting and select the Base currency system setting.
-
-
Set up the "Start every night" element properties:
- In the Frequency of process start field, select "Day."
- In the Run every field block, specify "1 day in 1:30 AM."
- Select your time zone and configure other optional properties, if needed.
-
Set up the "Read base currency" element properties (Fig. 5):
-
In the Which data read mode to use? field, select "Read the first record in the selection."
-
In the Which object to read data from? field, select the "Currency" object.
-
Set up the following filter in the How to filter records? area: "Id = Base currency." In this case, "Base currency" is the name of the custom process parameter that you added earlier.
noteTo set the filter: click Add condition, select the Id column; click <?> and select Compare with parameter command; in the Select parameter window, click Process parameters tab and select the "Base currency" parameter that you added earlier.
-
In the What record data should the process read? field, select "Read data from selected columns only."
-
Click Add column link and select the Short name column to have the process read the base currency short name (USD, EUR, etc.) from the lookup.
-
-
Set up the "Get currency exchange rate from the Fixer web service" element properties (Fig. 5):
-
In the Which service to call? field, select "Currency exchange rate (Fixer)."
-
In the Which method to call? field, select the "Get latest exchange rates" method.
noteThe http://fixer.io/ web service does not require authentication, so you can use a single Call web service element to obtain the response with the required data. If web service requires authentication, then in addition to the request methods for obtaining the necessary data, you need to set up authentication methods. In a process diagram, you will need to add at least two Call web service elements: the first one calls the authentication method, and the second Call web service element calls the needed functional method, while passing authentication cookie, session Id, etc. as a request parameter.
-
Populate the request parameter values:
- Map the Base Currency parameter to the base currency short name, obtained by the "Read base currency" element. To do this, click > Process parameter and select the Read base currency element and its parameter Short name.
- Specify the value of the Endpoint parameter. For the purposes of this process, using the "latest" endpoint will be enough. Enter "latest" value manually.
-
-
Add an outgoing conditional flow to the Parallel gateway (AND). Set up the condition for moving down this flow only if the outgoing Success parameter of the "Get currency exchange rate from the Fixer web service" element is "true:"
- In the Condition to move down the flow field, click .
- In the opened Formula window, on the Process elements tab, select the Get currency exchange rate from the Fixer web service element.
- In the right side of the window, double-click the Success parameter.
- Add "==true" text after the parameter variable, so that the whole formula text looks like this: #Get currency exchange rate from the Fixer web service.Success# ==true
-
Add an outgoing condition flow to the Terminate signal. Set up the condition for moving down this flow only if the outgoing Success parameter of the "Get currency exchange rate from the Fixer web service" element is "false." This way, if the web service call ends in error, the process will terminate (Fig. 6).
-
Add an Add data element for each exchange rate that must be updated. For example, to update Euro exchange rate, "Add EUR exchange rate" element properties (Fig. 7):
As a result, the process will automatically start every day, at 1:30 AM, and:
The process will terminate if the web service call results in an error.
- check current base currency
- call web service for exchange rates in relation to the base currency
- write the updated rates for the selected currencies (in this particular case, Euro, Australian dollar and Ruble) on the Currency rates detail of the Currency lookup (Fig. 8).
See also
Getting started with low-code web service integration