YouTrack Standalone 2020.3 Help

Create an Issue

Use Case:

Use the REST API to create a new issue with the default values for issue custom fields.

Summary

To create an issue, you need to know an entity id of the project to which the issue should be reported. It means that you need to get a list of available projects, find an id of the target project, and then create a new issue in this project.

Step-by-Step

  1. Get a list of available projects.

    curl -X GET \ 'https://example.myjetbrains.com/youtrack/api/admin/projects?fields=id,name,shortName' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer perm:amFuZS5kb2U=.UkVTVCBBUEk=.wcKuAok8cHmAtzjA6xlc4BrB4hleaX' \ -H 'Content-Type: application/json'

    For such request, you get response from the server with the following body:

    [ { "shortName": "GRP", "name": "GRA Project", "id": "0-7", "$type": "Project" }, { "shortName": "RAP", "name": "Rest Api Project", "id": "0-2", "$type": "Project" }, { "shortName": "RP", "name": "Rest Project", "id": "0-6", "$type": "Project" }, { "shortName": "SP", "name": "Sample Project", "id": "0-0", "$type": "Project" }, { "shortName": "SNBX", "name": "Sandbox", "id": "0-3", "$type": "Project" } ]

    You can also filter the list of projects by shortName or a name of the required project.

    Sample request with the filter by a project's name:

    curl -X GET \ 'https://example.myjetbrains.com/youtrack/api/admin/projects?fields=id,name,shortName&query=Sample+Project' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer perm:amFuZS5kb2U=.UkVTVCBBUEk=.wcKuAok8cHmAtzjA6xlc4BrB4hleaX' \ -H 'Content-Type: application/json'

    Sample request with the filter by a project's shortName:

    curl -X GET \ 'https://example.myjetbrains.com/youtrack/api/admin/projects?fields=id,name,shortName&query=sp' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer perm:amFuZS5kb2U=.UkVTVCBBUEk=.wcKuAok8cHmAtzjA6xlc4BrB4hleaX' \ -H 'Content-Type: application/json'

    To the sample request with the query parameter, the response body contains data only for the matching project:

    [ { "shortName": "SP", "name": "Sample Project", "id": "0-0", "$type": "Project" } ]
  2. In the response from the server, locate the id of the target project. In our sample, the required project id is 0-0.

    "id" : "0-0"
  3. Send a POST request to create a new issue in the target project:

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

    In the body of the response, the server returns the entity id of the created issue:

    { "id": "2-38", "$type": "Issue" }

That's it: We created a new issue. All custom fields of the issue are set to their default values.

Last modified: 28 October 2020