Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateWorkItemForIssue fails with Bad Request error #120

Open
labsilva opened this issue Sep 2, 2022 · 0 comments
Open

CreateWorkItemForIssue fails with Bad Request error #120

labsilva opened this issue Sep 2, 2022 · 0 comments

Comments

@labsilva
Copy link

labsilva commented Sep 2, 2022

Expected behavior

Using the YouTrackSharp Nuget package (version 2021.3.6) to create a work item for an existing issue should correctly create the work item in the issue.

YouTrack server on-prem, Build 2022.2.53793, Fri, Aug 19, 2022.

Actual behavior

The request fails with the following error:

YouTrackSharp.Generated.YouTrackErrorException : The HTTP status code of the response was not expected (400).

Status: 400
Response: 
{"error":"Bad Request","error_description":"YouTrack is unable to locate an Me-type entity unless its ID is also provided","error_developer_message":"YouTrack is unable to locate an Me-type entity unless its ID is also provided"}

Could not find any reference to this error on my Google searches.

I've triple-checked that the data supplied on the method call is valid and everything "exists" on our YouTrack instance.
The bearer token used is valid and has the necessary service scopes for the operation.

Steps to reproduce the behavior

The following Xunit test triggers the error, you'll just have to supply valid values to the configuration options:

public class YouTrackWorkItemTests
    {
        private readonly BearerTokenConnection connection;

        public YouTrackWorkItemTests()
        {
            connection = new BearerTokenConnection(
                "<youtrack instance url>",
                "<bearer token>"
            );
        }


        [Fact]
        public async Task ShouldCreateTimeTrackingWorkItem()
        {
            // Arrange
            var issueService = connection.CreateIssuesService();
            var timeTrackingService = connection.CreateTimeTrackingService();

            var issueId = "<an existing issue id from a project with time tracking enabled>";
            var description = "<any description will do>";
            var duration = TimeSpan.FromHours(1);
            var author = "<a valid user name with access to the project>";

            // Act
            var issue = await issueService.GetIssue(issueId).ConfigureAwait(false);
            var workItemTypes = await timeTrackingService.GetWorkTypesForProject(issue.GetField("projectShortName").AsString()).ConfigureAwait(false);

            var workItem = new WorkItem(
                    DateTime.UtcNow,
                    duration,
                    description,
                    workItemTypes.First(),
                    new Author { Login = author });
            var workItemId = await timeTrackingService.CreateWorkItemForIssue(issue.Id, workItem);

            // Assert
            workItemId
                .Should()
                .NotBeNullOrEmpty()
                .And
                .NotBeNullOrWhiteSpace();

        }
    }

Any help is appreciated! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant