jetbrains / youtracksharp Goto Github PK
View Code? Open in Web Editor NEW.NET Standard 2.0 Library to access YouTrack API.
Home Page: https://www.jetbrains.com/youtrack
License: Apache License 2.0
.NET Standard 2.0 Library to access YouTrack API.
Home Page: https://www.jetbrains.com/youtrack
License: Apache License 2.0
We are using UserManagementService .CreateUser (https://github.com/JetBrains/YouTrackSharp/blob/192/src/YouTrackSharp/Management/UserManagementService.cs#L86) for users creating in our library. In case of sending full name like "FirstName LastName" it should create user with the full name equals "FirstName LastName"
Actually it works wrong and saves it as string "FirstName+LastName". Probably the reason is WebUtilities.UrlEncode on fullName string (this helper replaces ' ' character with the '+' character).
Also, I think this problem is actual for all POST/PUT requests.
You can just call UserManagementService .CreateUser with FullName parameter that contains spaces.
getting a list of issues should not get a 404.
getting a list of issues results in a 404, after our youtrack instance was updated to 2019.1
Code which broke after Youtrack was updated
https://example.myjetbrains.com/youtrack/rest/issue?filter=test
Steps to solve the problem:
So it seems there were multiple breaking changes in the new API Version, which this library does not support at this point.
GetUsers called without paramters should return all users, not only the first 10 records.
The description says: "Get a list of all available registered users."
only 10 users are returned
call GetUsers() without parameters, more than 10 registered users in Youtrack
Newtonsoft.Json.JsonSerializationException : Error converting value 1 to type YouTrackSharp.Management.WorkDay'. Path 'workWeek[0]', line 1, position 43.
Seems API changed to use just integers.
Yesterday API version 2020.1.0 worked (the project uses .Net 4.8, so we use this version).
Today I went wrong with an error:
The code:
connection = new BearerTokenConnection ("https: // [some name] .myjetbrains.com / youtrack", "[token]");
connection.CreateIssuesService (). GetIssues (...);
Error:
System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
How to solve this in a project for .Net 4.8?
PS
We tried a project on .net 5.0 and version YoutTrackSharp 2021.3.1, we get an error:
Unhandled exception. YouTrackSharp.UnauthorizedConnectionException: Could not authenticate. Server did not return expected authentication response. Check the Response property for more details.
at YouTrackSharp.BearerTokenConnection.GetAuthenticatedApiClient ()
at YouTrackSharp.Issues.IssuesService.GetIssues (String filter, Nullable1 skip, Nullable
1 take, Boolean wikifyDescription, Boolean wikifyContents)
See the following URL's for documentation:
Perhaps good to split the work for this in separate issues and PR's.
Can I ask about the plans for support of the new REST API of YouTrack? Currently we are using the old /rest/...
interface, but, if I understand it correctly, JetBrains wants to move to the new /api/...
endpoint. This is obviously a substantial change, is there a plan to do it? Or do you have an insight into the state of development of different REST APIs in YouTrack?
Thanks for any information.
I have assigned a user to an issue in YouTrack. When I request that's projects issues via YouTrackSharp, the Issue items that come back do not have their Assignee property populated.
I have a program that calls GetWorkTypesForProject on each project in a YouTrack instance. Recently, someone added a project in which time tracking was disabled. YouTrack returns an HTTP 400 response with an error message when I call GetWorkTypesForProject on this project. I'd like to ignore this error, but on the C# side, I just get a HttpRequestException, which is hard to distinguish from other transient/critical HTTP errors like 503.
Calling GetWorkTypesForProject() when time tracking is disabled throws an informative exception (YouTrackErrorException?)
Calling GetWorkTypesForProject() when time tracking is disabled throws an HttpRequestException.
Call TimeTrackingService.GetWorkTypesForProject() on a project in which time tracking is disabled.
Tying to get issues from YT:
var connection = new BearerTokenConnection("https://[some].myjetbrains.com/youtrack", "[token]");
onnection.CreateIssuesService().GetIssues("[filter]", take: 1000);
Got error:
Unhandled exception. YouTrackSharp.UnauthorizedConnectionException: Could not authenticate. Server did not return expected authentication response. Check the Response property for more details.
at YouTrackSharp.BearerTokenConnection.GetAuthenticatedApiClient()
at YouTrackSharp.Issues.IssuesService.GetIssues(String filter, Nullable`1 skip, Nullable`1 take, Boolean wikifyDescription, Boolean wikifyContents)
Hello,
I'm using version 2019.2.0 on a version on a 2019.2 server and I want to create a new issue.
This is my code:
BearerTokenConnection connection = new BearerTokenConnection(
"https://youtrack.example.com/",
"perm:Ym...Dfg");
IIssuesService issuesService = connection.CreateIssuesService();
YouTrackSharp.Issues.Issue ytIssue = new YouTrackSharp.Issues.Issue
{
Summary = summary,
Description = descriptionBuilder.ToString(),
};
string ytIssueID = await issuesService.CreateIssue("SIMNC", ytIssue);
During the call to CreateIssue
my program just ends without any error message and the issue is not created.
What am I doing wrong?
'UsernamePasswordConnection' is referenced in the readme -- but it doesn't appear to exist.
It's supported in addition to BearerTokenConnection
Try to use UsernamePasswordConnection.
See https://www.jetbrains.com/help/youtrack/standalone/Users.html
GET user https://www.jetbrains.com/help/youtrack/standalone/GET-User.html
GET users https://www.jetbrains.com/help/youtrack/standalone/GET-Users.html
PUT user https://www.jetbrains.com/help/youtrack/standalone/PUT-User.html
POST user https://www.jetbrains.com/help/youtrack/standalone/POST-User.html
DELETE user https://www.jetbrains.com/help/youtrack/standalone/DELETE-User.html
GET user groups https://www.jetbrains.com/help/youtrack/standalone/GET-User-Groups.html
POST user group https://www.jetbrains.com/help/youtrack/standalone/POST-User-Group.html
DELETE user group https://www.jetbrains.com/help/youtrack/standalone/DELETE-User-Group.html
At the moment it is not possible to depend on this library if you want to strong name your own libraries because YouTrackSharp isn't strong named so it would be good to have a strong named version.
I was trying to add comment using code into particular youtrackitem.
but it is giving 404 error. not sure what is correct api url
var youtrackConnection = new YouTrackSharp.BearerTokenConnection("https://xxxx.myjetbrains.com/youtrack/api/", "token");
var issuesService = youtrackConnection.CreateIssuesService();
Task backgroundJobAwaiter = Task.Run(async () =>
{
try
{
await issuesService.ApplyCommand("Project-1090", command: "Comment", comment: "Test");
}
catch (Exception ex)
{
Console.Write(ex);
}
});
backgroundJobAwaiter.Wait();
See the following URL for documentation:
Should be relatively easy to implement and write a test for.
Hello,
It seems that this library uses legacy YouTrack API which is being discontinued:
https://blog.jetbrains.com/youtrack/2021/02/discontinuing-the-legacy-rest-api-action-required/
Are there plans to update this library to use a new API?
Thanks
The agile board API has been removed in YouTrack 2018.2. Users on previous versions will still be able to use it, but the API will always return 404 errors on YouTrack 2018.2 and above.
When new API is available, update library to make use of it.
This might be more of a question than an issue, but is there anyway to set the HttpClient timeout on the BearerTokenConnection object? I've been trying to play around with the object, and using the GetAuthenticatedHttpClient() for setting this property, but I am not having any luck.
Any help would be appreciated.
If this is not supported, I think this would be an extremely convenient feature to add.
hi,
i'v tried several times to create a new issue that contains custom fields but it just won't work.
i even tried to get an issue from the YouTrack and use it's object to create a similar one:
var issueManagement = new IssueManagement(connectionObject);
dynamic issueObject = issueManagement.GetIssue("SPM-191");
issueManagement.CreateIssue(issueObject);
but it also won't add any data to the the custom fields.
The email address should be valid and as entered with the @ sign
The email address has the @ sign replaced by %40
Create new user with an email address and it will "Encode" it.
Same as issue #90 I believe we need to leave the string as is, no encoding since it will be be re-encoded in the body somehow.
ringId from response is mapped to property Id of User
no property Id in class user
Support setting properties on HttpClientHandler
in both BearerTokenConnection
and UsernamePasswordConnection
. Scenarios could be configuring SSL etc.
An example could be setting the HttpClientHandler
's ServerCertificateCustomValidationCallback
:
var connection = new BearerTokenConnection(
"https://ytsharp.myjetbrains.com/youtrack/",
"perm:abcdefghijklmn",
handler =>
{
handler.ServerCertificateCustomValidationCallback =
(sender, certificate, chain, sslPolicyErrors) => true;
});
(Note the above is not a secure example as it disables SSL certificate checks!)
EasyHttp doesn't provide working support for PUT requests, since it fails to set the needed ContentLength. Using System.Net.HttpWebRequest as a workaround works.
As received by email from YouTrack, the REST API will be depreciated as of july 2021. "In the upcoming 2021.3 release, support for this version of the API will be discontinued. This means that its endpoints will be deactivated to ignore incoming requests."
https://www.jetbrains.com/help/youtrack/incloud/2021.2/monitor-rest-api-traffic.html
Will this library being updated?
Thanks.
We are writing a small program with YouTrackSharp which migrates time tracking entries from YouTrack into an external system. I noticed the JSON returned from /rest/issue/issue id/timetracking/workitem has created and updated fields that reflect when each entry was added or modified. These would be pretty useful for us to avoid reimporting work items we have already seen and to identify updates to old work items, but they are not reflected in the .NET TimeTracking.WorkItem class. Could they be added? Any other missing created or updated fields would also be handy, though I understand that for Issues, they can be retrieved with the GetField() method.
When you load Issues and you receive an issue without description (and yes that could happen)
This method will fail when Description is not existent (the same will be for all properties)
public string Description {
get
{
var field = GetField("Description");
return field?.Value.ToString();
}
set => SetField("Description", value);
}
public Field GetField(string fieldName)
{
_fields.TryGetValue(fieldName, out var field); //when this returns false it should not be ignored!!!!
return field;
}
is to make unit tests base on YouTrackSharp classes like IssuesService and so I don't want to call server too often. Instead I would rather use interface of the class to mock it in any mocking package so no changes are applied during tests on company's YouTrack.
that there are no interfaces what is pretty dissapointing and there are few ways around to solve this but they are not prefered as they use tricks instead of clear logic.
that we identified (yet to test) are:
that I took was creating those interfaces and commiting to develop branch.
Any help or advise would be apprieciated,
Krzysztof Nowicki
When using IsMarkDown = false it should create a case without the Markdown option ( YouTrack Wiki ). The Querystring sent to YT should show markdown=false.
Nothing is appended to the QueryString when using IsMarkDown = false. ( only appended when IsMarkDown = true )
Create an issue and use IsMarkDown = false, the querystring is not appeneded and the Case is created with the default value to MarkDown.
Potential fix on or around: "if (issue.IsMarkdown)" on line 97 of IssueService.cs
The current implementation parses JSON from server while ignoring the case of field names. This behaviour is AFAIK implemented in file Issues/Issue.cs
on line 22:
private readonly IDictionary<string, Field> _fields = new Dictionary<string, Field>(StringComparer.OrdinalIgnoreCase);
I am not sure why we have this behaviour -- JSON is case-sensitive and YouTrack can have two different fields that only differ in case (in my case it was fields Sprint
and sprint
). I was able to fix it by simply changing the comparer to StringComparer.Ordinal
. I would be very happy to submit this simple change as pull request, or am I missing something?
Thank you.
See:
There is still an issue in POST/PUT requests. It is linked to the #89.
Currentlu it replaces spaces in string with the space escape code '%20'. I guess the reason is escaping strings for FromData requests. In case of POST/PUT data could be sent as is, because of sending in request body, but not in the URL
Thr following code:
BearerTokenConnection ytConnection = new BearerTokenConnection(
"https://youtrack.XXX.com/",
"perm:...");
Issue issue = new Issue
{
Description = description.ToString(),
Summary = "Summary",
};
IIssuesService issuesService = ytConnection.CreateIssuesService();
string id = await issuesService.CreateIssue("XXX", issue);
Results in a System.Net.Http.HttpRequestException with the message
"Response status code does not indicate success: 414 (Request-URI Too Long)."
What am I doing wrong here?
Using YouTrackSharp 2019.1.0.0
Allow uploader to specify content type in the MultipartFormDataContent object in the AttachFileToIssue metehod
We are trying to show user-facing descriptions of the issues returned by a specific query, however some issues contain wiki markup, which obscures the content of the description. It would be great if we could use wikifyDescription=true to fetch the description as HTML, so we could use an HTML parser to get a user-facing description of each issue.
Hello,
We have a Release Notes custom text field in YouTrack. We pull it via API to display in the external release notes generator app.
The issue we came across is that there's no way to get markdown text converted to HTML using YouTrackSharp client.
YouTrack API itself returns markdown text transformed to HTML when requested. For a example a request like this:
http://youtrackurl/api/issues/AB-2420?fields=$type,id,summary,customFields($type,id,projectCustomField($type,id,field($type,id,name)),value($type,avatarUrl,buildLink,color(id),fullName,id,isResolved,localizedName,login,minutes,name,presentation,text,markdownText))
returns markdownText
property:
{
"projectCustomField": {
"field": {
"name": "Release Notes",
"id": "30-39",
"$type": "CustomField"
},
"id": "201-10",
"$type": "TextProjectCustomField"
},
"value": {
"id": "text",
"text": "n/a - internal\n**testing markdown**\nList:\n- item 1\n- item 2",
"markdownText": "<div class=\"wiki text common-markdown\"><p>n/a - internal<br/><strong>testing markdown</strong><br/>List:</p>\n<ul class=\"wiki-list0\">\n<li>item 1</li>\n<li>item 2</li>\n</ul>\n</div>",
"$type": "TextFieldValue"
},
"id": "201-10",
"$type": "TextIssueCustomField"
}
I tried to use a few other markdown libraries to manually convert markdown to HTML, but they produce a different result than YouTrack.
Please let me know if exposing markdownText property is in the roadmap.
Alex
In https://confluence.jetbrains.com/display/YTD4/Timestamps+in+REST+API
For any timestamp in REST API, YouTrack uses Java timestamp format: The number of milliseconds
But in
https://github.com/JetBrains/YouTrackSharp/blob/master/src/YouTrackSharp/Json/UnixDateTimeOffsetConverter.cs
in method WriteJson I see ".ToUnixTimeSeconds()"
and because of this when I do
timeTrackingService.CreateWorkItemForIssue("MA-2633", new WorkItem(new DateTime(2017, 1, 1), TimeSpan.FromHours(0.5), ""))
then I have a result with date 18 Jan 1970 in YouTrack
I want to use YoutrackSharp in my F# application. When I install the YoutrackSharp Nuget package and run my application, I get the following runtime error:
System.IO.FileLoadException:
'The File or Assembly "System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" or one of its dependencies could not be found.
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
I use .F# 4.1, NET Framework 4.7 and Visual Studio 2017 (15.3.5). The same exception occurs with other .NET frameworks (I tested 4.6.1)
Steps to reproduce:
When I do the same in C#, everything works. Is this some kind of version conflict with a dependency from FSharp.Core? How could I debug this?
Tags associated with issues are not being included in the Issue object returned by GetIssuesBySearch.
When I try to create WorkItem with Author field I get an exception
Response status code does not indicate success: 403 (Forbidden).
I think it is because method CreateWorkItemForIssue in YouTrackSharp.TimeTracking.TimeTrackingService call
rest/issue/{issueId}/timetracking/workitem
And in documentation api youtrack I see for this call that is has no author
https://www.jetbrains.com/help/youtrack/standalone/Create-New-Work-Item.html
I think it must be a call with author, described in
https://www.jetbrains.com/help/youtrack/standalone/Import-Workitems.html
but I can't find it in YouTrackSharp
See the following URL's for documentation:
Perhaps good to split the work for this in separate issues and PR's.
Test
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.