YouTrackSharp problem creating a new WorkItem

I am trying to create a new WorkItem and attach it to an existing issue using YouTrackSharp.

In my code I make a call like this:

            WorkItem wi = new WorkItem()
                Author = new Author() { Login = UserName, },
                Date = WorkItem.StartTime,
                Description = WorkItem.Description,
                Duration = TimeSpan.FromMinutes(minutes),
                WorkType = WorkTypes.FirstOrDefault(x => x.Name == WorkItem.WorkType),
                Created = DateTime.Now,
                Updated = DateTime.Now,

                string result = await TimeTrackingService.CreateWorkItemForIssue(WorkItem.IssueId, wi);
                MessageBox.Show($"Work item created: {result}");
            catch (Exception ex)
                MessageBox.Show($"Error creating work item: {ex.Message}");

When I call CreateWorkItemForIssue, I get back the result:

Error creating work item: The HTTP status code of the response was not expected (400).
YouTrack is unable to locate an Me-type entity unless its ID is also provided

It looks like the underlying code cannot cope with the Author type.  Internally YouTrackSharp is converting the Author to a Me type.  Based on the error message I am guessing that the Me object needs an ID, but  I cannot provide an entity ID to the Author type, so I don't know where to go from here.  How can I fix this?

Official comment


This is Julia from YouTrack Support.

It looks like there's indeed no way to create a work item under a different user with TimeTrackingService, but let me check with our developers on this to be sure.

In the meantime, as a workaround, I suggest you try creating an IssueWorkItem via the YouTrack API client like this:

var client = await connection.GetAuthenticatedApiClient();
IssueWorkItem iwi = new IssueWorkItem()
   Author = new User() { Id = "1-2" },
   Duration = new DurationValue() { Minutes = 120 },
   // Other properties
var res = await client.IssuesTimetrackingWorkitemsPostAsync("KT-12", false, "id", iwi);

Thanks for responding,, Julia.  I'll give your workaround a try, but I have some questions:

* If I have a connection instance and a user name, how do I find the UserID of a user?  YouTrackSharp.Management.User doesn't contain it.

* Is a WorkItemType.Id the same as a WorkItem.Id, or do those represent different information in YouTrack?

* Are the Date and Created fields in IssueWorkItem UNIX epoch seconds?  Or JSON timestamp (UNIX epoch milliseconds)?

Just to clarify, I don't need to create a WorkItem as a different user.  I want to create a work item as myself.  I have a BearerTokenConnection with my credentials, and I want to call CreateWorkItemForIssue.  That requires an Author, and I don't know how to make a valid one.  Calling “new Author()” internally constructs a  Me instance when the call is made, with no ID.

This looks like an API bug.  The public API uses Author and internally converts it to Me, but Author does not have an ID field and Me requires one.



Is there any further information on this?


Hi asthomas, sorry for the delayed response!

The developers let me know that the suggested workaround is the way to go at the moment. Also, please report the issue with creating a Me instance on GitHub:

As for your questions:

  • You can obtain the user Ring ID like this:
var userManagementService = connection.CreateUserManagementService();
var result = await userManagementService.GetUser("your_username");
var userRingId = result.RingId;

Just make sure to use the RingId property when constructing a user for the new issue work item.

  • WorkItemType.Id is the ID of the type of work (e.g. Development, Documentation, etc.). It's different from WorkItem.Id which is the ID of a certain work item (i.e. logged time entry);
  • The Date and Created fields are both in milliseconds.

Please sign in to leave a comment.