Bitbucket (Basic Auth & Polling)#

This example will walk you through creating a developer app that uses Basic Authentication and a has a single trigger that polls a web service for data. To make the example real, we'll be implementing the actual Bitbucket API.

Quick Preparation Checklist#

Create an App#

To get started, go to the Developer Platform and click the "Create App" button. You'll be asked to give a title and a brief description.

Create App screen

After you submit, you should find yourself with a fresh App like this:

Screenshot of empty dev app

Setting up authentication#

We'll start by defining how Zapier should authenticate with Bitbucket. From the above screen, click the "Get Started" button in the authentication section.

Get Started button

On Step 1 you will want to choose Basic Auth since that is what Bitbucket uses. You should then find yourself on Step 2 with some pre-generated authentication fields. These are the fields that users will be presented with when they add a Bitbucket account in Zapier.

Screenshot of pre-generated authenticationfields

The default fields are all that is needed for Bitbucket, so click next to go to the final step. Here, we define how the fields we collect from users should map to parameters used in the actual API call. Since this is Basic Auth, we will define username and password keys in the auth mapping. Our fields are conveniently called username and password as well, so all we need is this:

Screenshot of auth mapping

Note: the {{username}} is our variable syntax, which says take whatever value the user put in the username authentication field and make it be the username in the Basic Auth call.

At this point, we have the authentication setup and are ready to make our first trigger.

Fetching data from Bitbucket using polling#

The trigger we are going to build will watch Bitbucket for new repositories being added to a user's account. Generally, the first trigger you add to an App should be for an API endpoint that requires authentication and is guaranteed to always return some data. This allows Zapier to verify that the authentication credentials a user provides are valid (we make an actual API call to check).

From your App, click the "Add your first test trigger" button.

Create trigger button

The first form you see allows you to define some of the user-facing details of the trigger.

Step 1 of adding a trigger

Click next to proceed to Step 2, Trigger Fields. Trigger fields add extra information for the trigger which you can use in the URL or in Scripting. We're actually going to skip over this step because our New Repository trigger does not require any additional info. Hit next to get to Step 3, where we define how our trigger will fetch data from Bitbucket.

Bitbucket provides an API endpoint that lists the repositories in a user's account. For Zapier to keep up-to-date, we are going to poll this endpoint at a regular interval to check for new repositories. Here is what we will fill out:

Step 3 of trigger editor

Click save to proceed to Step 4. In this step, we will copy and paste an example of what the Bitbucket API returns. This is not strictly necessary, but it helps users setup their Zaps when they do not have any repositories available to sample. The data can be found by making a raw request with your favorite HTTP client, or using Bitbucket's API Browser.

Step 4 sample data

When you click "Parse" you will be presented with a slew of form fields, one for each JSON key in the sample. These forms allow you to override the default name Zapier will give each key. For instance, Zapier will automatically turn the key "utc_last_updated" into "Utc Last Updated", but you might want to rename it to just "Last Updated". For now, we will skip this step and click "Save".

At this point, we have defined our first trigger and are ready to test it out!

Testing what we have built#

Now that we have built out the basics of our app, it is time to try it out and see if it works. Go to your dashboard and click the create a zap button. On Step 1 of the Zap Editor, you should now have our Bitbucket Example app. The app should have a single trigger, New Repository.

Your Dev App on Step 1 of Zap Editor

After you select the trigger and any action (the Zapier Delay is a good one to test with), Step 2 will ask you to add your Bitbucket account.

Step 2 of Zap Editor

When you click the button, you will get this form:

Screenshot of authentication fields from Zap Editor

As you can see, the form contains the two authentication fields we set up, plus another one that Zapier adds so the user can name the account. Fill out the form and click continue. At this point, Zapier will make an API call the repositories endpoint. If everything is setup correctly (and you have at least one repository in your Bitbucket account), you should get a success message and the account should be added:

Example of successfully adding a Bitbucket account

If you like, you can continue to fill out the Zap. Down at Step 6, when you click the test button, you should see some samples load up that match repositories in your account. At this point, we know our trigger is working.

Congratulations! You have a working Bitbucket application that:

  • Uses Basic Auth.
  • One polling trigger (reused for testing).

Be sure to check out our other examples for more details on doing other interesting things with Zapier's developer platform!

↑ Was this documentation useful? Yes No
Get Help