API passing the key as a param to new/create from a rails 3.1 app. How?
Added by Erik Ordway almost 13 years ago
Using REST api from a rails 3.1.13 to redmine 1.3 stable of last week. I am trying to use the API key "passed in as a "key" parameter". I can do this with RedmineClient::Issue.find but not with RedmineClient::Issue.new .
So if you want to use the API and set the user/key on request by request basis so that the issues are created by the user causing the request on the remote system you can set the :key in each request like
RedmineClient::Issue.find(offering.issue_id, :params => {:key => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"})
What I can not figure out how to do is doing this with
RedmineClient::Issue.new()
If you do
issue = RedmineClient::Issue.new( :subject => "The subject ", :description => "The Descriptiong", :project_id => 55, #Curricular Support :tracker_id => 34, #Program :category_id => 159 ,#Folder Request :params => {:key => xxxxxxxxxxxxxxxxx } )
It gets added to the Issue as a value and not set as a :params to be found by redmine in
# Returns the API key present in the request def api_key_from_request
The other items in the :params looked at by this message for RedmineClient::Issue.new are:
format --> json action --> create controller --> issues
With RedmineClient::Issue.find they are:
format --> json action --> show id --> 5623 controller --> issues key --> xxxxxxxxxxxxxxxxxxxxxxxxxxx
I have tried some other variations like putting all the issue values in a hash and then passing :params => {:key => xxxxxxxxxxxx } as a second value to Issue.new with no luck. The code was all working before I switched over from a site wide key and it does work for RedmineClient::Issue.find
Replies (1)
RE: Solution API passing the key as a param to new/create from a rails 3.1 app. How? - Added by Erik Ordway almost 13 years ago
If you are use something like Eric Davis's Redmine Client or in my case a copy of it in /lib you can add
class << self attr_accessor :key end def save prefix_options[:key] = self.class.key super end
see attached file
and then in your code do the following when you need to set the key
RedmineClient::Issue.key = xxxxxxxxxxxxxxxxxxxxx
This will effect both create and new. If you need to change the key often in the running application like I do there is the possibility the that there will be threading issues but I am not sure.