Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7687039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:36:46+00:00 2026-05-31T19:36:46+00:00

I have been looking for a way to remove an attachment from Jira using

  • 0

I have been looking for a way to remove an attachment from Jira using the SOAP Api, but it seems that this is not possible natively, and I would prefer not having to implement a new plugin for Jira, as suggested in the accepted answer to this question, or recompiling the existing plugin to support this as mentioned here.

This answer to the abovementioned question seems to do exactly what I want, but alas, I can’t get i to work. The response i get is an error stating that:

XSRF Security Token Missing

JIRA could not complete this action due to a missing form token.

You may have cleared your browser cookies, which could have resulted in the expiry of your current form token. A new form token has been reissued.

As I am using Asp.Net MVC C#, I have used the code from the answer, as is, with only the server url adjusted, as well as with different credentials (a Jira user) and the username/password passed through as request parameters using:

os_username=jirausername&os_password=xxxxxxx

The code I am currently using is as follows:

public void RemoveAttachment(string issueid, string attachmentid)
        {
            using (System.Net.WebClient client = new System.Net.WebClient())
            {
                //Compute jira server base url from WS url
                string baseUrl = _service.Url.Substring(0, _service.Url.IndexOf("/rpc/"));

                //Compute complete attachment url
                string attachmenturl = baseUrl + "/secure/DeleteAttachment.jspa?id=" +
                                       issueid + "&deleteAttachmentId=" + attachmentid;

                client.Credentials = new System.Net.NetworkCredential("jirausername", "xxxxxxx");
                string response = client.DownloadString(attachmenturl);
            }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:36:47+00:00Added an answer on May 31, 2026 at 7:36 pm

    I ended up using a method that first requests the deletion confirmation form, then extracts a required token from the form, and finally posts something equivalent to the form content in order to delete the attachment. Code below.

    public void RemoveAttachment(string issueid, string attachmentid)
    {
        //Compute jira server base url from WS url
        string baseUrl = _service.Url.Substring(0, _service.Url.IndexOf("/rpc/"));
    
        //Compute complete attachment deletion confirm url
        string confirmurl = baseUrl + "/secure/DeleteAttachment!default.jspa?id=" +
                     issueid + "&deleteAttachmentId=" + attachmentid + "&os_username=jirauser&os_password=xxxxxx";
    
        //Create a cookie container to maintain the xsrf security token cookie.
        CookieContainer jiracontainer = new CookieContainer();
    
        //Create a get request for the page containing the delete confirmation.
        HttpWebRequest confirmrequest = (HttpWebRequest)WebRequest.Create(confirmurl);
        confirmrequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
        confirmrequest.CookieContainer = jiracontainer;
    
        //Get the response and the responsestream.
        WebResponse confirmdeleteresponse = confirmrequest.GetResponse();
        Stream ReceiveStream = confirmdeleteresponse.GetResponseStream();
    
        // Open the stream using a StreamReader for easy access.
        StreamReader confirmreader = new StreamReader(ReceiveStream);
        // Read the content.
        string confirmresponse = confirmreader.ReadToEnd();
    
        //Create a regex to extract the atl/xsrf token from a hidden field. (Might be nicer to read it from a cookie, which should also be possible).
        Regex atl_token_matcher = new Regex("<input[^>]*id=\"atl_token\"[^>]*value=\"(?<token>\\S+)\"[^>]*>", RegexOptions.Singleline);
        Match token_match = atl_token_matcher.Match(confirmresponse);
    
        if (token_match.Success)
        {
            //If we found the token get the value.
            string token = token_match.Groups["token"].Value;
    
            //Compute attachment delete url.
            string deleteurl = baseUrl + "/secure/DeleteAttachment.jspa";
    
            //Construct form data.
            string postdata = "atl_token=" + HttpContext.Current.Server.UrlEncode(token) + "&id=" + issueid + "&deleteAttachmentId=" + attachmentid + "&Delete=Delete&os_username=jirauser&os_password=xxxxxx";
    
            //Create a post request for the deletion page.
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(deleteurl);
            request.KeepAlive = false;
            request.CookieContainer = jiracontainer; // Remember to set the cookiecontainer.
            request.ProtocolVersion = HttpVersion.Version10;
            request.Method = "POST";
    
            //Turn our request string into a byte stream
            byte[] postBytes = Encoding.ASCII.GetBytes(postdata);
    
            //Make sure you specify the proper type.
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = postBytes.Length;
            Stream requestStream = request.GetRequestStream();
    
            //Send the post.
            requestStream.Write(postBytes, 0, postBytes.Length);
            requestStream.Close();
    
            //Get the response.
            WebResponse deleteresponse = request.GetResponse();
    
            // Open the responsestream using a StreamReader for easy access.
            StreamReader deleteresponsereader = new StreamReader(deleteresponse.GetResponseStream());
    
            // Read the content.
            string deleteresponsecontent = deleteresponsereader.ReadToEnd();
    
            // do whatever validation/reporting with the response...
        }
        else
        {
            //We couldn't find the atl_token. Throw an error or something...
        }
    
    }
    

    Edit:
    Same thing works for removing comments. Replace ‘attachment’ with ‘comment’ and ‘deleteAttachmentId’ with ‘commentId’ and you should be good to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling looking for an understandable way to do this. I have four
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I know that this question has been asked before, but I'm looking for a
I have been looking for a way to get rid of the nasty black
I have been looking for a way to allow users to manually override geolocation
I have been looking to implement a custom class of : IList<ArraySegment<byte>> this will
I've been looking at some server logs using tail -f recently, and have thought
I've been looking at the Facebook API to find some way to edit a
i have been looking through the different questions as to how to remove spaces
Is there any way that you can remove IPs from a string? The input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.