cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot delete tags. I'm using API Rest Alfresco

awaxisnei
Champ in-the-making
Champ in-the-making
Hi,

I can´t delete document tags and Alfresco tags using APIRest.

I`m creating Request Delete with the following url:

String url = server + "/alfresco/service/api/tags/workspace/SpacesStore/" + nameTag + "?alf_ticket=" + ticket;

And the error is:

Remote Server Error (405) Method not allowed.

- The Server, nameTag and ticket are correct.


I need help!! Thanks!
8 REPLIES 8

kaynezhang
World-Class Innovator
World-Class Innovator
I have tested it ,it works fine,there must be something wrong with your code. Following is my test code
   HttpClient client = new HttpClient();      client.getState().setCredentials(            new AuthScope("localhost", 8080, "Alfresco"),            new UsernamePasswordCredentials("admin", "admin"));      String apiurl = "http://localhost:8080/alfresco/service/api/tags/workspace/SpacesStore/tag1";      DeleteMethod delete = new DeleteMethod(apiurl);      try {         delete.setDoAuthentication(true);         int status = client.executeMethod(delete);         if (status != HttpStatus.SC_OK) {            System.err.println("Method failed: " + delete.getStatusLine());         }         String resultString = delete.getResponseBodyAsString();         System.out.println(resultString);      } catch (Exception e) {         e.printStackTrace();      } finally {         delete.releaseConnection();      }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

awaxisnei
Champ in-the-making
Champ in-the-making
¡¡Thanks!!

My code is in C# .net. I forgot to tell it

I Have an Exception: Server error 405 . Method not allowed



I have this methods:


 public string sendDelete(string endPoint)        {            HttpWebRequest request = CreateWebRequestDelete(endPoint);            try            {                using (var response = (HttpWebResponse)request.GetResponse())                {                    var responseValue = string.Empty;                    if (response.StatusCode != HttpStatusCode.OK)                    {                        string message = String.Format("DELETE failed. Received HTTP {0}", response.StatusCode);                        throw new ApplicationException(message);                    }                    // grab the response                      using (var responseStream = response.GetResponseStream())                    {                        using (var reader = new StreamReader(responseStream))                        {                            responseValue = reader.ReadToEnd();                        }                    }                    return responseValue;                }            }            catch (Exception ex)            {                return null;            }        } private HttpWebRequest CreateWebRequestDelete(string endPoint)        {            var request = (HttpWebRequest)WebRequest.Create(endPoint);            request.Method = "DELETE";            request.ContentLength = 0;            request.ContentType = "text/xml";            return request;        } public string deleteTag(string nameTag)        {            try            {                String ticket = admon.getTicketConector();                String url = server + "/alfresco/service/api/tags/workspace/SpacesStore/" + nameTag + "?alf_ticket=" + ticket;                return sendDelete(url);            }            catch(Exception ex)            {                throw ex;            }        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

kaynezhang
World-Class Innovator
World-Class Innovator
I have tested your code ,it works fine.Following is test code ,you can test it
       public string sendDelete(string endPoint)        {            HttpWebRequest request = CreateWebRequestDelete(endPoint);            try            {                using (var response = (HttpWebResponse)request.GetResponse())                {                    var responseValue = string.Empty;                    if (response.StatusCode != HttpStatusCode.OK)                    {                        string message = String.Format("DELETE failed. Received HTTP {0}", response.StatusCode);                        throw new ApplicationException(message);                    }                    // grab the response                      using (var responseStream = response.GetResponseStream())                    {                        using (var reader = new StreamReader(responseStream))                        {                            responseValue = reader.ReadToEnd();                        }                    }                    Console.WriteLine(responseValue);                    return responseValue;                }            }            catch (Exception ex)            {                return null;            }        }        private HttpWebRequest CreateWebRequestDelete(string endPoint)        {            var request = (HttpWebRequest)WebRequest.Create(endPoint);            request.Method = "DELETE";            request.ContentLength = 0;            request.ContentType = "text/xml";            return request;        }        public string deleteTag(string nameTag)        {            try            {                String ticket = getTicketConector();                String url = server + "alfresco/service/api/tags/workspace/SpacesStore/" + nameTag + "?alf_ticket=" + ticket;                return sendDelete(url);            }            catch (Exception ex)            {                throw ex;            }        }        public string getTicketConector()        {            String ticket = null;            string URI = server + "alfresco/service/api/login?u=admin&pw=admin";            HttpWebRequest request = WebRequest.Create(URI) as HttpWebRequest;            //request.Method = "POST";            //request.ContentType = "application/x-www-form-urlencoded";            try            {                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)                {                    StreamReader sr = new StreamReader(response.GetResponseStream());                    XmlDocument xml = new XmlDocument();                    xml.LoadXml(sr.ReadToEnd());                    XmlNode root = xml.SelectSingleNode("/ticket");                    ticket = root.InnerText;                }            }            catch (Exception e)            {                return (e.Message + Environment.NewLine + e.StackTrace);            }            return ticket;        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

awaxisnei
Champ in-the-making
Champ in-the-making
Thanks, kaynezhang!!!

But I have the same error… I`ve test your code and the server throw the following exception: http code: 405 Method not allowed.

Could it be for the permits of user?. I have admin permission but I am not de administrator or creator of Alfresco repository…

kaynezhang
World-Class Innovator
World-Class Innovator
Which version of afresco are you using?  it might be a bug.
I don't think it is a permission problem,but yuou can give it a try and  test it with admin user account

awaxisnei
Champ in-the-making
Champ in-the-making
I tried what you tell me and I have not managed to remove a tag.

Thanks for all!

kaynezhang
World-Class Innovator
World-Class Innovator
You can download a newer version of alfresco ,and test it to verify if it is a bug of your version

awaxisnei
Champ in-the-making
Champ in-the-making
Hi!! Could I delete a tag for a node?

I have a 3.4.d version of community Alfresco.


Thanks!!