Home > Software design >  Curl - error body is missing when trying to comment on gitlab merge request
Curl - error body is missing when trying to comment on gitlab merge request

Time:10-13

I'm trying to post a comment on the merge request but I get the error {"error":"body is missing"}. Any idea how I can resolve this?

curl --request POST --header "Private-Token: askljdhakjdlsa" http://10.10.10.10/api/v4/projects/9/merge_requests/67/notes --data '{ "body": "Comment test" }'

CodePudding user response:

I think you missed Restful API Styleguide for JSON. Styleguide says you need to pass another header Content-Type: application/json like

curl --request POST --header "Private-Token: askljdhakjdlsa" --header "Content-Type: application/json" --data '{ "body": "Comment test" }' http://10.10.10.10/api/v4/projects/9/merge_requests/67/notes 

If you do not want to use JSON data then(by default Content-Type header will be application/x-www-form-urlencoded)

curl --request POST --header "Private-Token: askljdhakjdlsa" --data "body=Comment test" http://10.10.10.10/api/v4/projects/9/merge_requests/67/notes 

CodePudding user response:

Considering the Create new merge request note, an alternative to application/x-www-form-urlencoded (mentioned in Arif Khan's answer) would be:

curl --request POST --header "Private-Token: askljdhakjdlsa" \
"http://10.10.10.10/api/v4/projects/9/merge_requests/67/notes?body=Comment test"
  • Related