Project

General

Profile

Creating issue via api

Added by jon morgan over 13 years ago

Hi,

I have the following code that uses httparty in an attempt to create an issue via the api:

self.class.base_uri @api_url
self.class.basic_auth @api_username, @api_password        
self.class.headers 'content-type' => 'text/xml'
self.class.post("/issues.xml", :body => {:issue => {:subject => 'test, :description => 'test, :project_id => 1}})

However whenever this gets run I get the following error, does anyone know what is going wrong and how to fix this?

/!\ FAILSAFE /!\  Sun Oct 31 12:23:22 +0000 2010
  Status: 500 Internal Server Error
  undefined method `name' for nil:NilClass
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/activesupport/lib/active_support/whiny_nil.rb:52:in `method_missing'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/activesupport/lib/active_support/xml_mini/rexml.rb:29:in `merge_element!'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/activesupport/lib/active_support/xml_mini/rexml.rb:18:in `parse'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/activesupport/lib/active_support/xml_mini.rb:12:in `__send__'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/activesupport/lib/active_support/xml_mini.rb:12:in `parse'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/activesupport/lib/active_support/core_ext/hash/conversions.rb:164:in `from_xml'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/actionpack/lib/action_controller/params_parser.rb:34:in `parse_formatted_parameters'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/actionpack/lib/action_controller/params_parser.rb:11:in `call'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/actionpack/lib/action_controller/session/cookie_store.rb:93:in `call'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/actionpack/lib/action_controller/failsafe.rb:26:in `call'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchronize'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:114:in `call'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/actionpack/lib/action_controller/reloader.rb:34:in `run'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:108:in `call'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/railties/lib/rails/rack/static.rb:31:in `call'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in `call'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `each'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `call'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/railties/lib/rails/rack/log_tailer.rb:17:in `call'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:13:in `call'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/chunked.rb:15:in `call'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:64:in `process'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process_client'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process_client'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run'
    /Users/scott/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:34:in `run'
    /Users/scott/rails_apps/redmine-1.0/vendor/rails/railties/lib/commands/server.rb:111
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3


Replies (2)

RE: Creating issue via api - Added by Holger Just over 13 years ago

It seems to me, you are missing some quotation marks in line 4 of your code.
Also, in the request hash which is logged above the quoted stack trace, make sure the params look valid. As they would look when you create the issue by hand.

RE: Creating issue via api - Added by jon morgan over 13 years ago

Hi,

Thanks for your reply, I have tried entering the missing required fields (guess I was expecting this to fall back to the default), unfortunately, this hasn't made any difference and the same error message still exits.

Here's the updated code:
response = self.class.post("/issues.xml", :body => {:issue => {
:subject => issue_tracker_title,
:description => issue_tracker_body,
:project_id => issue_tracker_project_id,
:tracker_id => 1,
:status_id => 1,
:priority_id => 4}
})

    (1-2/2)