Forum Discussion
MS Project Online API to read calendar information
Alright, let's try another approach since those endpoints aren't working for you.
Given that you can successfully retrieve the list of calendars and details for a specific calendar, let's explore different ways to get the detailed information you need about workweeks and exceptions.
Alternative Approach: Use the Project Server Client-Side Object Model (CSOM)
The CSOM API might offer the functionality you're looking for. You can use it via REST or by scripting in PowerShell.
Using REST API with CSOM
Get Work Weeks and Exceptions: Unfortunately, the specific endpoints for workweeks and exceptions you tried aren't available in the REST API directly. However, you can use the CSOM API.
Example: PowerShell Script Using CSOM
Here's an example using PowerShell to retrieve the information. This script assumes you have the necessary permissions and that you have installed the Microsoft.SharePoint.Client and Microsoft.ProjectServer.Client assemblies.
Install the required modules: First, ensure you have the necessary modules installed:
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
PowerShell Script:
# Load necessary assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.ProjectServer.Client.dll"
# Connect to SharePoint Online
$siteUrl = "https://<sitecollection>/<site>"
$username = "email address removed for privacy reasons"
$password = Read-Host -Prompt "Enter your password" -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
# Get Project Context
$projectContext = New-Object Microsoft.ProjectServer.Client.ProjectContext($siteUrl)
$projectContext.Credentials = $ctx.Credentials
# Load the calendar
$calendarId = [Guid]::Parse("calendarid") # Replace with your calendar ID
$calendar = $projectContext.EnterpriseCalendars.GetById($calendarId)
$projectContext.Load($calendar)
$projectContext.ExecuteQuery()
# Get Work Weeks and Exceptions
$workWeeks = $calendar.WorkWeeks
$exceptions = $calendar.Exceptions
$projectContext.Load($workWeeks)
$projectContext.Load($exceptions)
$projectContext.ExecuteQuery()
# Display Work Weeks
foreach ($workWeek in $workWeeks) {
Write-Output "Work Week: $($workWeek.Name)"
}
# Display Exceptions
foreach ($exception in $exceptions) {
Write-Output "Exception: $($exception.Name)"
}
Using REST API via PowerShell Script
If you need to stick with REST API and you don't have direct endpoints, you might need to:
- Use PowerShell or CSOM: Direct access to calendars' workweeks and exceptions might require client-side scripting.
- Combine Data: If you retrieve the general calendar data and workweek/exceptions data through different means, you might need to combine and process this information locally.
In summary, direct REST endpoints for workweeks and exceptions might not be available. Using the CSOM API via PowerShell or client-side scripting is a solid alternative to get the detailed information you need. This approach should provide you with the ability to retrieve workweeks and exceptions programmatically.
If you're comfortable with PowerShell, give the script a try. If not, consider using CSOM with another client-side language you prefer.
Let me know if you need more help! And good luck!, Tony
Hi Avillarruel,
I tried using CSOM , but I'm still only receiving basic calendar information. I am not getting details on work weeks and work time.
Thanks.
- DeletedJun 05, 2024Ouch! It looks like you are running into some permission or config issues...
- Aravind470Jun 06, 2024Copper ContributorAlright, I'll look into it. Thanks a lot for your help!