Forum Discussion
MS Project Online API to read calendar information
Hi @Aravind470
To get detailed calendar info from MS Project Online, you'll need to hit a couple of different endpoints. The one you're using gives you the basics, but to get the full picture, like holidays and working days, you need to dig a bit deeper.
Here's how you can do it:
1. Retrieve Calendar Details:
You are already using this endpoint to get basic calendar details:
https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars('calendarid')
2. Retrieve Calendar Work Weeks:
To get information about the work weeks defined in the calendar, you can use:
https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars('calendarid')/WorkWeeks
3. Retrieve Calendar Exceptions:
To get the exceptions (holidays, non-working days) for the calendar, use:
https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars('calendarid')/Exceptions
This will give you a complete look at the calendar, including work weeks and any exceptions like holidays. Easy peasy! ![]()
Regards, Tony
- Aravind470May 31, 2024Copper Contributor
Hi Deleted ,
I attempted to retrieve the calendar details from Project Online using the following endpoints:
- https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars('calendarid')/WorkWeeks
- https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars('calendarid')/Exceptions
However, both requests resulted in a 404 Not Found error.
Can you suggest any alternative endpoints or provide guidance on how to correctly fetch the calendar details, including holidays and working days in a week, from Project Online?
I'm using SharePoint Online credentials for authentication.
I'm uploading the image below
Thank you.
- DeletedMay 31, 2024
You're getting a 404 error, so let's double-check everything.
Check Your URL: Ensure the URL format is correct and consistent:
- Verify the <sitecollection> and <site> values are correct.
- Ensure the calendarid is correctly formatted and exists.
- It should look like this: https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars('calendarid')
Use the Correct Endpoints: Sometimes API versions and structures change. Verify the endpoint paths and usage.
Authentication: Ensure your SharePoint Online credentials are correctly configured and have the necessary permissions.
Alternative Endpoints and Approaches: You might need to use different or additional endpoints to retrieve the detailed calendar information.
1. Get All Calendars:
Start by fetching all calendars to ensure you're using a valid calendar ID.
GET https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars2. Retrieve Calendar Details:
Use the following to get detailed information about a specific calendar:
GET https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars('calendarid')3. Work Weeks and Exceptions:
Sometimes the API paths can be tricky. Try these:Alternative Work Weeks Endpoint:
GET https://<sitecollection>/<site>/pwa/_api/ProjectData/Calendars(guid'calendarid')/WorkWeeksAlternative Exceptions Endpoint:
GET https://<sitecollection>/<site>/pwa/_api/ProjectData/Calendars(guid'calendarid')/ExceptionsExample Code (Updated Fetch Requests)
Here's an updated version of the Fetch requests considering possible adjustments:const siteUrl = 'https://<sitecollection>/<site>';
const calendarId = 'calendarid'; // Ensure this is a valid GUID
const headers = {
'Accept': 'application/json;odata=verbose',
'Authorization': 'Bearer <your_access_token>' // Ensure your access token is valid
};// Fetch all calendars to verify the calendar ID
fetch(`${siteUrl}/pwa/_api/ProjectServer/Calendars`, { headers })
.then(response => response.json())
.then(data => console.log('All Calendars:', data));// Fetch basic calendar details
fetch(`${siteUrl}/pwa/_api/ProjectServer/Calendars('${calendarId}')`, { headers })
.then(response => response.json())
.then(data => console.log('Calendar Details:', data));// Fetch work weeks (alternative endpoint)
fetch(`${siteUrl}/pwa/_api/ProjectData/Calendars(guid'${calendarId}')/WorkWeeks`, { headers })
.then(response => response.json())
.then(data => console.log('Work Weeks:', data));// Fetch exceptions (alternative endpoint)
fetch(`${siteUrl}/pwa/_api/ProjectData/Calendars(guid'${calendarId}')/Exceptions`, { headers })
.then(response => response.json())
.then(data => console.log('Exceptions:', data));
Permissions. Ensure that:- Your account has the necessary permissions to access Project Online APIs.
- The access token or credentials used are valid and have the required scopes.
Debugging Tips
- Verify Calendar ID: Make sure it exists.
- Check Permissions: Your account should have the right access.
- Use Postman: Test the API calls manually to see if you get more detailed error messages.
Hopefully, this helps! If you still run into issues, let me know!
Regards, Tony
- Aravind470Jun 03, 2024Copper ContributorHi Avillarul,
I tried the following endpoints, but I am still getting a 404 error:
1. GET https://<sitecollection>/<site>/pwa/_api/ProjectData/Calendars(guid'calendarid')/WorkWeeks
2. GET https://<sitecollection>/<site>/pwa/_api/ProjectData/Calendars(guid'calendarid')/Exceptions
The following endpoints are working for me:
1. GET https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars
2. GET https://<sitecollection>/<site>/pwa/_api/ProjectServer/Calendars('calendarid')
However, I need to retrieve the workweeks, working time, and exceptions for a calendar. I have confirmed that the credentials are correct, as the API for getting calendars is working. Is there any way to retrieve the working time and workweeks? Any assistance on this would be greatly appreciated