Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to add attachments while creating issue using Rest Api

Saurabh Bhandari May 19, 2021

Hi, I am trying to add attachments while creating the issue using rest/api/3/issue? api.

{    "issueUpdates": [
        {
            "fields": {
                "summary": "string",
                "issuetype": {
                    "name": "Epic"
                },
                "description": {
                    "type": "doc",
                    "version": 1,
                    "content": [
                        {
                            "type": "paragraph",
                            "content": [
                                {
                                    "text": "string",
                                    "type": "text"
                              }
                            ]
                        }
                    ]
                },
                "project": {
                    "key": "SP"
                },
                "attachment": [
                    {
                        "id": "10003",
                        "filename": "Jira.json",
                        "author": {
                            "self": "https://jb-saurabh.atlassian.net/rest/api/3/user?accountId=5c25230db393bf4ce955eb2c",
                            "accountId": "5c25230db393bf4ce955eb2c",
                            "emailAddress": "saurabh.bhandari@jitterbit.com",
                            "avatarUrls": {
                                "48x48": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5c25230db393bf4ce955eb2c/46526343-ea20-4917-a41c-fcb740972a27/48",
                                "24x24": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5c25230db393bf4ce955eb2c/46526343-ea20-4917-a41c-fcb740972a27/24",
                                "16x16": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5c25230db393bf4ce955eb2c/46526343-ea20-4917-a41c-fcb740972a27/16",
                                "32x32": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5c25230db393bf4ce955eb2c/46526343-ea20-4917-a41c-fcb740972a27/32"
                            },
                            "displayName": "Saurabh Bhandari",
                            "active": true,
                            "timeZone": "Asia/Calcutta",
                            "accountType": "atlassian"
                        },
                        "created": "2021-05-19T12:37:24.332+0530",
                        "size": 155883,
                        "mimeType": "application/json",
                        "content": "https://jb-saurabh.atlassian.net/secure/attachment/10003/Jira.json"
                    }
                ]            }        }    ]
}

 And I am getting the below error :

 

{
    "issues": [],
    "errors": [
        {
            "status": 400,
            "elementErrors": {
                "errorMessages": [],
                "errors": {
                    "attachment": "string expected at index 0"
                }            },
            "failedElementNumber": 0
        }
    ]
  

Can anyone please help me out to find the current payload

Thanks

 

1 answer

1 vote
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 19, 2021

Hi @Saurabh Bhandari 

That is correct, you cannot add an attachment at the time of creating an issue. What you need to do is make a note of the issue key when you create it, then run another API call to add the attachment. I give some C# code in my answer to this post which may help you

Saurabh Bhandari May 19, 2021

thanks @Warren for your reply, But I am getting this attachment node when I request for metadata using rest/api/3/issue/createmeta?projectKeys=SP&issuetypeNames=Epic&expand=projects.issuetypes.fields  for creating a issue

In response, I am getting node for attachment as : 

"attachment": {
                            "required": false,
                            "schema": {
                                "type": "array",
                                "items": "attachment",
                                "system": "attachment"
                            },
                            "name": "Attachment",
                            "key": "attachment",
                            "hasDefaultValue": false,
                            "operations": [
                                "set"
                            ]
                        }

 I think this means we can have attachment data in create issue request.

Please correct me I am doing something wrong

Saurabh Bhandari May 26, 2021

@Warren Can you please check the above details. I am stuck in this. 

Thanks in advance.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events