Failed to establish local tunnel on multi-page blueprints with Confluence Connect

Hi. My company needs to implement Confluence blueprints with multiple pages and for this they have assigned me to help create them via this tutorial

I have been able to thus far clone the repository, install dependencies, modify atlassian-connect.json to what is specified, create the route handler created.js with the code provided, create a credentials.json file for which I provided my company’s domain name, my username and an API token I created.

However, when I run npm start I get this error:

From the error messages thrown, I gather that the main error is that a local tunnel cannot be established (Failed to establish local tunnel) because of failed MSpanList_Insert.

Looking this up online I thought it would have to do with having an old version of Go/GoLang, but my go version command outputs go version go1.11.5 darwin/amd64 (I’m doing this on a MacOS Mojave 10.14)

Also, the line Cannot read property ‘indexOf’ of undefined seems to point to an error with the lock package. I also tried looking this up, but found little help.

Is it possible that the tutorial omits or assumes I can follow certain steps that I clearly haven’t? Has anyone been able to successfully complete this tutorial? It is worth mentioning that I am only a developer of my company, but I went over the steps with my Project Manager, who should have the proper credentials, should that be the issue, and he also couldn’t get past this step.

Please let me know if you need me to provide more information to solve this. Thank you for any help or insight you may provide.

Hello @carlos,

At first glance, I’m thinking the following might have caused the error:

  1. You do not have ngrok installed. It is a tool to tunnel your local development environment to the internet.
  2. If you already have ngrok, then maybe some network restrictions are what’s causing the error.

Cheers,
Ian

Thank you for your reply. I do have ngrok installed. I ran ngrok http 3000 and got this:

I’ve been doing this at home, on a mac where I was assigned admin rights. How could I check if I have network restrictions that won’t allow for ngrok to work properly?

Since your ngrok is looking ok, it might not be a tunnel issue. I’ll see what I can do.

Hello @carlos, I was able to replicate your issue; it manifests when credentials.json is created. After digging deeper, unfortunately, the sample app is quite dated and the dependencies needs to be updated. The storage adapter in config.json also needs to be modified to use sequelize. I think it would be a lot faster to create a new connect template by calling atlas-connect-new then copy the following files from the tutorial to the newly created project:

  • atlassian-connect.json
  • blueprint.xml
  • routes/*

For broken tutorials like this, I would encourage you to raise this to Atlassian by clicking the “Give docs feedback” link found in the upper right-hand side of the documentation page in order for the team to make the necessary changes. Thanks.

Thank you very much! Thus far, at least I am past that step. I tried atlas-connect new to create a new project, copied over the files and directories you said, created credentials.json with the information I had, and got this error:

So while the issue with credentials in my company gets resolved, I created my own atlassian account and changed the credentials.json file and got it running. I managed to locate the Simple remote multi-page blueprint in the Create dialog, tried adding a new page, but I didn’t get any child pages.

I tried changing my atlassian-connect.json's webhook event to * in case the blueprint_page_created wasn’t firing to attempt to launch created.js regardless of what event would fire, but it didn’t work.

How could I check if webhooks are firing properly, or at all? Thank you again for all the help you’ve provided me with to this point

I noticed there appears to be a request for a bug fix on this issue here that is not resolved. Are the developers still working on this or is there an alternative way to create multi-page blueprints?

@iragudo please let me know if you were able to see my replies. I sent a message to the developers by clicking on the Give docs feedback option you had suggested, but I have yet to hear from them.

I also found this ticket. Is this an issue with web hooks that has been going on for long? I have voted on both tickets (this one and the one mentioned in an earlier comment), but are there any other ways to catch the developers’ attention to fix this?

Please let me know, and thank you for all your help

By the way @iragudo I tried the Atlassian Connect Inspector and it seems that at no point the blueprint_page_created event is fired.

I guess that could confirm the events in a webhook are not being fired. Also, I tried changing the event to page_created instead but I get the same result.

Hello @carlos,

Yes, it seems you experienced CONFCLOUD-62678.

In your descriptor file, when you changed blueprint_page_created to page_created, what happens? Based on your screenshot, page_created webhook is being fired.

@iragudo,

It seems that when I change blueprint_page_created to page_created, no child pages are created, but the page_created event is fired twice:

And, when I create a page (this one I titled Sample Multi-page Title) another one gets created, titled Simple remote multi-page blueprint, which corresponds with the value property of the name property of the blueprints module in the app descriptor:

{
  "key": "confluence-multipage-blueprint-example",
  "name": "Confluence Multi-page Blueprint Example",
  "description": "Example of creating multi-page blueprint with control over the result structure",
  "vendor": {
    "name": "Atlassian Labs",
    "url": "https://www.atlassian.com"
  },
  "baseUrl": "{{localBaseUrl}}",
  "links": {
    "self": "{{localBaseUrl}}/atlassian-connect.json",
    "homepage": "{{localBaseUrl}}/atlassian-connect.json"
  },
  "authentication": {
    "type": "jwt"
  },
  "lifecycle": {
    "installed": "/installed"
  },
  "scopes": [
    "READ",
    "WRITE"
  ],
  "modules": {
    "blueprints": [
      {
        "template": {
          "url": "/blueprint.xml"
        },
        "createResult": "edit",
        "description": {
          "value": "Create simple multi-pages"
        },
        "key": "remote-multipage-blueprint",
        "name": {
          "value": "Simple remote multi-page blueprint"
        }
      }
    ],
    "webhooks": [
      {
        "event": "page_created",
        "url": "/created"
      }
    ]
  }
}

Nothing inside created.js seems to refer to making a single page titled that. The file, though it’s just like the one in the tutorial, is here:

const descriptor = require('../atlassian-connect.json');
module.exports = function (app, addon) {
  app.post('/created', addon.authenticate(), function (req, res) {
    // Create a wrapper for request (https://www.npmjs.com/package/request)
    // which handles authorisation signing automatically
    var httpClient = addon.httpClient(req);
    var body = req.body;

    // Check if the blueprint creation callback is current registered blueprint
    if (body.blueprint.indexKey !== descriptor.modules.blueprints[0].key) {
      return;
    }

    // Create content for child pages
    for (var i = 1; i <= 5; i++) {
      // Randomize the title because we can't create pages with same name in one space
      var title = 'Test child page ' + i + ' - ' + String(Math.random()).slice(2);

      // Content of the page
      var contentBody = '<p>Data for child page ' + i + '.</p>';

      var content = {
        'type': 'page',
        'title': title,
        'space': {
          'key': body.page.spaceKey
        },
        'ancestors': [{ 'id': body.page.id }],
        'body': {
          'storage': {
            'value': contentBody,
            'representation': 'storage'
          }
        }
      };

      // Create child pages
      httpClient.post({
        url: '/rest/api/content',
        headers: {
          'X-Atlassian-Token': 'nocheck'
        },
        json: content
      }, function (err, res, body) {
        if (err) {
          console.error(err);
        }
      });
    }
  });
};

Since you are waiting for page_created, child pages will not be created because of this

    // Check if the blueprint creation callback is current registered blueprint
    if (body.blueprint.indexKey !== descriptor.modules.blueprints[0].key) {
      return;
    }

The body will not contain blueprint since you are now waiting for the page_created webhook. Removing this condition will get you to the next line however, I do not recommend doing that because creating the child pages will result in page_created webhooks being triggered, thus, creating more child pages. What’s going to happen then is a loop that creates new child pages for every child page, and so on.

If the goal is to create a blueprint that creates child pages, then using page_created is not a safe option since it will be prone to an infinite loop of page creations. A probable hack (notice the use of the word hack) is to use a pre-defined child page title marker that will be used to replace the if statement above but do take note of a possible endless loop once the if statement is implemented incorrectly.

Hope this helps.
Ian