Internal
Create a new instance of the service.
Adds one or more attachments to an issue. Attachments are posted as multipart/form-data (RFC 1867).
Note that:
X-Atlassian-Token: no-check
header, if not it is
blocked. See Special headers for more information.file
.The following examples upload a file called myfile.txt to the issue TEST-123:
curl --location --request POST
'https://your-domain.atlassian.net/rest/api/3/issue/TEST-123/attachments'
-u 'email@example.com:<api_token>'
-H 'X-Atlassian-Token: no-check'
--form 'file=@"myfile.txt"'
// This code sample uses the 'node-fetch' and 'form-data' libraries:
// https://www.npmjs.com/package/node-fetch
// https://www.npmjs.com/package/form-data
const fetch = require('node-fetch');
const FormData = require('form-data');
const fs = require('fs');
const filePath = 'myfile.txt';
const form = new FormData();
const stats = fs.statSync(filePath);
const fileSizeInBytes = stats.size;
const fileStream = fs.createReadStream(filePath);
form.append('file', fileStream, {knownLength: fileSizeInBytes});
fetch('https://your-domain.atlassian.net/rest/api/3/issue/TEST-123/attachments',
{
method: 'POST',
body: form,
headers: {
'Authorization': `Basic ${Buffer.from(
'email@example.com:'
).toString('base64')}`,
'Accept': 'application/json',
'X-Atlassian-Token': 'no-check'
}
})
.then(response => {
console.log(
`Response: ${response.status} ${response.statusText}`
);
return response.text();
})
.then(text => console.log(text))
.catch(err => console.error(err));
// This code sample uses the 'Unirest' library:
// http://unirest.io/java.html
HttpResponse response =
Unirest.post("https://your-domain.atlassian.net/rest/api/2/issue/{issueIdOrKey}/attachments")
.basicAuth("email@example.com", "")
.header("Accept", "application/json")
.header("X-Atlassian-Token", "no-check")
.field("file", new File("myfile.txt"))
.asJson();
System.out.println(response.getBody());
# This code sample uses the 'requests' library:
# http://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json
url =
"https://your-domain.atlassian.net/rest/api/2/issue/{issueIdOrKey}/attachments"
auth = HTTPBasicAuth("email@example.com", "")
headers = {
"Accept": "application/json",
"X-Atlassian-Token": "no-check"
}
response = requests.request(
"POST",
url,
headers = headers,
auth = auth,
files = {
"file": ("myfile.txt", open("myfile.txt","rb"), "application-type")
}
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4,
separators=(",", ": ")))
// This code sample uses the 'Unirest' library:
// http://unirest.io/php.html
Unirest\Request::auth('email@example.com', '');
$headers = array(
'Accept' => 'application/json',
'X-Atlassian-Token' => 'no-check'
);
$parameters = array(
'file' => File::add('myfile.txt')
);
$response = Unirest\Request::post(
'https://your-domain.atlassian.net/rest/api/2/issue/{issueIdOrKey}/attachments',
$headers,
$parameters
);
var_dump($response)
// This sample uses Atlassian Forge and the `form-data` library.
// https://developer.atlassian.com/platform/forge/
// https://www.npmjs.com/package/form-data
import api from "@forge/api";
import FormData from "form-data";
const form = new FormData();
form.append('file', fileStream, {knownLength: fileSizeInBytes});
const response = await
api.asApp().requestJira('/rest/api/2/issue/{issueIdOrKey}/attachments', {
method: 'POST',
body: form,
headers: {
'Accept': 'application/json',
'X-Atlassian-Token': 'no-check'
}
});
console.log(`Response: ${response.status} ${response.statusText}`);
console.log(await response.json());
Tip: Use a client library. Many client libraries have classes for handling multipart POST operations. For example, in Java, the Apache HTTP Components library provides a MultiPartEntity class for multipart POST operations.
This operation can be accessed anonymously.
Permissions required:
The ID or key of the issue that attachments are added to.
Returned if the request is successful.
example:
[
{
"author": {
"accountId": "5b10a2844c20165700ede21g",
"active": true,
"avatarUrls": {
"16x16": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=16&s=16",
"24x24": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=24&s=24",
"32x32": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=32&s=32",
"48x48": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=48&s=48"
},
"displayName": "Mia Krystof",
"emailAddress": "mia@example.com",
"self": "https://your-domain.atlassian.net/rest/api/3/user?accountId=5b10a2844c20165700ede21g",
"timeZone": "Australia/Sydney"
},
"content": "https://your-domain.atlassian.net/rest/api/3/attachment/content/10000",
"created": 1651316514000,
"filename": "picture.jpg",
"id": "10001",
"mimeType": "image/jpeg",
"self": "https://your-domain.atlassian.net/rest/api/3/attachments/10000",
"size": 23123,
"thumbnail": "https://your-domain.atlassian.net/rest/api/3/attachment/thumbnail/10000"
},
{
"author": {
"accountId": "5b10a2844c20165700ede21g",
"active": true,
"avatarUrls": {
"16x16": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=16&s=16",
"24x24": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=24&s=24",
"32x32": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=32&s=32",
"48x48": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=48&s=48"
},
"displayName": "Mia Krystof",
"emailAddress": "mia@example.com",
"self": "https://your-domain.atlassian.net/rest/api/3/user?accountId=5b10a2844c20165700ede21g",
"timeZone": "Australia/Sydney"
},
"content": "https://your-domain.atlassian.net/rest/api/3/attachment/content/10001",
"created": 1658898511000,
"filename": "dbeuglog.txt",
"mimeType": "text/plain",
"self": "https://your-domain.atlassian.net/rest/api/3/attachments/10001",
"size": 2460
}
]
Returns the metadata for the contents of an attachment, if it is an archive, and metadata for the attachment itself. For example, if the attachment is a ZIP archive, then information about the files in the archive is returned and metadata for the ZIP archive. Currently, only the ZIP archive format is supported.
Use this operation to retrieve data that is presented to the user, as this operation returns the metadata for the attachment itself, such as the attachment's ID and name. Otherwise, use Get contents metadata for an expanded attachment, which only returns the metadata for the attachment's contents.
This operation can be accessed anonymously.
Permissions required: For the issue containing the attachment:
The ID of the attachment.
Returned if the request is successful. If an empty list is returned in the response, the attachment is empty, corrupt, or not an archive.
example:
{
"entries": [
{
"index": 0,
"label": "MG00N067.JPG",
"mediaType": "image/jpeg",
"path": "MG00N067.JPG",
"size": "119 kB"
},
{
"index": 1,
"label": "Allegro from Duet in C Major.mp3",
"mediaType": "audio/mpeg",
"path": "Allegro from Duet in C Major.mp3",
"size": "1.36 MB"
},
{
"index": 2,
"label": "long/path/thanks/to/.../reach/the/leaf.txt",
"mediaType": "text/plain",
"path": "long/path/thanks/to/lots/of/subdirectories/inside/making/it/quite/hard/to/reach/the/leaf.txt",
"size": "0.0 k"
}
],
"id": 7237823,
"mediaType": "application/zip",
"name": "images.zip",
"totalEntryCount": 39
}
Returns the metadata for the contents of an attachment, if it is an archive. For example, if the attachment is a ZIP archive, then information about the files in the archive is returned. Currently, only the ZIP archive format is supported.
Use this operation if you are processing the data without presenting it to the user, as this operation only returns the metadata for the contents of the attachment. Otherwise, to retrieve data to present to the user, use Get all metadata for an expanded attachment which also returns the metadata for the attachment itself, such as the attachment's ID and name.
This operation can be accessed anonymously.
Permissions required: For the issue containing the attachment:
The ID of the attachment.
Returned if the request is successful. If an empty list is returned in the response, the attachment is empty, corrupt, or not an archive.
example:
{
"entries": [
{
"entryIndex": 0,
"mediaType": "audio/mpeg",
"name": "Allegro from Duet in C Major.mp3",
"size": 1430174
},
{
"entryIndex": 1,
"mediaType": "text/rtf",
"name": "lrm.rtf",
"size": 331
}
],
"totalEntryCount": 24
}
Returns the metadata for an attachment. Note that the attachment itself is not returned.
This operation can be accessed anonymously.
Permissions required:
The ID of the attachment.
Returned if the request is successful.
example:
{
"author": {
"accountId": "5b10a2844c20165700ede21g",
"accountType": "atlassian",
"active": false,
"avatarUrls": {
"16x16": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=16&s=16",
"24x24": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=24&s=24",
"32x32": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=32&s=32",
"48x48": "https://avatar-management--avatars.server-location.prod.public.atl-paas.net/initials/MK-5.png?size=48&s=48"
},
"displayName": "Mia Krystof",
"key": "",
"name": "",
"self": "https://your-domain.atlassian.net/rest/api/3/user?accountId=5b10a2844c20165700ede21g"
},
"content": "https://your-domain.atlassian.net/jira/rest/api/3/attachment/content/10000",
"created": "2022-10-06T07:32:47.000+0000",
"filename": "picture.jpg",
"id": 10000,
"mimeType": "image/jpeg",
"self": "https://your-domain.atlassian.net/rest/api/3/attachments/10000",
"size": 23123,
"thumbnail": "https://your-domain.atlassian.net/jira/rest/api/3/attachment/thumbnail/10000"
}
Returns the contents of an attachment. A Range
header can be set to define a
range of bytes within the attachment to download. See the HTTP Range header
standard for
details.
To return a thumbnail of the attachment, use Get attachment thumbnail.
This operation can be accessed anonymously.
Permissions required: For the issue containing the attachment:
The ID of the attachment.
Optional
redirect?: booleanWhether a redirect is provided for the attachment download. Clients that do not
automatically follow redirects can set this to false
to avoid making multiple
requests to download the attachment.
Returned if the request is successful when redirect
is set to false
.
Returns the attachment settings, that is, whether attachments are enabled and the maximum attachment size allowed.
Note that there are also project permissions that restrict whether users can create and delete attachments.
This operation can be accessed anonymously.
Permissions required: None.
Returned if the request is successful.
example:
{
"enabled": true,
"uploadLimit": 1000000
}
Returns the thumbnail of an attachment.
To return the attachment contents, use Get attachment content.
This operation can be accessed anonymously.
Permissions required: For the issue containing the attachment:
Optional
fallbackWhether a default thumbnail is returned when the requested thumbnail is not found.
Optional
height?: numberThe maximum height to scale the thumbnail to.
The ID of the attachment.
Optional
redirect?: booleanWhether a redirect is provided for the attachment download. Clients that do not
automatically follow redirects can set this to false
to avoid making multiple
requests to download the attachment.
Optional
width?: numberThe maximum width to scale the thumbnail to.
Returned if the request is successful when redirect
is set to false
.
Deletes an attachment from an issue.
This operation can be accessed anonymously.
Permissions required: For the project holding the issue containing the attachment:
The ID of the attachment.
Protected
Static
initialize
This resource represents issue attachments and the attachment settings for Jira. Use it to get the metadata for an attachment, delete an attachment, and view the metadata for the contents of an attachment. Also, use it to get the attachment settings for Jira.
See
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments