I am trying to post a comment with the content of JSON file(example: cat somefile.json) as a PR comment via rest API 2.0.
Any help can be appreciated
Thanks,
Srinivas Aluka
Hi @Srinivas Aluka,
You will need to pass the content of the file in the data of the request and any new lines should be escaped.
For example, if the content of the JSON file is the following:
{
"a": "a",
"b": "b"
}
You can post it as a PR comment via API with a call like the following:
curl -u BitbucketUsername:AppPassword \
-X POST "https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/pullrequests/pr-id/comments" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"content":{"raw": "{ \n\"a\": \"a\", \n \"b\": \"b\" \n}"}}'
where
BitbucketUsername is the username of a Bitbucket account with access to the repo
AppPassword is an app password for the account
workspace-id is the workspace id of the workspace that owns the repo
pr-id is the id of the PR where you want to post the comment
Please feel free to let me know if that works for you and if you have any questions
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.