Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Trying to retrieve email address of Pull Request author using API

I am using Adpatavist ScriptRunner.

I want to get the email address of whoever raised a pull request, as part of an Event Handler (so it can be sent on to Jenkins)

This is the code I have got to:

PullRequestOpenRequestedEvent event = (PullRequestOpenRequestedEvent)event

def pullRequest=event.getPullRequest()
def email = pullRequest.getAuthor().getUser().getEmailAddress()

 If I just look a the pull request in JSON via the API I can see the email address I want to get

"author": {
"user": {
"name": "myname",
"emailAddress": "",

However, when I do this I get the following error in the logs:, "POST /projects/XXX/repos/YYY/pull-requests HTTP/1.1" c.o.s.b.DynamicEventListenerInvoker Event handler failed: event: com.atlassian.bitbucket.event.pull.PullRequestOpenRequestedEvent file: <inline script>
java.lang.IllegalStateException: Pull request author could not be found in its participants
                at com.atlassian.stash.internal.pull.InternalPullRequest.getAuthor(
                at com.atlassian.bitbucket.pull.PullRequest$ Source)

 Participants is an empty object in the API, and never seems to have anything in it (even when I add reviewers etc)

Am I just missing something fundamental with the API calls? Is my Bitbucket server configured incorrectly?

Any ideas appreciated

3 answers

1 accepted

0 votes
Answer accepted

For anyone else who happens across this, I had the location of getUser within the API incorrect, I got it working using the following:

PullRequestOpenEvent event = (PullRequestOpenEvent)event
def email = event.getUser().getEmailAddress()

Hi @Josh Berry 

Hope you are doing well.

I am looking to update/set the pull request merge commit author as the Original author (pull request open author or developer).

Usually, the developer who (he/she)  worked on the branch will open the pull request and add the reviewers (senior developer/ team lead) to review the pull request changes. Once reviewer reviews or accepts the changes and merge the pull request to Master branch with commit message but the commit author will set as reviewer (because he/she is the one who commit).

So my question is here ...i want to set the pull request merge commit author should set to teh open pull request author.

I am able to get the autoer details using the PullRequestMergeEvent so now i want to compare it to original author and then set it.

Do you have any sample script code to update the pull request commit?

Thanks in advance.

0 votes
Hana Kučerová Community Leader Oct 17, 2019

Hi Josh,

to be able to obtain an email address of a pull request author, you have to send GET request to URL: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}

According to log it seems to me, that you are sending POST request and also there is no pull request id in the url.

Ah, GET vs POST might be the bit of information I was missing. Thanks very much, a new path to go down

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

⭐ Calling all Bitbucket and DevOps experts: Special showcase opportunity ⭐

Hi, Bitbucket community! Are you a DevOps practitioner (or know one in your network)? Do you have DevOps tips, tricks, or learnings you'd like to share with the community? If so, we'd love to hea...

1,440 views 4 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you