Connect to a Remote Service Using Custom Connector¶
Overview¶
This walkthrough demonstrates how to consume the Stack Exchange API by importing its OpenAPI specification to create a custom connector within the WSO2 Integrator: BI.
- Create a new integration project in Visual Studio Code.
- Add an automation artifact to define the integration flow.
- Create a Stack Overflow connection using an OpenAPI specification.
- Configure the connector to retrieve questions from Stack Overflow.
- Print the API response to the system console for verification.
Prerequisites¶
Before you begin, make sure you have the following:
- Visual Studio Code: Install Visual Studio Code if you don't have it already.
- WSO2 Integrator: BI Extension: Install the WSO2 Integrator: BI extension. Refer to Install WSO2 Integrator: BI for detailed instructions.
- OpenAPI definition file: Download or prepare the OpenAPI specification file for Stack Exchange API (for example, stackexchange.yaml).
Step 1: Create a new integration project¶
WSO2 Integrator: BI extension provides a low-code graphical environment to visually design and deploy integrations.
- Launch VS Code and click the WSO2 Integrator: BI icon on the left sidebar.
- Click the Create New Integration button to open the project creation wizard.
- In the Integration Name field, enter
stackoverflow. - Choose a project directory by clicking Select Path.
- Click the Create Integration button to initialize your integration project.
The integration project will be created and ready for further configuration.
Step 2: Create a new automation¶
In this step, you will add an Automation artifact to your integration, which allows you to define logic that can be executed periodically or manually.
- In the Design view of your
stackoverflowintegration, click the + Add Artifact button. - Under the Automation section, select Automation.
- In the Create New Automation form, click the Create button to finalize the artifact creation.
- The Diagram view will load automatically, displaying the starting point of your automation flow with a Start node and an Error Handler.
Step 3: Create Stack Overflow connection¶
In this step, you will generate a Stack Overflow connection using an OpenAPI specification to integrate with the Stack Exchange API.
- In the Automation diagram view, click the + icon on the flow line between the Start and Error Handler nodes.
- In the right-side palette, select Add Connection.
- In the Add Connection overlay, click OpenAPI under the Connect via API Specification section.
- In the Connector Configuration form, configure the following:
- Connector Name: Enter
stackOverflow. - Import Specification File: Click to browse and select your local OpenAPI definition file (e.g.,
stackexchange.yaml).
- Connector Name: Enter
- Click Save Connector.
- On the Create Connection screen, review the Connection Details.
- Click Save Connection to finalize the setup.
Note
Completing these steps creates the Stack Overflow connection. As part of this process, the related connector is also generated automatically.
Step 4: Configure the Stack Overflow operation¶
In this step, you will use the connection actions to retrieve data from the Stack Exchange API.
- In the Automation diagram view, click the + icon on the flow line after the Start node.
- In the right-side palette under the Connections section, select the stackoverflowClient you created in the previous step.
- From the list of available actions, select List Questions.
- In the Operation Configuration pane, ensure the following:
- Result: The variable name
httpResponseis automatically assigned to capture the API response.
- Result: The variable name
- Click Save to add the operation to your integration flow.
- The diagram will now display the get node linked to the stackoverflowClient, representing the remote API call.
Step 5: Print the API response¶
In this step, you will add a function to print the JSON payload received from the Stack Overflow API to the system console for verification.
- In the Automation diagram view, click the + icon on the flow line after the get node.
- In the right-side palette, select Call Function.
- In the Functions library, scroll down to the Standard Library section and select println under io.
- In the io : println configuration pane, click the + Add Item button.
- Click the f(x) icon in the input field to open the expression editor.
- Navigate to Variables and select httpResponse.
- In the expression field, update the text to
httpResponse.getJsonPayload()to extract the JSON data from the response object. - Click Save to add the print statement to your automation flow.
Step 6: Run and test the application¶
In this final step, you will execute the automation and verify that the integration successfully retrieves and prints data from the Stack Overflow API.
- Select the Run icon (green play button) in the top-right corner of the editor to start the service.
- Wait for the integrated terminal to open at the bottom of the screen.
- The terminal will display the status
Executing task: bal runfollowed byRunning executable. - Verify that the JSON payload containing Stack Overflow questions is printed to the console as expected.
Success
You have now successfully integrated with the Stack Exchange API using a low-code approach. The setup is completed by creating both the connection and its connector. The API response is printed to your console, and your automation is ready for further enhancements or deployment.