Project

General

Profile

Format for creating a project via REST API using JSON?

Added by Matthias Paul Scholz over 12 years ago

I am one of the developers of the Java Redmine API project and am presently evaluating the possibility of switching from XML-based communication with the REST API to a JSON-based one.

While fetching projects via JSON works fine, I am running into troubles with creating a project: any of the JSON-Strings I am trying for specifying the project in the request to the REST API triggers a Redmine 500 error.

Sadly, the concrete JSON string required is not specified on the according REST API documentation for projects, so I tried to deduce the correct format from the response to a JSON-based GET request for a project by its identifier.
Yet, no success with the string

{"project":{"identifier":"test1330610227803","name":"test project"}}

What am I doing wrong?
How should the concrete project definition look like when using JSON?

I am running against a Redmine 1.3.1 instance.

When using XML, creation of projects works fine, so it shouldn't be a configuration nor a credentials issue.


Replies (6)

RE: Format for creating a project via REST API using JSON? - Added by Jean-Philippe Lang over 12 years ago

This format is correct and works fine for me. Could you give some details about your 500 error?

RE: Format for creating a project via REST API using JSON? - Added by Matthias Paul Scholz over 12 years ago

I tried it on my local Redmine 1.3 instance and the production.log (set to :debug) reveals the error stack added below.
Strangely enough, this looks like Redmine internally trying to interpret that as XML (?), though my post call is

POST http://localhost/redmine/projects.json?include=trackers HTTP/1.1

Stack:

{"project":{"identifier":"test1330692295778","name":"test project"}}
/!\ FAILSAFE /!\  Fri Mar 02 13:45:09 +0100 2012
  Status: 500 Internal Server Error
  undefined method `name' for nil:NilClass
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/xml_mini/rexml.rb:29:in `merge_element!'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/xml_mini/rexml.rb:18:in `parse'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/xml_mini.rb:12:in `__send__'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/xml_mini.rb:12:in `parse'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/core_ext/hash/conversions.rb:164:in `from_xml'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/params_parser.rb:34:in `parse_formatted_parameters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/params_parser.rb:11:in `call'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/session/cookie_store.rb:99:in `call'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/failsafe.rb:26:in `call'
    /usr/lib/ruby/gems/1.8/gems/rack-1.1.2/lib/rack/lock.rb:11:in `call'
    /usr/lib/ruby/gems/1.8/gems/rack-1.1.2/lib/rack/lock.rb:11:in `synchronize'
    /usr/lib/ruby/gems/1.8/gems/rack-1.1.2/lib/rack/lock.rb:11:in `call'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:106:in `call'
    /usr/lib/ruby/1.8/phusion_passenger/rack/request_handler.rb:92:in `process_request'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
    /usr/lib/ruby/1.8/phusion_passenger/railz/application_spawner.rb:418:in `start_request_handler'
    /usr/lib/ruby/1.8/phusion_passenger/railz/application_spawner.rb:358:in `handle_spawn_application'
    /usr/lib/ruby/1.8/phusion_passenger/utils.rb:184:in `safe_fork'
    /usr/lib/ruby/1.8/phusion_passenger/railz/application_spawner.rb:354:in `handle_spawn_application'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server.rb:352:in `__send__'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server.rb:352:in `main_loop'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server.rb:163:in `start'
    /usr/lib/ruby/1.8/phusion_passenger/railz/application_spawner.rb:213:in `start'
    /usr/lib/ruby/1.8/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
    /usr/lib/ruby/1.8/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
    /usr/lib/ruby/1.8/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'
    /usr/lib/ruby/1.8/phusion_passenger/spawn_manager.rb:154:in `spawn_application'
    /usr/lib/ruby/1.8/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server.rb:352:in `__send__'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server.rb:352:in `main_loop'
    /usr/lib/ruby/1.8/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
    /usr/lib/phusion_passenger/passenger-spawn-server:61 

RE: Format for creating a project via REST API using JSON? - Added by Matthias Paul Scholz over 12 years ago

Any feedback?

I am going to file that as a bug, will I?

RE: Format for creating a project via REST API using JSON? - Added by Etienne Massip over 12 years ago

Setting Content-Type: application/json in HTTP headers should help you.

RE: Format for creating a project via REST API using JSON? - Added by Matthias Paul Scholz over 12 years ago

Merci Etienne.
That helped. :)
Have it working now after setting the content type correctly.

Maybe it would be useful to provide some more info regarding JSON access in the REST API documentation than presently - it's pretty much focused on XML currently.

    (1-6/6)