All docs This doc
Skip to end of metadata
Go to start of metadata

connector allows you to invoke a third-party product's functionality from the WSO2 Enterprise Service Bus (ESB) message flow, enabling you to connect to and interact with the APIs of services such as Twitter, Salesforce, and JIRA. For example, if you enable the Twitter connector in your ESB instance, your message flow can call the Twitter APIs. You can receive requests containing a user's Twitter name and password, log into the user's Twitter account, get a list of his/her followers, and write that information to a Google spreadsheet. You can also use one or more connectors to manage complex business use cases.

In this tutorial, you use the Twitter connector from the WSO2 Store to invoke Twitter's Verify Credentials API using an application deployed in WSO2 Integration Cloud.

Before you begin,

  • Go to and create an account if you do not have one already.
  • Download the WSO2 Twitter ESB connector from here. You can also go to WSO2 Store at, search for the word "Twitter", and download the Twitter connector that appears under ESB Connectors.
  • Install cURL on your machine if you do not already have it installed (you will use this to test the application by sending a sample request).

Let's get started!

Creating a Twitter application

To use Twitter APIs, you first create a Twitter application through which you authenticate yourself and communicate with Twitter.

  1. Go to  and click Create New App.

  2. Enter the following information in the form that opens, scroll down, and click Create your Twitter application.

    NameTwitterESBConnect (or any other name of your choice)
    DescriptionVerifies credentials and retrieves user's details.

  3. Click the application to open it, go to its Permissions tab, select the Read, Write  and Access direct messages option, and click Update Settings.

  4. Go to the application's Keys and Access Tokens tab and generate a consumer key and secret pair and an access token by clicking the respective buttons. These tokens are required to authenticate any application/API that tries to invoke the Twitter APIs.
  5. Copy the following values, as you will need them later in this tutorial.
    • Consumer Key
    • Consumer Secret
    • Access Token
    • Access Token Secret
    You have now created a Twitter application. Let's proceed to create a REST API that reads Twitter's APIs.

Developing a REST API to connect to the Twitter application

Let's use the WSO2 ESB Tooling environment to develop our REST API. WSO2 ESB Tooling provides user-friendly, configuration-driven development capabilities. Based on the Eclipse development environment, its simple graphical editor is ideal for developing and managing services, features, and artifacts.

  1. Click the Tooling link on

  2. From the dialog box that opens, click the Download button, and select a tooling build that suits your OS. We recommend that you use the complete plug-in installation with pre-packaged Eclipse, so that you do not have to install Eclipse separately.

    Tip: If you cannot figure out which ESB Tooling package to download, click here.

  3. Extract the tooling package and run Eclipse either by double-clicking the Eclipse icon or navigating to the extracted folder using the Command-line/Terminal and running the ./eclipse command.

    Tip: If you get any errors when you try to start Eclipse, such as the file being damaged or unable to be opened, see this.

  4. The Eclipse user interface opens. Click the Developer Studio -> Open Dashboard menu at the top, and then click the ESB Solution Project link.

    Tip: An ESB Solution Project is a combination of several project types. It allows you to save different artifact types under one project. For example, if your project requires an ESBConfig‬, registry resource‬, connector exporter,‬ and a composite application, create an ESB Solution Project instead of creating each type of project separately.

    For more information about WSO2 ESB project types, see Working with ESB Artifacts.

  5. In the dialog box that opens, give a name for the project (in this tutorial, let's call it TwitterConnectPrj), and click Finish.

    Next, let's add the Twitter connector to the project that you just created. 

  6. Back in the Eclipse UI, right-click the main configuration project (i.e., TwitterConnectPrj), and click Add or Remove Connector.
  7. In the dialog box that opens, click the Add connector option, click Next, give the location of the Twitter connector that you downloaded in the Before you begin section at the beginning of this tutorial, and click Finish.

    You have now added the connector to your project. Next, let's create the REST API. 
  8. Right-click the project that you just created and click New-> REST API from the popup menu.
  9. Select the Create a New API Artifact option from the dialog box that opens, click Next, enter the following details, and click Finish.
    • Name: TwitterConnectAPI
    • Context: /twitterconnect 

    After creating the API, the Twitter connector operations will be available in the tools palette. You can drag and drop connector operations into your API in the Design view. Let's do that next.
  10. In the Project Explorer, click the API you just created, go to the Design tab, and drag and drop the init operation from the Twitter Connector folder in the tools palette to the canvas on the right.

    Tip: You can go to the Source tab to see the code being auto-generated every time you edit something in the Design tab. You can directly type in code on the Source tab, too.

  11. Click the init operation, go to its Properties tab, and give the Consumer Key, Consumer Secret, Access Token, and Access Token Secret values that you copied in step 5 of the previous section.
  12. Drag and drop the getAccountVerifyCredentials operation from the tools palette onto the canvas to the right of the init operation. The getAccountVerifyCredentials operation uses Twitter's Verify Credentials API and returns the user's details after credential verification.
  13. Expand the Mediators folder in the tools palette and drag and drop the Respond mediator to the canvas on the right.

    Tip: The Respond mediator stops processing the current message and sends the message back to the client as a response. For more information on the Respond mediator, click here.


  14. Save all your changes.
    You have now completed creating your REST API. Next, let's create an archive file of the tooling project that you just created.

Exporting the project to a composite application archive

  1. In the Project Explorer, right-click the connector project (its name ends with "ConnectorExporter") and click New -> Add/Remove Connectors.
  2. Select the Add connector option in the dialog box that opens, click Next to go to the next screen, select from the file system the Twitter connector that you downloaded in the Before you begin section at the beginning of this tutorial, and click Finish.
  3. In the Project Explorer, click the pom.xml file of the composite application project, go to its Dependencies tab, and note that you have two project artifacts available: the configuration project and the connector project.
  4. Right-click the C-App project and select Export Composite Application Project from the pop-up menu.

  5. Give a name and location for the composite application archive file and click Next.
  6. Select both artifacts to be included in the composite application archive and click Finish

    You have now created a composite archive of the tooling project. Let's import that to WSO2 Integration Cloud. 

Creating an ESB application in WSO2 Integration Cloud using the archive

  1. Log in to WSO2 Integration Cloud by going to
  2. Sign in to WSO2 Cloud and go to the Integration Cloud tab. Then, click ESB Compsite Application.
  3. Select the Local File System option and click Continue.

  4. Enter the following information in the form that opens, scroll down, and click Create

    • Application Name: TwitterESBConnect (or any other name of your choice).
    • Upload the archive file you created before.

  5. Note that the created application opens in the Integration Cloud. Copy its endpoint URL that appears under the Endpoints section in the Overview tab.

    Next, let's invoke the project.

Invoking the application created in the Integration Cloud

REST endpoints are presented in WSO2 Integration Cloud as Swagger definitions. Swagger definitions can come in the JSON language or YAML. In the Integration Cloud, the default is JSON. You can use a tool like the Swagger Editor to get the HTTP endpoint of a REST API in Swagger.

  1. Access the URL you copied in the previous step using a Web browser and copy the Swagger definition that opens.
  2. Go to, paste the Swagger definition in the left-hand panel, and click the Try this operation link of the GET operation on the right-hand panel.
  3. Copy the endpoint URL of the GET request.
  4. Go to the Command-line or Terminal and execute the following command:

    curl <endpoint URL of the GET request that you got in step 3 above>
    For example,
  5. Note that Twitter's Verify Credentials API is invoked and you get the Twitter account owner's information (e.g., name, screen name, location etc.) on the terminal.

You have now used the Twitter connector from WSO2 Store to invoke Twitter's Verify Credentials API using an application deployed in WSO2 Integration Cloud.

Next' next

See Host the Backend Applications for your APIs or see Integration Solutions.

  • No labels