POST request example to create Issue through REST API

Added by Alex Last almost 8 years ago

I don't see any examples what exactly to send in POST request to create an issue. The wiki page only says "use POST /issues.xml".
how do I pass API access key? how do I pass the Issue parameters?

I tried the following:

URL:

https://www.hostedredmine.com/projects/taskconnector-test/issues.xml

POST request body:

key=293a64eef15b452047a0315ecc6eff2a9bbd4a9c<?xml version="1.0" encoding="UTF-8"?><issue><subject>Issue_from_REST_API</subject><project_id>dummy</project_id></issue></xml>

should I move "key" to the URL? are there any parameters I need to provide in the request before sending the XML body?

I'm getting

Resp Code:405
Resp Message:Method Not Allowed

Replies (9)

RE: POST request example to create Issue through REST API - Added by Alex Last almost 8 years ago

this is the code I'm trying now (Java):

    private static void doPost() throws IOException, ClientProtocolException {

        DefaultHttpClient httpclient = new DefaultHttpClient();

        httpclient.getCredentialsProvider().setCredentials(
                new AuthScope(host, port),
                new UsernamePasswordCredentials("admin", "admin"));

        HttpPost httpPost = new HttpPost(url);

        System.out.println("executing request:\n" + httpPost.getRequestLine());
        HttpEntity entity = new EntityTemplate(cp);
        httpPost.setEntity(entity);
        HttpResponse response = httpclient.execute(httpPost);

        HttpEntity responseEntity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (responseEntity != null) {
            System.out.println("Response content length: " 
                    + responseEntity.getContentLength());
        }
        System.out.println(EntityUtils.toString(responseEntity));
        httpclient.getConnectionManager().shutdown();
    }

    static ContentProducer cp = new ContentProducer() {
        public void writeTo(OutputStream outstream) throws IOException {
            Writer writer = new OutputStreamWriter(outstream, "UTF-8");
            writer.write("format=xml&action=new&");
            writer.write("project_id=1&subject=123123123&tracker_id=1&status_id=1");
            writer.flush();
        }
    };

(I don't see a way to provide "API access key", so had to set user&password instead)

and the response is:

executing request:
POST http://172.17.10.53:3000/projects/ace/issues.xml HTTP/1.1
----------------------------------------
HTTP/1.1 405 Method Not Allowed
Response content length: 1

Note: "GET" request to the same server successfully returns list of issues in XML format.

The server log has:


Processing ApplicationController#new to xml (for 172.18.1.206 at 2010-08-04 19:04:34) [POST]
  Parameters: {"format"=>"xml", "project_id"=>"1", "action"=>"new", "subject"=>"123123123", "tracker_id"=>"1", "status_id"=>"1"}

ActionController::MethodNotAllowed (Only get requests are allowed.):
  /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'

Processing ProjectsController#show (for 127.0.0.1 at 2010-08-04 19:04:42) [GET]
  Parameters: {"action"=>"show", "id"=>"ace", "controller"=>"projects"}
Rendering template within layouts/base
Rendering projects/show

RE: POST request example to create Issue through REST API - Added by Alex Last almost 8 years ago

I see I must use
http://172.17.10.53:3000/issues.xml
instead of
http://172.17.10.53:3000/projects/ace/issues.xml

Mentioning in REST API docs that need to use "<server>/issues.xml" to create issues and
"<server>project/<proj_name>/issues.xml" to list them would have saved hours...

this at least solves the problem with 405 error, but then need to provide "key" somehow.
adding "key" to HTTP header parameters does not help. I have to use basic HTTP authorization (provide username & password), but I need to use API access key.

RE: POST request example to create Issue through REST API - Added by Chrisitian Noack almost 8 years ago

If you want to use the REST API to create an issue from the command line (maybe just for testing), you can do the following:

echo '<issue><project_id>project-01</project_id><subject>test1</subject><description>desc1</description><category_id>1</category_id></issue>' | \
curl -X POST -H 'Content-type: text/xml' \
-H 'Accept: text/xml' -d @- http://localhost:3000/projects/project-01/issues/create?format=xml\&key=1234ab56ef453238392938492839

Replace the above (not valid) key with your own (you find it under "Mein Konto"/"My Account")

RE: POST request example to create Issue through REST API - Added by Alex Last almost 8 years ago

Thanks! I tried your variant and it didn't work for HTTPS connection (on www.hostedredmine.com) -

echo '<issue><subject>task from CURL</subject><project_id>taskconnector-test</project_id></issue>' | \

curl X POST -H 'Content-type: text/xml' \
-H 'Accept: text/xml' -d @
https://www.hostedredmine.com/projects/taskconnector-test/issues/create?format=xml\&key=293a64eef15b452047a0315ecc6eff2a9bbd4a9c

could you please tell me what's wrong with this request? (key and other data is real in the query - feel free to use it. it's just a demo site)

RE: POST request example to create Issue through REST API - Added by Alex Last almost 8 years ago

oops. the URL was improperly formatted by redmine. ignore the "strikethrough" formatting. need to copy the whole URL, including the text with "strikethrough"

RE: POST request example to create Issue through REST API - Added by Alex Last almost 8 years ago

I also tried advice from Eric (Redmine developer):

curl --insecure -X POST -H "Content-Type: text/xml" -d "<issue><subject>api</subject><project_id>taskconnec

tor-test</project_id></issue>" https://293a64eef15b452047a0315ecc6eff2a9bbd4a9c:X@www.hostedredmine.com/issues.xml

this does not print any errors, but does not create any tasks on the server.

RE: POST request example to create Issue through REST API - Added by Brad Rushworth almost 8 years ago

Alexey Skor wrote:

I also tried advice from Eric (Redmine developer):

curl --insecure -X POST -H "Content-Type: text/xml" -d "<issue><subject>api</subject><project_id>taskconnec

tor-test</project_id></issue>" https://293a64eef15b452047a0315ecc6eff2a9bbd4a9c:X@www.hostedredmine.com/issues.xml

this does not print any errors, but does not create any tasks on the server.

I run HostedRedmine.com and I've decided to provide more help to Alexey solve his problem.

When I run the above, I get:

Processing IssuesController#create to xml (for 174.136.100.197 at 2010-08-25 19:05:51) [POST]
  Parameters: {"format"=>"xml", "action"=>"create", "issue"=>{"project_id"=>"taskconnector-test", "subject"=>"api"}, "controller"=>"issues"}
Filter chain halted as [:authorize] rendered_or_redirected.
Completed in 15ms (View: 0, DB: 3) | 401 Unauthorized [https://www.hostedredmine.com/issues.xml]

I seem to get this [:authorize] no matter which API access key I use. I have turned on the REST API in Redmine settings.

You can further follow our discussion here: https://www.hostedredmine.com/issues/2645

RE: POST request example to create Issue through REST API - Added by Alex Last over 7 years ago

this problem was finally fixed in Redmine 1.0.4. Previous Redmine versions did not allow using API access key for some operations.

Paintball - Added by Effesspeeceda Effesspeeceda over 7 years ago

Artistically, I welcome you all again. After my long presence in the forum is not, I could not track down the watchword to your noachian vignette and started a chic one. I'm happy that I am again with you.

(1-9/9)