104 lines
2.8 KiB
PowerShell
104 lines
2.8 KiB
PowerShell
<#
|
|
https://help.deltek.com/Product/Ajera/api/projects.html#messages-api-endpoint-post
|
|
|
|
|
|
#>
|
|
$MPE_Ajera_URI = "https://ajera.mpe.ca/ajera/AjeraAPI.ashx?ew0KICAiRGF0YWJhc2VOYW1lIjogIkFqZXJhIg0KfQ%3d%3d"
|
|
$Headers = @{
|
|
'Content-Type' = 'application/json'
|
|
Accept = 'application/json'
|
|
}
|
|
|
|
$Project_Out = @()
|
|
|
|
function Connect-Ajera {
|
|
|
|
$Session_Body = @{
|
|
Method = "CreateAPISession"
|
|
Username = "MMIntegration"
|
|
Password = "@s0Nny2day"
|
|
APIVersion = 1
|
|
UseSessionCookie = $false
|
|
} | ConvertTo-Json
|
|
|
|
|
|
$Session_token = Invoke-WebRequest -Uri $MPE_Ajera_URI -Method Post -Body $Session_Body -Headers $Headers
|
|
|
|
return $Session_token
|
|
}
|
|
|
|
function Disconnect-Ajera {
|
|
param (
|
|
$Token_to_Kill
|
|
)
|
|
$Session_Body = @{
|
|
Method = "EndAPISession"
|
|
SessionToken = $Token_to_Kill
|
|
} | ConvertTo-Json
|
|
|
|
|
|
$resp = Invoke-WebRequest $MPE_Ajera_URI -Headers $Headers -Body $Session_Body
|
|
return $null
|
|
}
|
|
|
|
|
|
if (!($APIKey)) {
|
|
# get session api key if not already loaded
|
|
$Session = Connect-Ajera
|
|
$resp = $Session.Content | ConvertFrom-Json
|
|
$APIKey = $resp.Content.SessionToken
|
|
}
|
|
|
|
|
|
|
|
$req_body = @{
|
|
Method = 'ListProjects'
|
|
SessionToken = $APIKey
|
|
MethodArguments = @{
|
|
FilterByStatus = @("Active")
|
|
}
|
|
} | ConvertTo-Json
|
|
|
|
|
|
$resp = Invoke-WebRequest -Uri $MPE_Ajera_URI -Headers $Headers -Body $req_body -Method Post
|
|
|
|
$projects = ($resp.Content | convertfrom-json).Content.projects
|
|
|
|
foreach ($project in $projects) {
|
|
# Get Client name for each project.
|
|
$req_body = @{
|
|
Method = 'GetProjects'
|
|
SessionToken = $APIKey
|
|
MethodArguments = @{
|
|
RequestedProjects = @($project.ProjectKey)
|
|
}
|
|
} | ConvertTo-Json
|
|
|
|
$resp = Invoke-WebRequest -Uri $MPE_Ajera_URI -Headers $Headers -Body $req_body -Method Post
|
|
$project_info = ($resp.Content | ConvertFrom-Json).Content
|
|
$Project_SharePoint_FolderName = $project.ID + "-" + $project_info.Projects.InvoiceGroups.Client.Description + '-' + $project.Description
|
|
|
|
$Project_Out += [PSCustomObject]@{
|
|
|
|
ProjectNumber = $project.ID
|
|
ProjectClient = $project_info.Projects.InvoiceGroups.Client.Description
|
|
ProjectName = $project.Description
|
|
Project_Ajera_LastUpdate = $project_info.Projects.LastModifiedDate
|
|
Project_SharePoint_TimeStamp = $null
|
|
Project_SharePoint_FolderName = $Project_SharePoint_FolderName
|
|
}
|
|
|
|
}
|
|
## Disconnect from Ajera.
|
|
$APIKey = Disconnect-Ajera -Token_to_Kill $APIKey
|
|
|
|
$Project_Out | out-gridview
|
|
|
|
# Now, we connect to sharepoint online and add folders
|
|
|
|
# Set the library URL and subfolder name
|
|
$libraryUrl = "https://mpeeng.sharepoint.com/sites/MPEProjectEmails/Shared Documents"
|
|
$subfolderName = "New Subfolder"
|
|
|
|
# Create the subfolder
|