Project

General

Profile

406 Not Acceptable when using REST Issues API

Added by Stephen Dolan over 13 years ago

I'm using redmine-1.0.0RC (from the 1.0-stable SVN branch), and I can't get the Issues API to return anything other than 406 errors. I've tried the various samples in Ruby and PHP, as well as wget/python/etc. Here's a sample HTTP session (from the PHP ActiveRecord):

GET /projects/netsoc/issues.xml HTTP/1.1
Authorization: Basic <password info omitted>
Host: <hostname omitted>
Accept: */*
Content-Type: text/xml
Length: 54

HTTP/1.1 406 Not Acceptable
Date: Mon, 26 Jul 2010 18:22:54 GMT
Server: lighttpd/1.4.26
Content-Type: text/html; charset=utf-8
Set-Cookie: _redmine_default=<long string omitted>; path=/; HttpOnly
X-Runtime: 114ms
Content-Length: 1
Cache-Control: no-cache

The authentication at least is working, as it gives a 401 rather than 406 error if the password is wrong. There's no error message, and no logfiles that I can find.

Configuration:
Running on lighttpd/1.4.26 via FastCGI
Ruby version 1.8.7 (x86_64-linux)
RubyGems version 1.3.5
Rack version 1.0
Rails version 2.3.5
Active Record version 2.3.5
Active Resource version 2.3.5
Action Mailer version 2.3.5
Active Support version 2.3.5
Application root /opt/redmine-1.0
Environment production
Database adapter mysql
Database schema version 20100705164950


Replies (19)

RE: 406 Not Acceptable when using REST Issues API - Added by Felix Schäfer over 13 years ago

I think you need to set the type of you are accepting, i.e. Accept: text/xml or something.

RE: 406 Not Acceptable when using REST Issues API - Added by Felix Schäfer over 13 years ago

Felix Schäfer wrote:

I think you need to set the type of you are accepting

That should read "of what you are expecting"...

RE: 406 Not Acceptable when using REST Issues API - Added by Taras Bunyk over 13 years ago

"Accept: text/xml" don't work either.

~$ curl -v -H 'Accept: text/xml' http://localhost/redmine/issues.xml
* About to connect() to localhost port 80 (#0)
*   Trying ::1... connected
* Connected to localhost (::1) port 80 (#0)
> GET /redmine/issues.xml HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: localhost
> Accept: text/xml
> 
< HTTP/1.1 406 Not Acceptable
< Date: Tue, 27 Jul 2010 08:21:05 GMT
< Server: Apache/2.2.14 (Ubuntu)
< X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.7
< X-Runtime: 182ms
< Cache-Control: no-cache
< Set-Cookie: _redmine_default=BAh7CCIWaXNzdWVzX2luZGV4X3NvcnQiDGlkOmRlc2M6CnF1ZXJ5ewk6EWNvbHVtbl9uYW1lczA6D3Byb2plY3RfaWQwOg1ncm91cF9ieTA6DGZpbHRlcnN7BiIOc3RhdHVzX2lkewc6DW9wZXJhdG9yIgZvOgt2YWx1ZXNbBiIAIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--41d73ceadfe22b495f9f0288168f397680d1179b; path=/redmine; HttpOnly
< Content-Length: 1
< Status: 406 Not Acceptable
< Vary: Accept-Encoding
< Content-Type: text/html; charset=utf-8
< 
* Connection #0 to host localhost left intact
* Closing connection #0

RE: 406 Not Acceptable when using REST Issues API - Added by Felix Schäfer over 13 years ago

You do have the REST API enabled, right?

Anyway, I just tried on my install to make sure it wasn't something with curl or anything, and it works like a charm (left out the data to not clobber the output):

$ curl -v http://orga.fachschaften.org/projects.xml
* About to connect() to orga.fachschaften.org port 80 (#0)
*   Trying 129.217.6.42... connected
* Connected to orga.fachschaften.org (129.217.6.42) port 80 (#0)
> GET /projects.xml HTTP/1.1
> User-Agent: curl/7.21.0 (x86_64-apple-darwin10.4.0) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.5 libidn/1.19
> Host: orga.fachschaften.org
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Tue, 27 Jul 2010 08:42:45 GMT
< Server: Apache
< X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.15
< ETag: "bfce9b25b660ec336453f21ac917784a" 
< X-Runtime: 18
< Cache-Control: private, max-age=0, must-revalidate
< Set-Cookie: _redmine=09b4043269483641c1551d04a0229cdd; path=/; expires=Thu, 29 Jul 2010 08:42:45 GMT; HttpOnly
< Content-Length: 6246
< Status: 200
< Vary: User-Agent
< Content-Type: application/xml; charset=utf-8
< 
* Connection #0 to host orga.fachschaften.org left intact
* Closing connection #0

Feel free to use the same URL I did to make sure your calls work properly.

RE: 406 Not Acceptable when using REST Issues API - Added by Taras Bunyk over 13 years ago

You do have the REST API enabled, right?

Yes, i too think that it is something with my installation, because http://orga.fachschaften.org/projects.xml works even in browser. Then how to check is REST API enabled, and how to enable it?

And thanks for your help.

RE: 406 Not Acceptable when using REST Issues API - Added by Felix Schäfer over 13 years ago

It's the last checkbox in Administration > Configuration > Authentication.

RE: 406 Not Acceptable when using REST Issues API - Added by Taras Bunyk over 13 years ago

Yes of course. I just thought it was "To enable API-style authentication".

May be problem is because i install it from Ubuntu repositories and version is "0.9.3.stable (SQLite)" ?

RE: 406 Not Acceptable when using REST Issues API - Added by Felix Schäfer over 13 years ago

Taras Bunyk wrote:

May be problem is because i install it from Ubuntu repositories and version is "0.9.3.stable (SQLite)" ?

Oh, I thought you were the original poster who had said he has 1.0.0. Vanilla 0.9.3 only supports REST API for projects IIRC, and I can't say works in the ubuntu version because they patch it to make it work with older rails versions.

RE: 406 Not Acceptable when using REST Issues API - Added by Taras Bunyk over 13 years ago

Now all is clearer. Thanks for comments.

RE: 406 Not Acceptable when using REST Issues API - Added by Stephen Dolan over 13 years ago

I'd tried messing with Accept headers with no success. The REST API was definitely enabled.

I tried running it via Webrick, and everything worked as expected. There seems to have been some issue in our lighttpd/FastCGI setup (possibly lighty parsed + stripped the Accept header? can this happen?). I couldn't figure out exactly what the issue was, so just moved it over to a lighttpd + mod_proxy + Thin setup instead, where the API now works (even with Accept: */*).

Thanks all,
Stephen

RE: 406 Not Acceptable when using REST Issues API - Added by Stephen Dolan over 13 years ago

Another question: Is it possible to set issue status via the REST API? It seems like a fairly basic feature...

RE: 406 Not Acceptable when using REST Issues API - Added by Felix Schäfer over 13 years ago

Should work by PUTting an xml of the form <issue><status_id>3</status_id></issue> to http://your.redmi.ne/issues/6.xml&key=1a022b4661da64e5dca53ebab0c94ad7, or that's how I would expect it to work.

RE: 406 Not Acceptable when using REST Issues API - Added by Alex Last over 13 years ago

I have a similar problem. I have a new Redmine install v. 0.9.6 and I'm trying to get list of issues through REST API. I'm getting

GET http://<server>.com:80/projects/tools/issues.xml?key=087a6cd6077a14fc1968af0e92949d1c6d30757a HTTP/1.1
----------------------------------------
HTTP/1.1 406 Not Acceptable
Response length: 1 type=Content-Type: text/html; charset=utf-8

this is the Java code I'm using (with Apache HttpClient library):

    static String apiAccessKey = "087a6cd6077a14fc1968af0e92949d1c6d30757a";
    static int port = 80;
    static String host = ".......com";
    static String url = "http://" + host + ":" + port
                        + "/projects/tools/issues.xml";
    public static void main(String[] args) throws ClientProtocolException,
            IOException {
         doGet();
    }
    private static void doGet() throws IOException, ClientProtocolException {
        url += "?key=" + apiAccessKey;
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(url);
//        httpget.addHeader("Accept", "application/xml");
        System.out.println("executing request:\n" + httpget.getRequestLine());
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (entity != null) {
            System.out.println("Response length: " 
                    + entity.getContentLength() + " type=" + entity.getContentType());
        }
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }

the same request sent to another Redmine server (which is running last TRUNK Redmine version and is started via "ruby script/server webrick -e production") works fine:

GET http://172.17.10.53:3000/projects/sep/issues.xml?key=fc20e8f5f1885fc194b7b7865e6d6ce9a44a4b88 HTTP/1.1
----------------------------------------
HTTP/1.1 200 OK
Response length: 8525 type=Content-Type: application/xml; charset=utf-8

I tried setting

httpget.addHeader("Accept", "application/xml");

but this didn't help. how can I check why I'm getting this bogus "406" error?

server shows:

Processing IssuesController#index to xml (for 172.17.10.56 at 2010-08-10 15:41:27) [GET]
  Parameters: {"format"=>"xml", "project_id"=>"sep", "action"=>"index", "controller"=>"issues", "key"=>"087a6cd6077a14fc1968af0e92949d1c6d30757a"}
  SQL (0.8ms)   SELECT max("settings".updated_on) AS max_updated_on FROM "settings" 
  User Load (0.7ms)   SELECT * FROM "users" WHERE ("users"."id" = 130) AND (users.status = 1) AND ( ("users"."type" = 'User' OR "users"."type" = 'AnonymousUser' ) )
  Project Load (0.4ms)   SELECT * FROM "projects" WHERE ("projects"."identifier" = E'sep') LIMIT 1
  EnabledModule Load (0.3ms)   SELECT * FROM "enabled_modules" WHERE ("enabled_modules".project_id = 12)
  IssueCustomField Load (0.5ms)   SELECT * FROM "custom_fields" WHERE (is_for_all='t') AND ( ("custom_fields"."type" = 'IssueCustomField' ) ) ORDER BY position
  IssueCustomField Load (1.2ms)   SELECT * FROM "custom_fields" INNER JOIN "custom_fields_projects" ON "custom_fields".id = "custom_fields_projects".custom_field_id WHERE ("custom_fields_projects".project_id = 12 ) AND ( ("custom_fields"."type" = 'IssueCustomField' ) ) ORDER BY custom_fields.position
  SQL (0.6ms)   SELECT count(*) AS count_all FROM "projects" WHERE (((projects.status = 1) AND (projects.id != 12)) AND (projects."lft" >= 5 AND projects."rgt" <= 8))
  Project Load (0.5ms)   SELECT * FROM "projects" WHERE ((projects.id != 12) AND (projects."lft" >= 5 AND projects."rgt" <= 8)) ORDER BY "lft" 
  SQL (11.5ms)   SELECT count(DISTINCT "issues".id) AS count_all FROM "issues" LEFT OUTER JOIN "issue_statuses" ON "issue_statuses".id = "issues".status_id LEFT OUTER JOIN "projects" ON "projects".id = "issues".project_id WHERE ((issue_statuses.is_closed='f') AND projects.id IN (12,15) AND projects.status=1 AND projects.id IN (SELECT em.project_id FROM enabled_modules em WHERE em.name='issue_tracking'))
  CACHE (0.0ms)   SELECT count(*) AS count_all FROM "projects" WHERE (((projects.status = 1) AND (projects.id != 12)) AND (projects."lft" >= 5 AND projects."rgt" <= 8))
  CACHE (0.0ms)   SELECT * FROM "projects" WHERE ((projects.id != 12) AND (projects."lft" >= 5 AND projects."rgt" <= 8)) ORDER BY "lft" 
  Issue Load Including Associations (124.5ms)   SELECT "issues"."id" AS t0_r0, "issues"."tracker_id" AS t0_r1, "issues"."project_id" AS t0_r2, "issues"."subject" AS t0_r3, "issues"."description" AS t0_r4, "issues"."due_date" AS t0_r5, "issues"."category_id" AS t0_r6, "issues"."status_id" AS t0_r7, "issues"."assigned_to_id" AS t0_r8, "issues"."priority_id" AS t0_r9, "issues"."fixed_version_id" AS t0_r10, "issues"."author_id" AS t0_r11, "issues"."lock_version" AS t0_r12, "issues"."created_on" AS t0_r13, "issues"."updated_on" AS t0_r14, "issues"."start_date" AS t0_r15, "issues"."done_ratio" AS t0_r16, "issues"."estimated_hours" AS t0_r17, "issue_statuses"."id" AS t1_r0, "issue_statuses"."name" AS t1_r1, "issue_statuses"."is_closed" AS t1_r2, "issue_statuses"."is_default" AS t1_r3, "issue_statuses"."position" AS t1_r4, "issue_statuses"."default_done_ratio" AS t1_r5, "projects"."id" AS t2_r0, "projects"."name" AS t2_r1, "projects"."description" AS t2_r2, "projects"."homepage" AS t2_r3, "projects"."is_public" AS t2_r4, "projects"."parent_id" AS t2_r5, "projects"."created_on" AS t2_r6, "projects"."updated_on" AS t2_r7, "projects"."identifier" AS t2_r8, "projects"."status" AS t2_r9, "projects"."lft" AS t2_r10, "projects"."rgt" AS t2_r11, "users"."id" AS t3_r0, "users"."login" AS t3_r1, "users"."hashed_password" AS t3_r2, "users"."firstname" AS t3_r3, "users"."lastname" AS t3_r4, "users"."mail" AS t3_r5, "users"."mail_notification" AS t3_r6, "users"."admin" AS t3_r7, "users"."status" AS t3_r8, "users"."last_login_on" AS t3_r9, "users"."language" AS t3_r10, "users"."auth_source_id" AS t3_r11, "users"."created_on" AS t3_r12, "users"."updated_on" AS t3_r13, "users"."type" AS t3_r14, "users"."identity_url" AS t3_r15, "trackers"."id" AS t4_r0, "trackers"."name" AS t4_r1, "trackers"."is_in_chlog" AS t4_r2, "trackers"."position" AS t4_r3, "trackers"."is_in_roadmap" AS t4_r4, "enumerations"."id" AS t5_r0, "enumerations"."name" AS t5_r1, "enumerations"."position" AS t5_r2, "enumerations"."is_default" AS t5_r3, "enumerations"."type" AS t5_r4, "enumerations"."active" AS t5_r5, "enumerations"."project_id" AS t5_r6, "enumerations"."parent_id" AS t5_r7, "issue_categories"."id" AS t6_r0, "issue_categories"."project_id" AS t6_r1, "issue_categories"."name" AS t6_r2, "issue_categories"."assigned_to_id" AS t6_r3, "versions"."id" AS t7_r0, "versions"."project_id" AS t7_r1, "versions"."name" AS t7_r2, "versions"."description" AS t7_r3, "versions"."effective_date" AS t7_r4, "versions"."created_on" AS t7_r5, "versions"."updated_on" AS t7_r6, "versions"."wiki_page_title" AS t7_r7, "versions"."status" AS t7_r8, "versions"."sharing" AS t7_r9 FROM "issues" LEFT OUTER JOIN "issue_statuses" ON "issue_statuses".id = "issues".status_id LEFT OUTER JOIN "projects" ON "projects".id = "issues".project_id LEFT OUTER JOIN "users" ON "users".id = "issues".assigned_to_id AND ("users"."type" = 'User' OR "users"."type" = 'AnonymousUser' ) LEFT OUTER JOIN "trackers" ON "trackers".id = "issues".tracker_id LEFT OUTER JOIN "enumerations" ON "enumerations".id = "issues".priority_id AND ("enumerations"."type" = 'IssuePriority' ) LEFT OUTER JOIN "issue_categories" ON "issue_categories".id = "issues".category_id LEFT OUTER JOIN "versions" ON "versions".id = "issues".fixed_version_id WHERE (((issue_statuses.is_closed='f') AND projects.id IN (12,15) AND projects.status=1 AND projects.id IN (SELECT em.project_id FROM enabled_modules em WHERE em.name='issue_tracking'))) ORDER BY issues.id DESC LIMIT 25 OFFSET 0
Completed in 526ms (View: 1, DB: 141) | 406 Not Acceptable [http://......com/projects/sep/issues.xml?key=087a6cd6077a14fc1968af0e92949d1c6d30757a]

RE: 406 Not Acceptable when using REST Issues API - Added by Alex Last over 13 years ago

both servers have "Enable REST web service: ON"

RE: 406 Not Acceptable when using REST Issues API - Added by Alex Last over 13 years ago

oh, and also -
authentication is working fine for both servers. I get "401" error when provide an invalid key:

WARNING: Authentication error: Unable to respond to any of these challenges: {}
----------------------------------------
HTTP/1.1 401 Authorization Required
Response length: 1 type=Content-Type: application/xml; charset=utf-8

RE: 406 Not Acceptable when using REST Issues API - Added by Felix Schäfer over 13 years ago

Alexey Skor wrote:

I have a similar problem. I have a new Redmine install v. 0.9.6 and I'm trying to get list of issues through REST API.

The Issue REST API is available in 1.0 and up only.

RE: 406 Not Acceptable when using REST Issues API - Added by Alex Last over 13 years ago

why do I see "Enable REST web service" option in 0.9.6 web interface then?

    (1-19/19)