2

I found an issue and get it's details with:

GET https://localhost/api/v4/projects/2779/issues/2

I can add a new_comment to the issue by:

POST https://localhost/api/v4/projects/2779/issues/2/notes?body=new_comment

how to close this issue at once with adding comment?

I've tried only to close without a comment by:

PUT https://localhost/api/v4/projects/2779/issues/2?state_event=close" and it works but I have to use to request first POST to comment and then PUT to close it.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
simoN
  • 65
  • 2
  • 12

2 Answers2

0

with adding comment

The Issue "Closing issues automatically" section mentions:

If a commit message or merge request description contains text matching a defined pattern, all issues referenced in the matched text are closed.
This happens when the commit is pushed to a project’s default branch, or when a commit or merge request is merged into it.

For example, if Closes #4, #6, Related to #5 is included in a Merge Request description, issues #4 and #6 are closed automatically when the MR is merged, but not #5.

So "comments" are related to commits or MR (Merge Requests), not comment on the issue itself.

The Edit issue API proposes the following call to close an issue:

curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/4/issues/85?state_event=close"

That should be pretty similar to what you have tried, except you need the PAT (Personal Access Token) with the right scope (api).

As the OP found out, the PUT is effective only after posting a comment on said issue: Create new issue note

POST /projects/:id/issues/:issue_iid/notes
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ok but on the other hand I am creating an issue with a title using: POST ```https://localhost/api/v4/projects/2779/issues?title=TestIssue``` and i want to add a description to this issue in the same POST. If it is not possible, how can I find ID or IID of this new issue. I can't find it in POST response ps. I know about private-token header. – simoN Jan 04 '21 at 12:21
  • @simoNPL In https://docs.gitlab.com/ee/api/issues.html#new-issue, the web-url field seems to be the newly created issue URL. – VonC Jan 04 '21 at 12:56
0

You can add \n/close to the end of your comment to close the issue with a single API call while adding a comment.

POST https://localhost/api/v4/projects/2779/issues/2/notes?body=new_comment\n/close

This works because /close is one of the quick actions.

Shashank V
  • 10,007
  • 2
  • 25
  • 41
  • ...and how to add assignee? I've tried: `https://localhost/api/v4/projects/2779/issues/20?assignee_id=240` and it's not working. I didn't get any error either – simoN Feb 02 '21 at 08:27