Recently, we were addressing a requirement where we needed to work with a custom connector. We had an API that accepted GET & POST request methods. Some values were needed to be read in the request as query parameters. Scouring through the internet, we found no documented way to read the query parameters.
After some trial & error, a way to do so was discovered, and below is how to do it –
After creating a custom connector, under the Definition step, there is a button named – ‘Import from sample’ where we can insert the URL along with our parameters, and the query parameters will be generated automatically.
After clicking on Import from sample, a screen pops up where we can define the method, request URL, headers & body if any. In our example, the method was GET and the URL consisted of a query parameter called status.
Clicking on import, the request looked as below –
Once the query parameter is populated, the down arrow beside it is clicked, and the edit option is selected.
After clicking on edit, a screen pops up where for Default Value, we need to pass @queryParameters(‘status’) so that the value passed when the API is called can be read from inside of the API. Same way, we can also read the header values.
E.g., to send a custom header – Access Token in the API we will need to write @headers(‘Access-Token’)
After configuring the parameter, we would need an URL to which we will send the requests. To get the URL, within the Test tab, Test Operation is clicked. After the request is executed, the API URL is generated in the request section.
The URL is copied and pasted where one is hitting the request. For this demonstration, we are using Postman to execute the requests.
On sending the request, our custom connector is being called. The custom connector calls our API URL (host) along with the query parameters we have passed in the request. This returns the expected response. Here, we can see that we are getting a status 200 response.
This is how we can read ‘queryParameters’ dynamically while using custom connectors.