Appendix: Using the EXECUTE Element Tag
The EXECUTE element can be configured to make either a Get request or a Post request to a RESTful API. The data processed by this type of element is exchanged between the API and a local variable.
Get requests will also initialise a JSON data object with the same name as the keyword used to fetch the requested data.
Implementation:
- Click to open the Element Browser to the right of the window.
- Use the Filter menu to select Tags.
- Locate and select EXECUTE.
The element has the following syntax:
<%# EXECUTE(
Keyword
PostDataKeyword
RequestURL
[optional parameters as required]) %>
Parameters can be entered in any order. Where a parameter is not required, it should be excluded.
The following parameters are required:
Parameter | Description |
---|---|
Keyword | (Get requests only) The name of the keyword that will store the data fetched from the API. This will also be the name of the JSON object initialised by the request. |
PostDataKeyword | (Post requests only) The name of the keyword that contains the data to post to the API. |
RequestURL | The complete URL of the API you want to query, including any required query strings. |
The following parameters are optional:
Parameter | Description |
---|---|
IsAuthenticated | A Boolean that indicates whether the request must be authenticated using an identity service. If True is used, you must also provide security details according to the requirements of the API. The default value is True. |
IDSAuthority | The complete URL of the API's identity server. Required if IsAuthenticated is True. |
ClientID | A valid client identifier for the identity server. Required if IsAuthenticated is True. |
ClientSecret | A matching client secret for the identity server. Required if IsAuthenticated is True. |
Token | A valid access token. Only required if the API uses authentication and IsAuthenticated is False. |
Scopes | The scopes of your request, as required by the API. Only required if the API uses authentication and IsAuthenticated is False. |
IsAsync | A Boolean that determines whether the request is asynchronous. The default value is True. |
AsyncRendering | A message string that will appear to users while data is being fetched. Only applicable if IsAsync is True. |
AsyncMethod | The name of a JQuery method to call when a response has been received from the API. Only applicable if IsAsync is True. The default value is FetchData. |
TimeOut | The maximum length of time - in seconds - to wait for a response from the API. The default value is 10. |
The following tag will return all user information in the JSONPlaceholder API and store it in the keyword UserDetails. Because this API does not require any authorisation, no security details have been provided.
<%# EXECUTE(
Keyword="UserDetails"
IsAuthenticated="false"
RequestUrl="https://jsonplaceholder.typicode.com/users" ) %>