Integration anytime any place anywhere.

Abusing Interlok as a programming language

Interlok configuration probably isn't Turing complete; but we can write code in XML...

We’re busy migrating away from Bitbucket; not because there’s anything wrong with it; but because as an organisation that’s grown out of 6+ companies, you have to rationalise and standardise things like source control; we’re using GitHub, Bitbucket, multiple on-premise Gitlab instances, Azure TFS; you get the picture. Apparently we need a spreadsheet (it’s always a spreadsheet) of all the projects that are currently in Bitbucket and when they were last used. That’s right; it’s Interlok Hammer time.

It would have been easy to go through and just export the list of projects in Bitbucket since you can already order by last updated date; but I wanted to include the repository type information (i.e. Mercurial or Git) since this also has a tangential impact on the migration since there might be some extra steps in the migration path to migrate from mercurial. How then to generate the CSV for the manager types.

We’re going to use the bitbucket REST API and iterate over list of projects and generate a CSV from there. The interesting point here is not that I chose Interlok to do this, but that the time it took was comparable to doing it manually; and the output of the project can be used to change the output if requirements change. I could have scripted it, used a formal programming language, but I’m not sure that it would have been any quicker to completion than the solution that I created.

The sequence of steps can be described pretty easily using some kind of pseudo-code:

  GET url (
  FOR EACH repo
    APPEND CSV record to file.
  IF has-next-page; url = next-page
UNTIL url == "";

Interlok Design

We can model that very easily in Interlok; I opted to make the trigger an HTTP Request which returns CSV data as the HTTP response; so GET returning text/plain is our baseline behaviour. Bearing in mind some of the limitations of Interlok; we currently don’t have the capability to support multiple payloads (this will come); so we have to use a staging file to store the data while we iterate over the URLs.

Our Interlok sequence can be elaborated to be:

Generate a filename for storing the CSV "csvFilename"
Generate the initial URL and store it as metadata (nextPage)
Write the CSV header that you want to "csvFilename"
  HTTP GET using nextPage as the URL.
  Remove "nextPage" from metadata.
  Check if there's a next page; store it as "nextPage"
  SPLIT/JOIN on $.values {
    MAP object into a simplified format
  }; JOIN it as a JSON Array
  JSON Array To CSV
  APPEND it to "csvFilename"
WHILE "nextPage" != null
READ "csvFilename"
Return the HTTP response

We can split this out into a number of conceptual steps:

Pre-loop activities

  • Generate the temporary CSV filename.
  • Write the CSV header (after generating as a payload) to the temporary filename.
  • Generate the initial URL.
  <generator class="guid-generator"/>
  <producer class="fs-producer">
    <destination class="configured-destination">
    <fs-worker class="fs-overwrite-file"/>
    <filename-creator class="metadata-file-name-creator">

Iterating over the URL

It’s a do-while; with a max-loops=-1. Inside the loop we

  • Query the URL (apache-http-request-service).
  • Remove the “next-page” metadata key (metadata-filter-service).
  • Re-create the “next-page” metadata key if it’s possible (json-path-service).
  • Split/Join to process each of the JSON values.
  • JSON array to CSV, omitting the headers (since we have already written it).

Note that I haven’t bothered with an OAUTH workflow here, I’m just using my username, and a Bitbucket App Password.

  <condition class="not">
    <condition class="metadata">
       <operator class="is-empty"/>
    <service class="service-list">
          <authenticator class="apache-http-dynamic-authorization-header">
          <filter class="regex-metadata-filter">
          <source class="string-payload-data-input-parameter"/>
            <source class="constant-data-input-parameter">
            <target class="metadata-data-output-parameter">
          <!-- discussed below -->
          <preference-builder class="csv-basic-preference-builder">
          <producer class="fs-producer">
            <destination class="configured-destination">
            <fs-worker class="fs-append-file"/>
              <filename-creator class="metadata-file-name-creator">

Pooling splitjoin

  • Split on a JSON path
  • For each of the JSON objects, map it into a simpler one (json-transform-service)
    • It’s a very simple JOLT mapping.
  • Join each of simplified JSON objects into a JSON array.
  <service class="service-list">
          <source-json class="string-payload-data-input-parameter"/>
          <mapping-spec class="constant-data-input-parameter">
    "operation": "shift",
    "spec": {
      "name": "repository_name",
      "scm": "repository_type",
      "project": {
        "name": "project"
      "updated_on": "last_updated"
          <target-json class="string-payload-data-output-parameter"/>
          <metadata-filter class="remove-all-metadata-filter"/>
  <splitter class="json-path-splitter">
    <json-source class="string-payload-data-input-parameter"/>
    <json-path class="constant-data-input-parameter">
    <message-splitter class="json-array-splitter"/>
  <aggregator class="json-array-aggregator"/>


The CSV looks something like:


All in all this took me about 45 minutes; this isn’t significantly longer than how long it would have taken someone to do it manually. We can argue the point about whether it would have been quicker to do it in python/node/go/rust whatever. I’m a developer, and I’m choosing not to write code, in fact, you might think of this as using Interlok as a drag and drop programming language.

We even have the capability to modify the JOLT transform so that we expose more information in the CSV file. You could equally point this at other source control systems that have a REST API with minor changes. It just goes to show that you can deliver value quickly with Interlok.