Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,576
Community Members
 
Community Events
176
Community Groups

Creating a PR comment via REST API

I am trying to follow this example:

https://developer.atlassian.com/server/bitbucket/rest/v806/api-group-pull-requests/#api-api-latest-projects-projectkey-repos-repositoryslug-pull-requests-pullrequestid-comments-post

and I have modified my python code to this:

def create_comment(pr_id, comment):
    url = f"http://{baseurl}/rest/api/latest/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pr_id}/comments"
    headers = {"Accept": "application/json", "Content-Type": "application/json"}
    payload = json.dumps({"text": comment})

    response = requests.request(
        "POST",
        url,
        data=payload,
        headers=headers,
        verify=False,
        auth=HTTPKerberosAuth(mutual_authentication=OPTIONAL),
    )

    print(response.status_code)

    print(
        json.dumps(
            json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")
        )
    )

But as a response I always get:

400
{
    "errors": [
        {
            "context": null,
            "exceptionName": null,
            "message": "The path query parameter is required when retrieving comments."
        }
    ]
}

What am I doing wrong here? I am not trying to retrieve comments. I am trying to add a comment. I can add a ?path=/ to my url, but then I only get an empty list of comments.

1 answer

0 votes

Hey @Matthias Redies

I think the problem is with the python requests, which on redirect, transform the POST into a GET request.

My guess is that because you are using "http", you get a redirect (301 or 302) to "https", and then the method changes.

If that doesn't help, try adding allow_redirects=False to disable redirections from the server.

Hope that helps   

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events