Skip to content

Commit

Permalink
api changes to fit frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
kris6673 committed Feb 4, 2025
1 parent b898886 commit d3a5cbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@ Function Invoke-EditContact {

# Prepare the body for the Set-Contact cmdlet
$bodyForSetContact = [pscustomobject] @{
'DisplayName' = $contactInfo.DisplayName
'WindowsEmailAddress' = $contactInfo.mail
'Identity' = $contactInfo.ContactID
'DisplayName' = $contactInfo.displayName
'WindowsEmailAddress' = $contactInfo.email
'FirstName' = $contactInfo.firstName
'LastName' = $contactInfo.LastName
'Title' = $contactInfo.jobTitle
'Title' = $contactInfo.Title
'StreetAddress' = $contactInfo.StreetAddress
'PostalCode' = $contactInfo.PostalCode
'City' = $contactInfo.City
'CountryOrRegion' = $contactInfo.Country
'Company' = $contactInfo.companyName
'mobilePhone' = $contactInfo.MobilePhone
'phone' = $contactInfo.BusinessPhone
'identity' = $contactInfo.ContactID
'CountryOrRegion' = $contactInfo.CountryOrRegion
'Company' = $contactInfo.Company
'mobilePhone' = $contactInfo.mobilePhone
'phone' = $contactInfo.phone
}

# Call the Set-Contact cmdlet to update the contact
$null = New-ExoRequest -tenantid $TenantID -cmdlet 'Set-Contact' -cmdParams $bodyForSetContact -UseSystemMailbox $true
$null = New-ExoRequest -tenantid $TenantID -cmdlet 'Set-MailContact' -cmdParams @{Identity = $contactInfo.ContactID; HiddenFromAddressListsEnabled = [System.Convert]::ToBoolean($contactInfo.hidefromGAL) } -UseSystemMailbox $true
$Results = "Successfully edited contact $($contactInfo.DisplayName)"
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant $TenantID -message $Results -Sev Info
$StatusCode = [HttpStatusCode]::OK
Expand All @@ -57,6 +58,6 @@ Function Invoke-EditContact {
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = $responseResults
Body = $Results
})
}
30 changes: 8 additions & 22 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-ListContacts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ Function Invoke-ListContacts {
Exchange.Contact.Read
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
$Request,

[Parameter(Mandatory = $true)]
$TriggerMetadata
)
param($Request, $TriggerMetadata)


# Define fields to retrieve
Expand All @@ -36,8 +30,8 @@ Function Invoke-ListContacts {
$TenantFilter = $Request.Query.tenantFilter
$ContactID = $Request.Query.id

Write-Host "Tenant Filter: $TenantFilter"
Write-Host "Contact ID: $ContactID"
# Write-Host "Tenant Filter: $TenantFilter"
# Write-Host "Contact ID: $ContactID"

# Validate required parameters
if (-not $TenantFilter) {
Expand All @@ -47,36 +41,28 @@ Function Invoke-ListContacts {
} else {
try {
# Construct Graph API URI based on whether an ID is provided
$graphUri = if ($ContactID) {
"https://graph.microsoft.com/beta/contacts/$ContactID?`$select=$($selectList -join ',')"
$graphUri = if ([string]::IsNullOrWhiteSpace($ContactID) -eq $false) {
"https://graph.microsoft.com/beta/contacts/$($ContactID)?`$select=$($selectList -join ',')"
} else {
"https://graph.microsoft.com/beta/contacts?`$top=999&`$select=$($selectList -join ',')"
}

Write-Host "Making Graph API request to: $graphUri"
# Write-Host "Making Graph API request to: $graphUri"

# Make the Graph API request
$GraphRequest = New-GraphGetRequest -uri $graphUri -tenantid $TenantFilter |
Select-Object $selectList |
ForEach-Object {
$_.editURL = "https://outlook.office365.com/ecp/@$TenantFilter/UsersGroups/EditContact.aspx?exsvurl=1&realm=$($env:TenantID)&mkt=en-US&id=$($_.id)"
$_
}
$GraphRequest = New-GraphGetRequest -uri $graphUri -tenantid $TenantFilter

# Ensure single result when ID is provided
if ($ContactID -and $GraphRequest -is [array]) {
$GraphRequest = $GraphRequest | Select-Object -First 1
Write-Host 'Multiple results found for ID, selecting first match'
}

$StatusCode = [HttpStatusCode]::OK
Write-Host 'Successfully retrieved contact data'
Write-Host (ConvertTo-Json $GraphRequest -Depth 5)
# Write-Host (ConvertTo-Json $GraphRequest -Depth 5)
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
$StatusCode = [HttpStatusCode]::InternalServerError
$GraphRequest = $ErrorMessage
Write-Host "Error retrieving contacts: $ErrorMessage"
}
}

Expand Down

0 comments on commit d3a5cbf

Please sign in to comment.