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

I'm trying to fetch pull requests by created date but the query is not working.

Eazhil Amuthan November 17, 2023

Query not working

I'm trying to fetch pull requests by created date but the query is not working.
i tried multiple queries with dates but none seems to be working.
Can anyone help me with how to structure the queries with dates

https://api.bitbucket.org/2.0/repositories/${workspace}/${repository}/pullrequests?q=state="MERGED"&created_on>2023-11-19T14:19:29

1 answer

1 accepted

0 votes
Answer accepted
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2023

Hi @Eazhil Amuthan 

welcome to the community.

Unfortunately I couldn´t find any query in the bitbucket API docu that supports a queryParameter called "created_on".

https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-get

 

Could you maybe send information where this is documented?

Best
Stefan

Eazhil Amuthan November 17, 2023

Thanks @Stefan Salzl for the speedy reply.
Here it's listed that we can use created_on to filter some of the following endpoint.

What I'm trying to achieve is to fetch all merged PRs between two release branches.
If this isn't possible, Is there any other way to achieve it?

https://developer.atlassian.com/cloud/bitbucket/rest/intro/#filtering
Screenshot 2023-11-17 at 11.45.30 PM.png

Like Stefan Salzl likes this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2023

ah... thanks for the hint. wasn´t aware of that. I´ll have to experiment with them.

Meanwhile:

Could you tell/show us how you are calling the API/in which way (automation/curl call/...) and what you get as a result/error?

Best
Stefan

Eazhil Amuthan November 17, 2023

I'm using axios to call the API and I'm not getting any errors but only the state filter ( state = "MERGED") is working 

const INITIAL_URL = `https://api.bitbucket.org/2.0/repositories/${workspace}/${repository}/pullrequests?q=state="MERGED"&created_on>2023-11-17T05:11:02`
const fetchAllPRs = async (URL) => {
try {
const res = await axios.get(URL, {
headers: {
Authorization: `Bearer ${token}`,
}
})
return res.data
} catch(e) {
console.log(e)
return null
}
}
Like Stefan Salzl likes this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2023

Hi @Eazhil Amuthan 

This:
https://api.bitbucket.org/2.0/repositories/{workspace}/[repository}/pullrequests?q=state="merged"&created_on<2023-02-27

as well as this:
https://api.bitbucket.org/2.0/repositories/{workspace}/[repository}/pullrequests?q=state="merged" AND created_on<2023-02-27

worked in my instance (I did the calls via postman, maybe you need to first encode your query before sending).

the encoded call looks like:
https://api.bitbucket.org/2.0/repositories/{workspace}/[repository}/pullrequests?q=state=%22merged%22%20and%20created_on%3C2023-02-27

Furthermore one more question:
do you get an empty reply or an error?

because I could see that you are filtering for any created_on date greater (>) than today (which makes it logic that it doesn´t provide any results). Could you try to change the "greater than" to a "smaller than (<) ?

Best
Stefan

Eazhil Amuthan November 17, 2023

Encoded URL works thanks @Stefan Salzl  

Like Stefan Salzl likes this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2023

AWESOME!!!! 💪💪

so good to hear you got that working ✌✌

 

Best
Stefan

Like # people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events