I want to be able to determine the URL parameters of a REST GET call in a call template. Is this possible with the current call templates, and if so: how?
Hey Remy,
that’s possible with the current versions of M10074 and M7899
In general, calls are being executed by using the process ‘N_Call Template Build, Execute, Process’. This process has a parameter called ‘parameters’ of type ‘List<Tuple<String,Mixed>>’.
For calls like POST, PUT etc. this parameter is used to build a body.. For GET calls, this list can be used to build up a dynamic URL.
See the steps below for an example:
Using query parameters in GET calls
-
Create a call template for a GET call. As an example, I use the free weather API from open-meteo.com by calling https://api.open-meteo.com/v1/forecast
-
I want to get the temperature for Hamburg, so I have to pass the following query parameters:
- latitude = 53.5507
- longitude = 9.993
- hourly = temperature_2m
- To pass these to the process, I first have to rewrite the key-value pairs in the format of a ‘List<Tuple<String,Mixed>>’. The format looks like this “[ <“key1”,“value1”>,<“key2”,“value2”> … ]”, so in our example we get:
[ <“latitude”, “53.5507”>, <“longitude”, “9.993”>, <“hourly”, “temperature_2m”> ]
- Then, I execute a test call with the test panel:
- The call is executed successfully and contains the correct query parameters:
- For your custom use case, make sure to pass the list of tuples to the process “N_Call Template Build, Execute, Process”. You can do so for example by configuring a scheduled task. Here, you can define an expression for the “parameters” list, which dynamically determines the correct parameters per execution.
Using path variables in GET calls
Maybe the steps above are not enough to complete your goal. As you can see, the base URL “https://api.open-meteo.com/v1/forecast” is static and remains unaffected. But what if we also want to call “https://api.open-meteo.com/v1/dwd-icon” for weather data from the German weather service (DWD) with the same call template?
We can extend the base URL of a call template by using a “path variable”.
- Create a call template and set the fixed base URL that won’t change. In our example, that is “https://api.open-meteo.com/v1”.
- Then we define a parameter list, like above, but with a new special item:
[ <“latitude”, “53.5507”>, <“longitude”, “9.993”>, <“hourly”, “temperature_2m”>, <“n_pathvariable”, “forecast”>]
- The key “n_pathvariable” is a special hard-coded key. Its value is evaluated and then added to the base URL with a “/”. So, when I execute a test call, I get the same result as in the previous example.
- To toggle between “forecast” and “dwd-icon” one simply has to change the value of the “n_pathvariable” item to “dwd-icon”
[ <“latitude”, “53.5507”>, <“longitude”, “9.993”>, <“hourly”, “temperature_2m”>, <“n_pathvariable”, “dwd-icon”>].
- The resulting call looks like this:
By the way, if the options above are not enough, you can execute a call template process after building the call.
This would allow you to execute an “Add/Edit” action in the context of the N_Call to modify the URL of the call right before it is executed. This way you can set any expression you want as the URL.
Hey! A question that relates to this:
I want to have a url parameter like this: baseurl/policies/{identifier}/cancel
The identifier is a field of a record which I have acces to via a workflow configuration. My plan is to trigger the Build, execute call from that workflow.
I tried the call template processes functionality, but the context is alway N_Call, so I don’t have acces to that field. If I would have, I could have taken the url.contact(“/identifier”).concat(“/cancel”).
Does anyone know of a way to do this?