Hi folks, I’m looking for insights on how to do cross-app requests (eg: Access a list of pages in a space from a jira web panel).
Context:
We have 2 connect apps, one in Confluence, and one in Jira.
We currently do cross-app requests by creating app links between the 2 apps in a shared database.
If a user wants to access Confluence pages from the Jira app, we use the atlassian_host from the linked Confluence app to make the request and retrieve the pages.
We’re currently in the process of migrating to Forge, and are looking to keep the cross-app features.
Results so far
So far, I’ve been able to make cross-app requests by:
-
Declaring confluence scopes in my jira app manifest (read:page:confluence)
-
Installing the app in both confluence and Jira with the forge cli
-
In the ui:
// In Jira web panel frontend
// Sample code from https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-get
import { requestConfluence } from "@forge/bridge";
const response = await requestConfluence(`/wiki/api/v2/pages`, {
headers: {
'Accept': 'application/json'
}
});
console.log(`Response: ${response.status} ${response.statusText}`);
console.log(await response.json());
- In a remote java backend, using ACSB 6.0.0:
//Sample code from https://bitbucket.org/atlassian/atlassian-connect-spring-boot/src/master/README.md
@RestController
@RequiredArgsConstructor
@Slf4j
public class SampleResource {
private final AtlassianForgeRestClients atlassianForgeRestClients;
@ContextJwt
@ForgeRemote
@GetMapping(value = "/pages")
public void getPages() {
try {
final HttpEntity<String> entity = new HttpEntity<>(null, null);
final ResponseEntity<String> response =
atlassianForgeRestClients
.asUser()
.requestConfluence()
.exchange(
"/api/v2/pages",
HttpMethod.GET,
entity,
String.class);
log.warn("Pages: {}", response.getBody());
} catch (Exception e) {
log.error("Error while fetching pages", e);
}
}
It was a little more complicated, as the code above produces an error. The RestTemplate produced by AtlassianForgeRestClients still uses api.atlassian.com/jira/ as a base url for Confluence requests, and I’m receiving an 401 error (“Unauthorized, scopes don’t match”).
However, replacing jira by confluence in the base url via debugger seems to work, and I was able to retrieve pages this way.
Remaining questions
-
How do I make my users install the app in both Confluence and Jira, or how do I skip this step? Is it even possible to install an app to 2 products through the Marketplace? I’m aware of the multi-app compatibility (https://developer.atlassian.com/platform/forge/app-compatibility/#multiple-app-compatibility–preview-) feature which is still in preview, and only accessible for apps fully on Forge, but I’m currently migrating a Connect app, so I cannot make use of this feature (yet).
-
Are cross-product requests intended by Atlassian? If so, is there a bug in the AtlassianForgeRestClients implementation or in my sample code?
I have read other posts on the topic such as Forge appToken requests to Confluence from a Connect remote? and Can't call Jira API from forge confluence module - #5 by PeterAtthem1