-
Notifications
You must be signed in to change notification settings - Fork 211
Description
Describe the bug
Updating a Contact's phone number fails under certain conditions, for example emergency number 911 or 112, but also short number notations.
In my case the number existed already for an Outlook contact, and was copied as part of a cleanup operation, removing identical phone numbers stored in seperate types.
The library seems to use some kind of validation and occasionally stores the original 'string' type as a 'number' type.
The Get-MgBetaUserContactFolderContact returns phone number in a correct way:
(original username replaced with 'me')
Body:
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users('me')/contactFolders('AQMkADAwATExAGM0OC03M2VkLWMzYWEALTAwAi0wMAoALgAAA7DLEhYCI_5MiIWX4_4w8eQBAMWfe-u06ExMAL4DhkswtvFoAAACAQ4AAAA%3D')/contacts",
"value": [
{
"@odata.etag": "W/\"EQAAABYAAADFn3v7tOhMTL4DhkswtvFoAAf5xmKv\"",
"id": "AQMkADAwATExAGM0OC03M2VkLWMzYWEALTAwAi0wMAoARgAAA7DLEhYCI_5MiIWX4_4w8eQHAMWfe-u06ExMAL4DhkswtvFoAAACAQ4AAADFn3v7tOhMTAC_A4ZLMLbxaAAGBgCUeXQAAAA=",
"createdDateTime": "2025-04-11T07:08:26Z",
"lastModifiedDateTime": "2025-04-11T08:16:41Z",
"changeKey": "EQAAABYAAADFn3v7tOhMTL4DhkswtvFoAAf5xmKv",
"categories": [],
"parentFolderId": "AQMkADAwATExAGM0OC03M2VkLWMzYWEALTAwAi0wMAoALgAAA7DLEhYCI_5MiIWX4_4w8eQBAMWfe-u06ExMAL4DhkswtvFoAAACAQ4AAAA=",
"birthday": null,
"fileAs": "Emergency number",
"displayName": "Emergency",
"givenName": "Emergency",
"initials": "E.",
"middleName": "",
"nickName": null,
"surname": "",
"title": "",
"yomiGivenName": null,
"yomiSurname": null,
"yomiCompanyName": null,
"generation": "",
"imAddresses": [],
"jobTitle": "",
"companyName": "",
"department": "",
"officeLocation": null,
"profession": null,
"assistantName": "",
"manager": "",
"spouseName": "",
"personalNotes": "",
"children": [],
"gender": null,
"isFavorite": null,
"emailAddresses": [],
"websites": [],
"phones": [
{
"type": "business",
"number": "112"
}
],
"postalAddresses": [],
"flag": {
"flagStatus": "notFlagged"
}
}
]
}
The SDK seems to rewrite the attribute and under certain condition store it as a different type see:
Body:
{
"fileAs": "Emergency number",
"phones": [
{
"number": 112,
"type": "business"
}
]
}
Expected behavior
The Phone type [Microsoft.Graph.Beta.PowerShell.Models.IMicrosoftGraphPhone] property Number should always be stored as 'string' and never become a 'number'.
Additionally, it looks like the SDK uses certain validation rules for the phone number, which seem to be different from client tools, like Outlook (New).
How to reproduce
- Create in Outlook a Contact with DisplayName 'Emergency' and Phone number 112.
- Save the contact
- Run below code/sequence with a valid $UserID
$UserID = [authenticated-user]
Import-Module -Name Microsoft.Graph.Authentication
Connect-Graph -Scopes User.Read.All, Group.ReadWrite.All, Contacts.ReadWrite -NoWelcome
$FolderParams = @{
UserId = $UserID
Filter = "DisplayName eq 'Contacts'"
}
$ContactFolder = Get-MgBetaUserContactFolder @FolderParams
$ContactParams = @{
UserId = $UserID
ContactFolderId = $ContactFolder.Id
Filter = "contains(DisplayName, 'Emergency')"
}
$Contacts = Get-MgBetaUserContactFolderContact @ContactParams
foreach ($Contact in $Contacts) {
$UpdateParams = @{
UserId = $UserID
ContactFolderId = $ContactFolder.Id
ContactId = $Contact.Id
Phones = $Contact.Phones
FileAs = 'Emergency number'
}
Update-MgBetaUserContactFolderContact @UpdateParams
}
SDK Version
2.26.1
Latest version known to work for scenario above?
No response
Known Workarounds
Explicitly write a string for property Phone.Number, even in case you would not modify it.
[string]$PhoneNr = $Phone.Number
if ($PhoneNr.StartsWith('+') -or $PhoneNr.Length -ne 9) {
# Bug?? If we just keep the number error "Cannot convert the literal '...' to the expected type 'Edm.String'" occurs"
# In case of extension-, emergency number etc.
if ($PhoneNr -match '^[0-9]+$') {
$Phone.Number = "'$PhoneNr'" #Explicit storage of a string
$Phone.Type = 'other'
}
$Phones += $Phone
}
Debug output
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
PATCH
Absolute Uri:
https://graph.microsoft.com/beta/users/me/contactFolders/AQMkADAwATExAGM0OC03M2VkLWMzYWEALTAwAi0wMAoALgAAA7DLEhYCI_5MiIWX4_4w8eQBAMWfe-u06ExMAL4DhkswtvFoAAACAQ4AAAA%3D/contacts/AQMkADAwATExAGM0OC03M2VkLWMzYWEALTAwAi0wMAoARgAAA7DLEhYCI_5MiIWX4_4w8eQHAMWfe-u06ExMAL4DhkswtvFoAAACAQ4AAADFn3v7tOhMTAC_A4ZLMLbxaAAGBgCUeXQAAAA%3D
Headers:
FeatureFlag : 00000003
Cache-Control : no-store, no-cache
User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.26200; nl-NL),PowerShell/2025.0.0
SdkVersion : graph-powershell-beta/2.26.1
client-request-id : dcb04cb6-ce89-49b9-912e-2fda778efa00
Accept-Encoding : gzip,deflate,br
Body:
{
"fileAs": "Emergency number",
"phones": [
{
"number": 112,
"type": "business"
}
]
}
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : private
Strict-Transport-Security : max-age=31536000
request-id : e4e3e22a-9252-43e1-8b6b-27743d23e67c
client-request-id : dcb04cb6-ce89-49b9-912e-2fda778efa00
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"003","RoleInstance":"AM1PEPF000105C8"}}
Date : Fri, 11 Apr 2025 08:16:49 GMT
Body:
{
"error": {
"code": "RequestBodyRead",
"message": "Cannot convert the literal '112' to the expected type 'Edm.String'."
}
}
Update-MgBetaUserContactFolderContact_UpdateExpanded: C:\Users\wimva\OneDrive\Documents\PowerShell\Scripts\Test.ps1:200:9
Line |
200 | Update-MgBetaUserContactFolderContact @userId @UpdateParamete …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot convert the literal '112' to the expected type 'Edm.String'. Status: 400 (BadRequest) ErrorCode: RequestBodyRead Date: Headers:
| Cache-Control : private Strict-Transport-Security : max-age=31536000 request-id :
| e4e3e22a-9252-43e1-8b6b-27743d23e67c client-request-id : dcb04cb6-ce89-49b9-912e-2fda778efa00 x-ms-ags-diagnostic :
| {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"003","RoleInstance":"AM1PEPF000105C8"}} Date :
| Fri, 11 Apr 2025 08:16:49 GMT
Recommendation: See service error codes: https://learn.microsoft.com/graph/errors
DEBUG: [CmdletEndProcessing]: - Update-MgBetaUserContactFolderContact end processing.
Configuration
Name Value
---- -----
PSVersion 7.6.0-preview.4
PSEdition Core
GitCommitId 7.6.0-preview.4
OS Microsoft Windows 10.0.26200
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Other information
No response