Here is an example of an integration of Jira with Confluence. These assume that you have the recommended app link configuration as described on Interacting with other Atlassian Apps. Also, see the examples of integrating Confluence from the Jira perspective.

Creating a JIRA Project

This example hooks up the SpaceCreateEvent, and responds by creating a project in Jira, using the primary Jira application link. See event handlers for more information.

import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.jira.JiraApplicationType
import com.atlassian.confluence.event.events.space.SpaceCreateEvent
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler
import groovy.json.JsonBuilder

import static com.atlassian.sal.api.net.Request.MethodType.POST

def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()

def event = event as SpaceCreateEvent
def space = event.space

def input = new JsonBuilder([
    projectTypeKey: "business",
    projectTemplateKey : "com.atlassian.jira-core-project-templates:jira-core-task-management",
    name: space.name,
    key: space.key,
    lead: event.space.creator.name,
]).toString()

def request = applicationLinkRequestFactory.createRequest(POST, "/rest/api/2/project")
    .addHeader("Content-Type", "application/json")
    .setEntity(input)

request.execute(new ResponseHandler<Response>() {
    @Override
    void handle(Response response) throws ResponseException {
        if ( response.statusCode != 201) {
            log.error ("Creating jira project failed: ${response.responseBodyAsString}")
        }
    }
})
See the Jira REST API documentation for more info on usage.

For how-to questions please ask on Atlassian Answers where there is a very active community. Adaptavist staff are also likely to respond there.

Ask a question about ScriptRunner for JIRA, for for Bitbucket Server, or for Confluence.