Integrate with Live Bitbucket Data in MuleSoft (via CData Connect AI)

Dibyendu Datta
Dibyendu Datta
Lead Technology Evangelist
Use CData Connect AI to connect to Bitbucket from the MuleSoft Anypoint Platform to integrate live Bitbucket data into custom reports and dashboards.

The MuleSoft Anypoint Platform enables the building, deployment, and management of APIs and integrations, facilitating seamless connectivity across applications and systems. When combined with CData Connect AI, it provides access to Bitbucket data for visualizations, dashboards, and more. This article explains how to use CData Connect AI to create a live connection to Bitbucket and how to connect and access live Bitbucket data from the MuleSoft Anypoint Platform.

Prerequisites

Before configuring and using MuleSoft with CData Connect AI, you must first connect a data source to your CData Connect AI account. For more information, see the Connections section.

Additionally, you need to generate a Personal Access Token (PAT) on the Settings page. Be sure to copy it down, as it serves as your password during authentication.

Configure Bitbucket Connectivity for MuleSoft

Connectivity to Bitbucket from MuleSoft is made possible through CData Connect AI. To work with Bitbucket data from MuleSoft, we start by creating and configuring a Bitbucket connection.

  1. Log into Connect AI, click Sources, and then click Add Connection
  2. Adding a Connection
  3. Select "Bitbucket" from the Add Connection panel
  4. Selecting a data source
  5. Enter the necessary authentication properties to connect to Bitbucket.

    For most queries, you must set the Workspace. The only exception to this is the Workspaces table, which does not require this property to be set, as querying it provides a list of workspace slugs that can be used to set Workspace. To query this table, you must set Schema to 'Information' and execute the query SELECT * FROM Workspaces>.

    Setting Schema to 'Information' displays general information. To connect to Bitbucket, set these parameters:

    • Schema: To show general information about a workspace, such as its users, repositories, and projects, set this to Information. Otherwise, set this to the schema of the repository or project you are querying. To get a full set of available schemas, query the sys_schemas table.
    • Workspace: Required if you are not querying the Workspaces table. This property is not required for querying the Workspaces table, as that query only returns a list of workspace slugs that can be used to set Workspace.

    Authenticating to Bitbucket

    Bitbucket supports OAuth authentication only. To enable this authentication from all OAuth flows, you must create a custom OAuth application, and set AuthScheme to OAuth.

    Be sure to review the Help documentation for the required connection properties for you specific authentication needs (desktop applications, web applications, and headless machines).

    Creating a custom OAuth application

    From your Bitbucket account:

    1. Go to Settings (the gear icon) and select Workspace Settings.
    2. In the Apps and Features section, select OAuth Consumers.
    3. Click Add Consumer.
    4. Enter a name and description for your custom application.
    5. Set the callback URL:
      • For desktop applications and headless machines, use http://localhost:33333 or another port number of your choice. The URI you set here becomes the CallbackURL property.
      • For web applications, set the callback URL to a trusted redirect URL. This URL is the web location the user returns to with the token that verifies that your application has been granted access.
    6. If you plan to use client credentials to authenticate, you must select This is a private consumer. In the driver, you must set AuthScheme to client.
    7. Select which permissions to give your OAuth application. These determine what data you can read and write with it.
    8. To save the new custom application, click Save.
    9. After the application has been saved, you can select it to view its settings. The application's Key and Secret are displayed. Record these for future use. You will use the Key to set the OAuthClientId and the Secret to set the OAuthClientSecret.
    Configuring a connection (Salesforce is shown)
  6. Click Save & Test
  7. Navigate to the Permissions tab in the Add Bitbucket Connection page and update the User-based permissions. Updating permissions

Add a Personal Access Token

When connecting to Connect AI through the REST API, the OData API, or the Virtual SQL Server, a Personal Access Token (PAT) is used to authenticate the connection to Connect AI. It is best practice to create a separate PAT for each service to maintain granularity of access.

  1. Click on the Gear icon () at the top right of the Connect AI app to open the settings page.
  2. On the Settings page, go to the Access Tokens section and click Create PAT.
  3. Give the PAT a name and click Create. Creating a new PAT
  4. The personal access token is only visible at creation, so be sure to copy it and store it securely for future use.

With the connection configured and a PAT generated, you are ready to connect to Bitbucket data from Mulesoft.

Connecting to CData Connect AI

Follow these steps to establish a connection from Mulesoft to CData Connect AI through the JDBC driver:

  1. Download and install the CData Connect AI JDBC driver.
    • Open the Integrations page of CData Connect AI.
    • Search for and select JDBC.
    • Download and run the setup file.
    • When the installation is complete, the JAR file can be found in the installation directory (inside the lib folder).
  2. Log into Mulesoft Anypoint Studio or launch the desktop application.
  3. Create a new Mulesoft project. Create a new MuleSoft project Add the project name The new project appears in a project folder. The new project is created
  4. In the Mule Palette located on the right, drag an HTTP Listener to the Message Flow area. Drag the HTTP Listener to the Message Flow area
  5. Click on the HTTP Listener to configure it. Click on the HTTP Listener to configure it
  6. Click the + sign on the right of Connector configuration. The HTTP Listener config dialog appears.
  7. Configure the HTTP Listener, providing a Port on which to query your data, and click OK. Add the port number to configure the HTTP Listener
  8. Provide a path on which to perform the actions. The HTTP Listener is now configured. Provide a path to perform the actions
  9. In the Mule Palette on the right, type database in the search bar. Search for database in Mule Palette search bar
  10. Drag the database operation you want to perform to the Message Flow area. For this example, we choose Select. Drag the database operation in the Message Flow area
  11. Select Generic Connection from the Connection dropdown in the Database Config dialog. Select Generic Connection from the Connection dropdown
  12. Click the Configure button to configure the JDBC driver. Select Use local file from the drop-down list. Select Use local file from the dropdown
  13. Locate the CData Connect AI JAR file from the JDBC driver installation and click OK. Add the CData Connect AI JAR file path
  14. Provide the following information:
    • URL: the URL for the connection, for example:
       jdbc:connect:Authscheme=Basic;user=username;password=PAT
      Note: the password is the PAT created in the Prerequisites section.
    • Driver class name: Enter the Driver class name as:
       cdata.jdbc.connect.ConnectDriver
      Add the URL and the Driver class name
  15. Click Test Connection. Click on Test Connection
  16. If the connection is successful, provide the SQL Query Text in the editor. You can see the table metadata on the right side in the Output tab. Write the SQL Query
  17. In the Mule Palette, drag Transform Message to the Message Flow area. Drag Transform Message to the Message Flow area
  18. Click Transform Message to configure it. Change the Output as follows: Configure Transform Message
  19. Save your project and run it. In the console, Mulesoft starts initializing the dependencies. Save and Run the project
  20. Once you see the message, "Message source 'listener' on flow your_project_name successfully started", you can start querying your data at the endpoint you provided. Check for the
  21. Query to check out the data using the Postman application (as shown below). Send an API request from Postman to check the Bitbucket data

SQL Access to Bitbucket Data from Cloud Applications

Now you have a direct connection to live Bitbucket data from MuleSoft Anypoint Platform. You can create more connections to ensure seamless data flow, automate business processes, and manage APIs - all without replicating Bitbucket data.

To get real-time data access to hundreds of SaaS, Big Data, and NoSQL sources (including Bitbucket) directly from your cloud applications, explore the CData Connect AI.

Ready to get started?

Learn more about CData Connect AI or sign up for free trial access:

Free Trial