Greetings.
I am trying to add a comment to my PR. I tried both the method from the documntation and from Google. Both return required key not provided and do not create a comment. As you can see, the error message doesn't tell me which required key is not provided.
The json from documentation is a long one
{
"type": "pullrequest_comment",
"id": 2154,
"created_on": "2023-06-28T12:44:36.726033+00:00",
"updated_on": "2023-06-28T12:44:36.726033+00:00",
"content": {
"raw": "test text",
"markup": "plaintext",
"html": ""
},
"user": {
"type": "user"
},
"deleted": False,
"inline": {
"from": 57,
"to": 122,
"path": ""
},
"pullrequest": {
"type": "pullrequest"
},
"resolution": {
"type": "<string>",
"user": {
"type": "user"
},
"created_on": "2023-06-28T12:44:36.726033+00:00"
}
{
"content": {
"raw": "first!"
}
}
Hello @anton.merzliakov and welcome to the Community!
You should be able to create a new comment in a Pull Request just providing the raw content, as in your example. However, it's important to include the header Content-Type: application/json in the request, otherwise it might fail with a bad request error as you received.
You can use the following example as a base to make your request :
curl -X POST -u USERNAME:APP_PASSWORD 'https://api.bitbucket.org/2.0/repositories/<workspace>/<Repository>/pullrequests/<Pull Request ID>/comments' --header 'Content-Type: application/json' --data '{"content":{"raw":"testing one comment"}}'
With this command, you should be able to successfully create a comment in the Pull Request ID provided in the URL.
Hope that helps! Let us know in case you run into any issues.
Thank you, @anton.merzliakov !
Patrik S
It actually worker! Really thank you a lot, Patrik!
(It would also be nice if the documentation had this example.)
Maybe you have any idea what is happening with Atlassian's Python library too? https://community.atlassian.com/t5/Bitbucket-questions/Create-a-PR-comment-using-Python/qaq-p/2407830#M95382
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is the risk you take when using third party libraries to 'short cut' your development work. It may or may not be maintained it to the exact extent needed.
If in doubt, always use the native functionality in your development language to interact with the REST APIs, and always use a test tool like Postman to validate your query before assuming your code is faulty.
PS. Atlassian, the company, doesn't own or maintain that python library. It's a public library that is maintained by volunteers. It's just called the 'Atlassian' library because it's used with Atlassian's products. If you have found a real bug with it, log it on its GitHub page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, I did try the official way first. It was nice that Patrik understood what was wrong with my request. The documentation can definitely be improved.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @muhammad mudassir ,
could you share the exact command you're using to make the request so we can help investigate why it's not showing?
Please make sure to hide any sensitive/personal information when sharing the command as this is a public forum.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Patrik S this issue is resolved but now I want to know if I can comment as a bot in PRs with my connect application, I am calling comment API and it simply comments on behalf of the user, I want to see my application name with [bot] tag there can you help me with this.
const jwtToken = atlassianJwt.encodeSymmetric(
{
iss: 'application-name',
iat: now.unix(),
exp: now.add(5, 'minutes').unix(),
qsh: atlassianJwt.createQueryStringHash(
atlassianJwt.fromMethodAndUrl(method, resource),
),
sub: data.clientKey,
},
installation.sharedSecret
);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @muhammad mudassir
Thank you for sharing the command.
For development-related inquiries, I recommend posting your question on our developer-focused community:
That community allows you to collaborate with other developers, and the Atlassian engineering team is also active in responding to questions.
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.