Search code examples
c#redmineredmine-api

Setting new issue's author through Redmine .NET API


I am trying to manage Redmine from ASP.NET MVC application with using Redmine .NET API.

The MVC application needs to allow users to create and edit Issue from its UI. (The MVC application has same users as Redmine does.) The following code added a new issue but the author is always set as the owner of API key.

using Redmine.Net.Api;
using Redmine.Net.Api.Types;

RedmineManager manager = new RedmineManager(host, apiKey);

Issue newIssue = new Issue();
// Set issue details
newIssue.Author = new IdentifiableName();
var user = manager.GetUsers(UserStatus.STATUS_ACTIVE, loginUserName).FirstOrDefault();
newIssue.Author.Id = user.Id;

manager.CreateObject<Issue>(newIssue);

I want to set the login user to the issue author.
Does anyone know how to do this?
Thanks.


Solution

  • Redmine doesn't allow to set the author field of an issue. It is always set to the current user on issue creation.

    The easiest solution would be to use the credentials of the author to create the issue with the API (i.e. either their username/password or their API key).

    If that is not possible, you can use Redmine's User impersonation feature. This allows you to use the API token of an Administrator for all of your requests. By setting the X-Redmine-Switch-User header to the login of another user in your POST request, you can create the issue as another user.

    While I have no experience with your .NET client library, it seems they support this feature as it is mentioned in their README. It seems you can set the login using the ImpersonateUser property of the RedmineManager class.