Add one or more attachments to an issue. This example will add 3 attachments to the issue "SCRUM-15".
curl -X POST --user jira@example.com:JIRA_API_TOKEN \
--header 'Accept: application/json' \
--header 'Content-Type: multipart/form-data' \
--header 'X-Atlassian-Token: no-check' \
--form 'name=file; file=@starfish.jpg' \
--form 'name=file; file=@sample2.docx' \
--form 'name=file; file=@sample.pdf' \
--url 'https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15/attachments'
#include <C_CkRestW.h>
#include <C_CkStreamW.h>
#include <C_CkJsonArrayW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
BOOL bTls;
int port;
BOOL bAutoReconnect;
HCkStreamW fileStream1;
HCkStreamW fileStream2;
HCkStreamW fileStream3;
const wchar_t *strResponseBody;
int respStatusCode;
HCkJsonArrayW jsonResponse;
int arrIdx;
int numArrayObjects;
HCkJsonObjectW jObj;
rest = CkRestW_Create();
// URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15/attachments
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRestW_Connect(rest,L"your-domain.atlassian.net",port,bTls,bAutoReconnect);
if (success != TRUE) {
wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
CkRestW_SetAuthBasic(rest,L"jira@example.com",L"JIRA_API_TOKEN");
CkRestW_putPartSelector(rest,L"1");
fileStream1 = CkStreamW_Create();
CkStreamW_putSourceFile(fileStream1,L"starfish.jpg");
CkRestW_AddHeader(rest,L"Content-Disposition",L"form-data; name=\"file\"; filename=\"starfish.jpg\"");
CkRestW_AddHeader(rest,L"Content-Type",L"image/jpeg");
CkRestW_SetMultipartBodyStream(rest,fileStream1);
CkRestW_putPartSelector(rest,L"2");
fileStream2 = CkStreamW_Create();
CkStreamW_putSourceFile(fileStream2,L"sample2.docx");
CkRestW_AddHeader(rest,L"Content-Disposition",L"form-data; name=\"file\"; filename=\"sample2.docx\"");
CkRestW_AddHeader(rest,L"Content-Type",L"application/vnd.openxmlformats-officedocument.wordprocessingml.document");
CkRestW_SetMultipartBodyStream(rest,fileStream2);
CkRestW_putPartSelector(rest,L"3");
fileStream3 = CkStreamW_Create();
CkStreamW_putSourceFile(fileStream3,L"sample.pdf");
CkRestW_AddHeader(rest,L"Content-Disposition",L"form-data; name=\"file\"; filename=\"sample.pdf\"");
CkRestW_AddHeader(rest,L"Content-Type",L"application/pdf");
CkRestW_SetMultipartBodyStream(rest,fileStream3);
CkRestW_putPartSelector(rest,L"0");
CkRestW_AddHeader(rest,L"Content-Type",L"multipart/form-data");
CkRestW_AddHeader(rest,L"X-Atlassian-Token",L"no-check");
CkRestW_AddHeader(rest,L"Accept",L"application/json");
strResponseBody = CkRestW_fullRequestMultipart(rest,L"POST",L"/rest/api/2/issue/SCRUM-15/attachments");
if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkStreamW_Dispose(fileStream1);
CkStreamW_Dispose(fileStream2);
CkStreamW_Dispose(fileStream3);
return;
}
respStatusCode = CkRestW_getResponseStatusCode(rest);
if (respStatusCode >= 400) {
wprintf(L"Response Status Code = %d\n",respStatusCode);
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkRestW_responseHeader(rest));
wprintf(L"Response Body:\n");
wprintf(L"%s\n",strResponseBody);
CkRestW_Dispose(rest);
CkStreamW_Dispose(fileStream1);
CkStreamW_Dispose(fileStream2);
CkStreamW_Dispose(fileStream3);
return;
}
jsonResponse = CkJsonArrayW_Create();
CkJsonArrayW_Load(jsonResponse,strResponseBody);
arrIdx = 0;
numArrayObjects = CkJsonArrayW_getSize(jsonResponse);
// Iterate over the members of the array.
while (arrIdx < numArrayObjects) {
// Make sure the array member at this index is a JSON object.
if (CkJsonArrayW_TypeAt(jsonResponse,arrIdx) == 3) {
jObj = CkJsonArrayW_ObjectAt(jsonResponse,arrIdx);
// ...
CkJsonObjectW_Dispose(jObj);
}
arrIdx = arrIdx + 1;
}
CkRestW_Dispose(rest);
CkStreamW_Dispose(fileStream1);
CkStreamW_Dispose(fileStream2);
CkStreamW_Dispose(fileStream3);
CkJsonArrayW_Dispose(jsonResponse);
}
[
{
"self": "https://chilkat.atlassian.net/rest/api/2/attachment/10001",
"id": "10001",
"filename": "starfish.jpg",
"author": {
"self": "https://chilkat.atlassian.net/rest/api/2/user?username=admin",
"name": "admin",
"key": "admin",
"accountId": "557058:be8b47b5-3bc0-43f6-b6b2-2cca0de12204",
"emailAddress": "admin@@chilkatsoft.com",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "Chilkat Admin",
"active": true,
"timeZone": "America/Chicago"
},
"created": "2018-04-13T10:04:44.966-0500",
"size": 6229,
"mimeType": "image/jpeg",
"content": "https://chilkat.atlassian.net/secure/attachment/10001/starfish.jpg",
"thumbnail": "https://chilkat.atlassian.net/secure/thumbnail/10001/starfish.jpg"
},
{
"self": "https://chilkat.atlassian.net/rest/api/2/attachment/10002",
"id": "10002",
"filename": "sample2.docx",
"author": {
"self": "https://chilkat.atlassian.net/rest/api/2/user?username=admin",
"name": "admin",
"key": "admin",
"accountId": "557058:be8b47b5-3bc0-43f6-b6b2-2cca0de12204",
"emailAddress": "admin@@chilkatsoft.com",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "Chilkat Admin",
"active": true,
"timeZone": "America/Chicago"
},
"created": "2018-04-13T10:04:45.706-0500",
"size": 21082,
"mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"content": "https://chilkat.atlassian.net/secure/attachment/10002/sample2.docx"
},
{
"self": "https://chilkat.atlassian.net/rest/api/2/attachment/10003",
"id": "10003",
"filename": "sample.pdf",
"author": {
"self": "https://chilkat.atlassian.net/rest/api/2/user?username=admin",
"name": "admin",
"key": "admin",
"accountId": "557058:be8b47b5-3bc0-43f6-b6b2-2cca0de12204",
"emailAddress": "admin@@chilkatsoft.com",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "Chilkat Admin",
"active": true,
"timeZone": "America/Chicago"
},
"created": "2018-04-13T10:04:46.292-0500",
"size": 178399,
"mimeType": "application/pdf",
"content": "https://chilkat.atlassian.net/secure/attachment/10003/sample.pdf"
}
]