JetBrains / YouTrackSharp

.NET Standard 2.0 Library to access YouTrack API.
https://www.jetbrains.com/youtrack
Apache License 2.0
135 stars 105 forks source link

CreateIssue fails with 404 in AdminUsersMeDraftsAsync #129

Closed pantosh closed 1 year ago

pantosh commented 1 year ago

Expected behavior

Expected a new issue to be created for a specific project short name.

Actual behavior

404 error when AdminUsersMeDraftsAsync is called to draft the issue. There is no obvious easy workaround.

Steps to reproduce the behavior

Create a new issue using public async Task<string> CreateIssue(string projectId, Issue issue) in IssuesService will throw a YouTrackErrorException:

Status: 404
Response: 
{"error":"Not Found","error_description":"HTTP 404 Not Found"}'

The issue drafting was introduced in #111 in commit 3f62b794170895d7048c2691ed58a96844e456c8

This non-draft REST code will correctly create a new issue:

curl -X POST \
'https://youtrackurl.com/api/issues' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer perm:cAUTHTOKEN' \
-H 'Content-Type: application/json' \
-d '{
"project":{"id":"99-99"},
"summary":"REST API lets you create issues!",
"description":"Let'\''s create a new issue using YouTrack'\''s REST API."
}'

Notice that the project id, here 99-99 as example is a YouTrack project id, not the shortnames used in the YouTrackSharp library.

Suggestion: Fix issue and make it possible to also create a non-drafted issue using the api/issues REST call above.

pantosh commented 1 year ago

For what it is worth, this clumpsy workaround will create a new issue, but without drafting:

    private async Task<Issue> AlternativeCreateIssue(string projectId, Issue issue)
    {
        var client = await connection.GetAuthenticatedApiClient();

        var apiProjects = await client.AdminProjectsGetAsync("id,shortName", 0, -1);
        var project = apiProjects.Single(x => x.ShortName == projectId);

        var apiIssue = new YouTrackSharp.Generated.Issue
        {
            Project = project,
            UsesMarkdown = issue.IsMarkdown
        };

        if (!string.IsNullOrEmpty(issue.Summary))
        {
            apiIssue.Summary = issue.Summary;
        }
        if (!string.IsNullOrEmpty(issue.Description))
        {
            apiIssue.Description = issue.Description;
        }

        var newApiIssue = await client.IssuesPostAsync("", null, null, apiIssue);
        var issuesService = connection.CreateIssuesService();
        return await issuesService.GetIssue(newApiIssue.Id);
    }
rekolobov commented 1 year ago

@pantosh Hi, thank you for the report!

Could you please check though, which are your YouTrack AND YouTrackSharp versions?

The endpoint /admin/users/me/drafts was obsoleted in favor of /users/me/drafts in version 2022.3 (see commit 7f37ed8ec3da254b107af7f28bdcd83d459e28b7 for related changes in the library). This endpoint is not "public" (not present in openapi spec), hence the drastic change, however it unfortunately still remains the only most generic way to retrieve all unknown custom field prototypes.

rekolobov commented 1 year ago

If, for example, you are running YT Standalone 2021.* but you need some fixes not present in 2021.3 versions of the library, I would gladly backport them.

pantosh commented 1 year ago

I am using Jetbrains hosted YT. Build 2023.1.17582

pantosh commented 1 year ago

Checking up on my NuGet I found that it was out of date. CreateIssue is working with 2022.3.1. I will close the issue.

rekolobov commented 1 year ago

Thank you for checking! Don't hesitate to write us if any other issue arise