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

**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
```


Answers:
author: Stefan Salzl
body: Hi [@Eazhil Amuthan](/t5/user/viewprofilepage/user-id/5367137)

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

comments: author: Eazhil Amuthan
body: Thanks [@Stefan Salzl](/t5/user/viewprofilepage/user-id/4616993) 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](https://community.atlassian.com/t5/image/serverpage/image-id/292550iC48AE35B07EE102E/image-size/large?v=v2&px=999 "Screenshot 2023-11-17 at 11.45.30 PM.png")](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#filtering)


author: Stefan Salzl
body: 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


author: Eazhil Amuthan
body: 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
 }
}
```


author: Stefan Salzl
body: Hi [@Eazhil Amuthan](/t5/user/viewprofilepage/user-id/5367137)

This:  
[https://api.bitbucket.org/2.0/repositories/{workspace}/\[repository}/pullrequests?q=state=](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=](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](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


author: Eazhil Amuthan
body: Encoded URL works thanks [@Stefan Salzl](/t5/user/viewprofilepage/user-id/4616993)


author: Stefan Salzl
body: AWESOME!!!! ??

so good to hear you got that working ??

Best  
Stefan


Tags: bitbucket-cloud

cloud