Project

General

Profile

Create Plugin With API Create Issues

Added by Vladimir Bocharov almost 3 years ago

Good afternoon.
There is a need to write a plugin that will expand the redmine api for my tasks, but for this you need to write your own post request to create issues. How can I implement the creation of issues through my api in the plugin?


Replies (1)

RE: Create Plugin With API Create Issues - Added by Mayama Takeshi almost 3 years ago

I am not sure if I understand what you mean by "expand the redmine api" but if you want to add new endpoints/methods to the Redmine API you can do it by specifying the new endpoints/methods in your plugin's config/routes.rb file.

For example, in my plugin I needed to call the Redmine API to delete a note (journal).
But the Redmine REST API doesn't support the method DELETE journals endpoint.
(obs: it is possible to delete a journal by using method PUT and setting the notes to an empty string. Ex: 'PUT MY_REDMINE_SERVER/redmine/journals/295683?journal[notes]='. However, for my plugin I decided having a specific method would be better)

So I added the method DELETE for it and set it to call method destroy in the journals controller this way:

delete '/journals/:id', to: 'journals#destroy'

Ref: https://github.com/MayamaTakeshi/redmine_rt/blob/master/config/routes.rb

Then I patched the journals controller by adding the method destroy:

      def destroy
        @journal = Journal.find(params[:id])
        unless @journal.editable_by?(User.current)
          raise ::Unauthorized
        end
        @journal.destroy
        respond_to do |format|
           format.api { render :nothing => true, :status => 204 }
        end
      end

Ref: https://github.com/MayamaTakeshi/redmine_rt/blob/master/lib/redmine_rt/journals_controller_patch.rb

Obs: I actually don't know if the way I coded this was a good approach, but it solved my problem at that time.

    (1-1/1)