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

doesn't support the new API on 2019.1 #83

Closed
bschaeublin opened this issue Apr 3, 2019 · 12 comments
Closed

doesn't support the new API on 2019.1 #83

bschaeublin opened this issue Apr 3, 2019 · 12 comments

Comments

@bschaeublin
Copy link

bschaeublin commented Apr 3, 2019

Expected behavior

getting a list of issues should not get a 404.

Actual behavior

getting a list of issues results in a 404, after our youtrack instance was updated to 2019.1

Steps to reproduce the behavior

Code which broke after Youtrack was updated
https://example.myjetbrains.com/youtrack/rest/issue?filter=test

Steps to solve the problem:

  • Replace "rest" with "api"
  • Replace "issue" with "issues"

So it seems there were multiple breaking changes in the new API Version, which this library does not support at this point.

@bschaeublin bschaeublin changed the title doesn't work with new API on cloud hosted scenario doesn't work with new API on 2019.1 Apr 3, 2019
@bschaeublin bschaeublin changed the title doesn't work with new API on 2019.1 doesn't support the new API on 2019.1 Apr 3, 2019
@maartenba
Copy link
Collaborator

An API overhaul has been done in 2019.1. We are looking at working on a new version of YouTrackSharp, for now 2019.1 is unfortunately not supported.

@bschaeublin
Copy link
Author

Thank you for your reply. I guess this will take some time?

I'm using 3 Endpoints so far, so I'll then create a light-weight client on my own until an official new version will be released.

@maartenba
Copy link
Collaborator

Yes, will take a bit of time, sorry for the hiccup :)

@maartenba
Copy link
Collaborator

@bschaeublin Would you mind trying with the 2019.1 prerelease version from NuGet?
https://www.nuget.org/packages/YouTrackSharp/2019.1.0-alpha-00003

Install-Package YouTrackSharp -Version 2019.1.0-alpha-00003

@bschaeublin
Copy link
Author

@maartenba Thank you! At least GetIssueCount does work now.
But i still get some problems when I call GetIssues with a specific query, which worked before.
I think i can delimit it to the date range search. Maybe it is a data problem too, as the Internal Server Error occurs on page 3, when paging with 100.

Please see attached screenshot:
image

@maartenba
Copy link
Collaborator

That could be a data problem indeed. Do you see the same issue with other queries or only this one?

@bschaeublin
Copy link
Author

I've managed to successfully run a query on a small test project. Is there a way to provide some more details on the 500 Issue? Can you reproduce the issue with any querys on bigger projects and paging through?

We're using it as SAAS, but I don't think i've enough privileges to get some logs.

@maartenba
Copy link
Collaborator

Paging seems to work, just added a unit test testing this explicitly: 5116ca8

Could you perhaps reach out to YouTrack support to troubleshoot that 500 error?

@bschaeublin
Copy link
Author

bschaeublin commented Apr 8, 2019

I had some time (holidays!) and managed to find out some stuff.

I edited your unit test to connect to our youtrack instance and changed the test a bit:

            [Fact]
            public async Task Valid_Connection_Page_Issues()
            {
                // Arrange
                var url = "an url";
                var token = "a token";

                var con = new BearerTokenConnection(url, token);

                var service = con.CreateIssuesService();

                // Act
                var totalResultsCount = 0;

                var skip = 0;
                while (skip < 1000)
                {
                    var result = await service.GetIssues("resolved date: 2018-02 .. 2019-01", skip, take: 100);
                    if (result?.Count > 0)
                    {
                        totalResultsCount += result.Count;
                    }
                    else
                    {
                        break;
                    }

                    skip += 100;
                }

                // Assert
                Assert.True(totalResultsCount > 100);

            }

The test failed, so i edited the IssueService.Querying.cs GetIssues Method to take the new api andpoint /api/issues instead of /rest/issue and the the test succeeded.

I compared the api results and discovered that the new api endpoint does not return all fields per default. So maybe it has to do with one field.

I reverted my changes and modified the GetIssue Method to return just the fields that i want.
Field by field I found out it is the field "links" which shows the relation of the ticket. Maybe it is a ticket with circular references that causes the internal server error?

I was wondering if the new api could handle it, and added the field in the request (see following sample) and rerun the unit test.
The test succeeded.

 public async Task<ICollection<Issue>> GetIssuesv20191(string filter = null, int? skip = null, int? take = null, bool wikifyDescription = false)
        {
            var queryString = new List<string>(5);
            if (!string.IsNullOrEmpty(filter))
            {
                queryString.Add($"filter={WebUtility.UrlEncode(filter)}");
            }
            if (skip.HasValue)
            {
                queryString.Add($"after={skip}");
            }
            if (take.HasValue)
            {
                queryString.Add($"max={take}");
            }

            queryString.Add("fields=id,links");
            queryString.Add($"wikifyDescription={wikifyDescription}");

            var query = string.Join("&", queryString);

            var client = await _connection.GetAuthenticatedHttpClient();
            var response = await client.GetAsync($"api/issues?{query}");

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return null;
            }

            response.EnsureSuccessStatusCode();

            var resultStr = await response.Content.ReadAsStringAsync();
            var issues = JsonConvert.DeserializeObject<Issue[]>(resultStr);
            return issues;
        }

The new api is not documented the way the old one was - so I have no idea how we get the new API endpoint to return all fields per default. If this would be possible we would have to change the endpoints from "/rest/issue" to "/api/issues" and change all the query parameters accordingly.

What do you think?

And some thoughts at the end:
A pitty, that existing api implementations are all broken now (for example my custom azure logic app connector), an api versioning would have been the preffered way to refactor an api.

@maartenba
Copy link
Collaborator

maartenba commented Apr 8, 2019

Regarding the error 500, can you email me the query, project name and instance name?

@bschaeublin
Copy link
Author

thank you for taking a look - i've sent it.

@maartenba
Copy link
Collaborator

After e-mail discussion this got flagged as a bug in YouTrack itself. Will proceed with 2019. release of this library.

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

2 participants