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 repoAppPassword is an app password for the accountworkspace-id is the workspace id of the workspace that owns the repopr-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
It looks like you're new here. Sign in or register to get started.