Missing functions on AP object

I’m running into issues with Atlassian Connect, using the javascript API.

I have a descriptor with a simple webitem

{
  "name": "Create Branch",
  "description": "Adds a button to issue tools to create a branch",
  "key": "com.example.create-branch",
  "baseUrl": "https://6026-86-88-172-152.ngrok.io",
  "vendor": {
      "name": "Example",
      "url": "https://example.com"
  },
  "authentication": {
      "type": "none"
  },
  "scopes": [ "READ" ],
  "apiVersion": 1,
  "modules": {
    "webItems": [
      {
          "key": "create-branch-tools-item",
          "location": "operations-operations",
          "weight": 10,
          "name": {
              "value": "Create branch"
          },
          "url": "/create-branch.html?issueKey={issue.key}&issueTypeId={issuetype.id}"
      }
    ]
  }
}

This causes a click of the Create branch button to open ‘create-branch.html’, so far so good. It opens a the page as expected.

My page loads using the following contents.

<!DOCTYPE html>
<html lang="en">

<head>
  <!--<link rel="stylesheet" href="https://unpkg.com/@atlaskit/css-reset@2.0.0/dist/bundle.css" media="all">-->
  <script src="https://connect-cdn.atl-paas.net/all.js"></script>
</head>

<body>
  <script>
    window.onload = function () {
      debugger;
    }
  </script>
</body>

</html>

It breaks on debugger, so I can inspect my scope. Now when I look at window.AP, which supposedly comes from https://connect-cdn.atl-paas.net/all.js, I would expect there to be functions like ‘request’, to get more info from my instance. But my AP object is very limited, when doing examples like AP.request(etc…) I always get not found.

Here is an example of what my AP object looks like:

What am I doing wrong here?

Your not doing anything wrong, except that Bitbucket is not using the all.js from the CDN. You need to use

<script type="application/javascript" src="https://bitbucket.org/atlassian-connect/all.js"></script>

which again, is not your fault, but the somewhat confusing documentation that Atlassian does not care to update because (unofficially) Connect is a dying framework.

I went and checked and the Bitbucket Cloud documentation does not state to use the CDN. About the Javascript API

Are you seeing something different?

Sorry for not mentioning, the plugin is for JIRA Cloud not for BitBucket.

I was following this:
About the JavaScript API (atlassian.com)
and same here: Getting started with Connect (atlassian.com) where they are using <script src="https://connect-cdn.atl-paas.net/all.js" async></script>

What do you get if you set the Authentication to “JWT” instead of “none”? I suspect you aren’t given the functions that require JWT if you don’t have the right auth declared.

Hi,
I am getting exactly the same values on the AP object as JeffreyBindinga and the same error (Uncaught TypeError: AP.request is not a function) when trying to use the AP.request function.

I created the app from ACE (it is just the autogenerated hello-world app). The https://connect-cdn.atl-paas.net/all.js is included automatically with this line on the layout.hbs file and the contents of this file are included in the hello-world.hbs file with this: {{!< layout}}

I am using JWT as the authentication method and READ in the scopes.

What could be wrong?

Thanks
Edgar

Looks like the script line was removed from previous reply, this is how the https://connect-cdn.atl-paas.net/all.js library is included (line 4) from the layout.hbs file
image

Hello,
I found out that the same hello-world.hbs file behaves different (in reference to the use of the AP.request function) depending on the module from where the AP.request function it is called. For example, if in my index.js file from routes I use the URL of the generalPages module, the call to the AP.request function works, however if I use the URL of a webItems module, I get the “AP.request is not a function” error.

What I noticed is that the generalPages creates an iframe element and the webItems is not creating one and according to the documentation it mentions the following: The Atlassian connect JavaScript API is designed to overcome this limitation. “It enables JavaScript code in a Connect app’s iframe to interact with the underlying platform APIs”

Does it mean that I need to create an iframe on the page that is created when I click on the webItem?, if so, how can I create it in order to use the the Atlassian connect JavaScript API?

Thanks,
Edgar