Creation of a confluence space when new Jira project is created

I am trying to automatically create a confluence space whenever a new project is created. I did go through some of the other similar questions, but none really worked. I am using Spring boot. Here’s the code snippet:

public class ProjectController {
    Logger logger = LoggerFactory.getLogger(ProjectController.class);
    private AtlassianHostRestClients atlassianHostRestClients;

    @RequestMapping(value = "/projectCreated", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)

    public void projectCreated(@RequestBody Project project) throws JsonProcessingException {"Project created");
        JsonNodeFactory jnf = JsonNodeFactory.instance;
        ObjectNode payload = jnf.objectNode();
        payload.put("key", project.getProject().getKey());
        payload.put("value", project.getProject().getName());
        ObjectNode description = payload.putObject("description");
            ObjectNode plain = description.putObject("plain");
                plain.put("value", "Confluence Space for " + project.getProject().getName());
                plain.put("representation", "plain");
        ObjectMapper mapper = new ObjectMapper();
        String a = mapper.writeValueAsString(payload);;
        ResponseEntity responseEntity = atlassianHostRestClients.authenticatedAsAddon().postForObject("/wiki/rest/api/space", payload.toString(), ResponseEntity.class);;


The web hook is being called correctly, but nothing is happening. Spring log shows: > "2022-07-04 09:15:55.473 DEBUG 6282 — [nio-8080-exec-1] .a.AbstractConnectAuthenticationProvider : Canonical request for incoming JWT: [CanonicalHttpServletRequest@356ea444 method = ‘POST’, relativePath = ‘/projectCreated’, parameterMap = ‘[lic → (none),]’]

If I remove @CanonicalJWT, I get an unauthorised request.

Specifically: Would the JWT token when I install as a Jira App work for confluence too? If it doesn’t, how do I go about getting a JWT token for confluence based on the Jira App?
Can someone help?


No. The Connect install flow is effectively an authorization handshake for the target product, not the site as a whole. To put it simply, the install only works for Jira, not for Confluence. Therefore, your app will need to obtain authorization from Confluence separately via another install flow. Then your app will have to keep track of the mapping between Jira & Confluence, which will have separate secrets.