HTTP Endpoint Examples
See a worked example of an HTTP endpoint that reads, creates, and deletes issue links using GET, POST, and DELETE requests, with sample curl calls.
The following example demonstrates how to use an HTTP endpoint to manage issue links for a given Jira issue. The endpoint handles GET, POST, and DELETE requests to read, create, and remove issue links.
Manage issue links
Path:/issues/:issueKey/links
This endpoint reads issue links from Jira, adds new ones, and removes existing links depending on the HTTP method used.
import type { ApiRequest, ApiResponse } from "@avst-sr/types/api-endpoints";
import api from "@avst-sr/api";
export default async function (request: ApiRequest): Promise<ApiResponse> {
const { method, pathParams, body } = request;
const issueKey = pathParams.issueKey;
switch (method) {
case "GET": {
// Fetch linked issues from Jira
const res = await api.get(`/rest/api/3/issue/${issueKey}?fields=issuelinks`);
const issue = await res.json();
return {
statusCode: 200,
body: JSON.stringify(issue.fields.issuelinks ?? []),
};
}
case "POST": {
// Create an issue link
const { targetIssue, linkType } = JSON.parse(body ?? "{}");
const res = await api.post("/rest/api/3/issueLink", {
body: {
type: { name: linkType },
inwardIssue: { key: issueKey },
outwardIssue: { key: targetIssue },
},
});
return {
statusCode: res.ok ? 201 : res.status,
body: await res.text(),
};
}
case "DELETE": {
// Remove an issue link
const { linkId } = JSON.parse(body ?? "{}");
const res = await api.del(`/rest/api/3/issueLink/${linkId}`);
return {
statusCode: res.ok ? 204 : res.status,
body: res.ok ? "" : await res.text(),
};
}
default:
return {
statusCode: 405,
body: JSON.stringify({ error: `Method ${method} not allowed` }),
};
}
}Example requests
GET: list linked issues
Retrieve all issue links for a given work item. Use this to inspect relationships between issues without querying Jira's full API directly.
curl -X GET "https://example.atlassian.net/gateway/api/svc/jira/apps/ari:cloud:ecosystem::app/12345678-1234-1234-1234-123456789012_prod/api/issues/ISSUE-42/links" \
-H "Authorization: Bearer <access_token>" \
-H "Accept: application/json"POST: create an issue link
Link two issues together by specifying a target issue and link type. Use this to programmatically define relationships between work items from an external system or automation.
curl -X POST "https://api.atlassian.com/svc/jira/a12bc345-678d-9e1f/zy2x11w1-0v1u-9876-ts54_3aaa01b0-02cc/api/issues/ISSUE-42/links" \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{"targetIssue": "ISSUE-99", "linkType": "Relates"}'DELETE: remove an issue link
Remove an existing link between two issues by providing the link ID. Use this to clean up stale or incorrect relationships without opening Jira manually.
curl -X DELETE "https://example.atlassian.net/gateway/api/svc/jira/apps/ari:cloud:ecosystem::app/12345678-1234-1234-1234-123456789012_prod/api/issues/ISSUE-42/links" \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{"linkId": "12345"}'