Error when calling requestJira from bitbucket app

Hi, I’m developing a Bitbucket app using Forge. In it, I need to call a Jira api to set a value for a field. When it reaches to this point, I’m getting this error:

Request jira is not allowed from bitbucket context.

In a similar post, I have found out that maybe installing it on Jira might solve the issue but it’s not possible to install in on Bitbucket and Jira at the same time.

Please help.
Thanks

1 Like

Welcome to the Atlassian developer community @MahdiMalekan,

There’s a prior thread about cross-product apps (before Bitbucket joined the Forge family), in which Atlassian asserts:

Forge today has been designed in a way that isn’t product specific, so an app can be composed from functionality from multiple products. That said, this is a bit theoretical, because in practice as you’ve discovered we don’t have a great story for how a single app can be installed in and interact with multiple products.

This is an area we are interested in investigating further, but definitely needs more work and thought. The doc you reference stating that Forge “supports and encourages” this is probably too strongly worded – we’ll tone that down.

With a focus on making sure the Marketplace aspect is clear, we did clarify our Marketplace docs about supporting multiple products:

The Forge platform lets developers build apps that are compatible with multiple products.

However, the Marketplace doesn’t currently support cross-product apps. If your app is compatible with multiple products, you’ll need to create two Forge apps using the same code base, and publish two separate listings on the Marketplace. Note, Forge apps listed on the Marketplace aren’t able to make API calls across different products and instances/installations.

In both cases, those statements about “compatible with multiple products” did not include Bitbucket. All this to say, we don’t do a good job acknowledging the problem you’re facing but it is the “expected behavior”. As such, I recommend logging this Bitbucket app making a Jira request as a suggestion so you, and others who might stumble upon this thread, would have something formal to track. Could you please open a “suggestion” issue yourself in our open Jira (JAC) in the ECO project. Once you have the issue key, please let us know here so other folks can watch, vote, and comment.

1 Like

Hi @ibuchanan and thanks for the reply.
I have created a suggestion here.

Although as a workaround, we can call the rest API directly. It’s a bit more complicated but it does the job.

2 Likes

Hi @MahdiMalekan do you have any working example? I have the same use case but I’m stuck with making rest requests directly.

Thanks in advance.

Hi @RivasAnyul
In order to send a rest request, import fetch like this:
import api, { fetch, route } from "@forge/api";

then you can simply send a rest api request to the JiraAPI:

  const headers = {
    Accept: "application/json",
    "Content-Type": "application/json",
    Authorization: `Basic ${Buffer.from(
      `${jiraParameters.user}:${jiraParameters.key}`
    ).toString("base64")}`,
  };
  const res = await fetch('https://xxx.atlassian.net/rest/api/latest/issue/', {
    method: "GET",
    headers,
  });

Don’t forget to add the required permission in the manifest file:

permissions:
  scopes:
    - read:pullrequest:bitbucket
  external:
    fetch:
      backend:
        - xxx.atlassian.net   <--
2 Likes