Hi everyone, I hope you’re all doing well.
I’d like to know if there is a simple way to define or retrieve a subpath from the request URL when triggering a User-Defined API, without having to create every route in the System Center page.
For example, I have created the route api/custom/devices, which returns device information from an element table. However, I would also like to have a route such as api/custom/devices/status, where only the current device’s status parameter is returned.
The idea was to avoid creating every route manually in System Center. Instead, we defined a single base route (e.g., /devices) and handled any requested subroutes (such as /devices/status) dynamically within the script.
Hi João,
Like Rene hinted at in his comment, it is possible to code all your API behavior in one script and check the 'requestData.Route' to see what route was triggered. This way you could either return all devices, or return the status. You will however have to create an API definition for each route that you want to trigger (that can then all point to that one script). It is currently not possible to have dynamic/catch-all like routes.
Thanks for the reply, Thomas! I was looking for something like the example Matthias showed. I know we can use the same script and tokens for multiple API routes, but what I was trying to avoid was manually creating and configuring the routes through System Center.
Note that with the example of Matthias, you'll still need to manually define multiple routes through system center. As mentioned, there is no way yet to define a prefix and have any API triggered with that prefix be handled by a script. The closest you could get is by automating the API definition creation by using the 'UserDefinableApiHelper' in an automation script. https://docs.dataminer.services/dataminer/Functions/User-Defined_APIs/Defining_an_API/UD_APIs_Creating_in_code.html
Understood. I will review this section of the documentation and combine it with the example provided by Matthias. Thank you for the clarification.
Hi João – are you trying to execute the same script and want it to return a different result based on the route? If so, you could instruct the script what to return (e.g., devices or status) in the body of the request.