JetBrains / JetBrains/YouTrackSharp

CreateWorkItemForIssue fails with Bad Request error

Open
#120 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
143
Forks
105
PR merge metrics
No merged PRs in 30d

Description

## 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:

```csharp
public class YouTrackWorkItemTests
{
private readonly BearerTokenConnection connection;

public YouTrackWorkItemTests()
{
connection = new BearerTokenConnection(
"",
""
);
}

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

var issueId = "";
var description = "";
var duration = TimeSpan.FromHours(1);
var author = "";

// 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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.