It looks like you’re trying to filter projects based on their access level (PUBLIC/PRIVATE) using the Clockify API, but the filter isn’t working as expected. The current request seems to be returning all projects instead of just the public ones. Here’s a solution that might help you filter the projects correctly:
This request is returning all projects regardless of the access level.
Solution:
Clockify’s API might not directly support filtering projects by access level in the way you’re trying to use it. You may need to fetch all projects first and then filter them on the client side based on their access level.
Step-by-Step Guide:
Fetch All Projects: First, retrieve all projects without applying the access filter.
Filter Projects on Client Side: Once you have all the projects, you can filter them based on the access level in your code.
javascript
Copy code
async function fetchAndFilterProjects() {
try {
const response = await axios.get(`/projects?page-size=50&page=${page}&archived=false`);
const projects = response.data;
// Filter projects by access level
const publicProjects = projects.filter(project => project.access === 'PUBLIC');
// Do something with the filtered projects
console.log(publicProjects);
} catch (error) {
console.error('Error fetching projects:', error);
}
}
fetchAndFilterProjects();
Explanation:
Fetching Projects: You fetch all projects without filtering by access level.
Filtering Projects: After fetching the projects, you filter them on the client side to get only the public projects.
Full Example:
Here is the full example incorporating both fetching and filtering:
javascript
Copy code
import axios from 'axios';
async function fetchAndFilterProjects(page) {
try {
const response = await axios.get(`/projects?page-size=50&page=${page}&archived=false`);
const projects = response.data;
// Filter projects by access level
const publicProjects = projects.filter(project => project.access === 'PUBLIC');
// Do something with the filtered projects
console.log(publicProjects);
} catch (error) {
console.error('Error fetching projects:', error);
}
}
// Example usage
fetchAndFilterProjects(1);
Additional Tips:
Pagination: If you have a large number of projects, ensure you handle pagination properly by iterating through all pages.
Error Handling: Make sure to handle any errors that might occur during the API request to avoid issues in your application.
By following this approach, you should be able to filter projects based on their access level effectively. If you have any further questions or need additional assistance, feel free to ask!
async getPublicProjects() {
// here is api call get<Project[]>(
// `/projects?page-size=50&page=${page}&archived=false`
// )
const publicProjects = data.filter((el) => el.public);
return publicProjects;
},
I needed to do it in one query, to fetch all public projects, and all other private projects where user have access.
Every query filter works what is described in clockify developer api docs, expect access filter
Thanks