Vadim Chekry
Vadim Chekry

Reputation: 1253

How to create a link to issue in Jira API?

I need to create programmatically a link of type "relates to" from one issue to another. I've found a method

createIssueLink(Long sourceIssueId, Long destinationIssueId, Long issueLinkTypeId, Long sequence, User remoteUser) 

in IssueLinkManager, but I can't find anyway to get the issueLinkTypeId. Can anybody help me with that?

Upvotes: 1

Views: 9623

Answers (2)

perfecto25
perfecto25

Reputation: 842

this should work with Jira 7.x

make 2 issues linked to each other

curl -u user:password -w '<%{http_code}>' -H 'Content-Type: application/json' https://jira.instance.com/rest/api/2/issueLink -X POST --data '{"type":{"name":"Related Incident"},"inwardIssue":{"key":"ISS-123"},"outwardIssue":{"key":"SYS-456"}}'

Upvotes: 0

mdoar
mdoar

Reputation: 6881

You probably want to use

    Collection linkTypes = issueLinkTypeManager.getIssueLinkTypesByName(name);

and then iterate until you find the IssueLinkType instance you want, then linkType.getId()

For remote access I recommend using the jira-python library and the create_issue_link method.

Internally that method does this:

def create_issue_link(self, type, inwardIssue, outwardIssue, comment=None):
    """
    Create a link between two issues.

    :param type: the type of link to create
    :param inwardIssue: the issue to link from
    :param outwardIssue: the issue to link to
    :param comment:  a comment to add to the issues with the link. Should be a dict containing ``body``\
    and ``visibility`` fields: ``body`` being the text of the comment and ``visibility`` being a dict containing\
    two entries: ``type`` and ``value``. ``type`` is ``role`` (or ``group`` if the JIRA server has configured\
    comment visibility for groups) and ``value`` is the name of the role (or group) to which viewing of this\
    comment will be restricted.
    """
    data = {
        'type': {
            'name': type
        },
        'inwardIssue': {
            'key': inwardIssue
        },
        'outwardIssue': {
            'key': outwardIssue
        },
        'comment': comment
    }
    url = self._get_url('issueLink')
    r = self._session.post(url, data=json.dumps(data))

~Matt

Upvotes: 1

Related Questions