名前空間: microsoft.graph
重要
Microsoft Graph の /beta
バージョンの API は変更される可能性があります。 実稼働アプリケーションでこれらの API を使用することは、サポートされていません。 v1.0 で API を使用できるかどうかを確認するには、Version セレクターを使用します。
user オブジェクトのプロパティを更新します。
- 管理者ロールを持たない既定のアクセス許可を持つメンバーまたはゲスト ユーザーが、すべてのプロパティを更新できるわけではありません。
メンバーとゲストの既定のアクセス許可を比較して、管理できるプロパティを確認します。
- 外部テナントでMicrosoft Entra 外部 IDを使用しているお客様は、この API 操作を使用して詳細を更新することもできます。 更新できるプロパティの一覧については、「 外部テナントの既定のユーザーアクセス許可 」を参照してください。
- 同期されたユーザーの場合、特定のプロパティを更新する機能は、権限のソースと同期が有効になっているかどうかによってさらに決定されます。
この API は、次の国内クラウド展開で使用できます。
グローバル サービス |
米国政府機関 L4 |
米国政府機関 L5 (DOD) |
21Vianet が運営する中国 |
✅ |
✅ |
✅ |
✅ |
アクセス許可
この API の最小特権としてマークされているアクセス許可またはアクセス許可を選択します。
アプリで必要な場合にのみ、より高い特権のアクセス許可またはアクセス許可を使用します。 委任されたアクセス許可とアプリケーションのアクセス許可の詳細については、「アクセス許可の種類」を参照してください。 これらのアクセス許可の詳細については、「アクセス許可のリファレンス」を参照してください。
アクセス許可の種類 |
最小特権アクセス許可 |
より高い特権のアクセス許可 |
委任 (職場または学校のアカウント) |
User.ReadWrite |
User.ManageIdentities.All、User.EnableDisableAccount.All、User.ReadWrite.All、Directory.ReadWrite.All |
委任 (個人用 Microsoft アカウント) |
User.ReadWrite |
注意事項なし。 |
アプリケーション |
User.ManageIdentities.All |
User.EnableDisableAccount.All、User.ReadWrite.All、Directory.ReadWrite.All |
特定のシナリオのアクセス許可
- 個人用 Microsoft アカウントに対する User.ReadWrite 委任されたアクセス許可を使用してプロファイルを更新するには、個人用 Microsoft アカウントをMicrosoft Entra テナントに関連付ける必要があります。
-
employeeLeaveDateTime プロパティを更新するには:
- 委任されたシナリオでは、管理者は グローバル管理者 ロールを必要とします。アプリには、 User.Read.All および User-LifeCycleInfo.ReadWrite.All 委任されたアクセス許可が付与されている必要があります。
- Microsoft Graph のアクセス許可を持つアプリのみのシナリオでは、アプリに User.Read.All および User-LifeCycleInfo.ReadWrite.All のアクセス許可を付与する必要があります。
-
customSecurityAttributes プロパティを更新するには:
- 委任されたシナリオでは、管理者に 属性割り当て管理者ロールを割り当て 、アプリに CustomSecAttributeAssignment.ReadWrite.All アクセス許可が付与されている必要があります。
- Microsoft Graph のアクセス許可を持つアプリのみのシナリオでは、アプリに CustomSecAttributeAssignment.ReadWrite.All アクセス許可を付与する必要があります。
-
User-Mail.ReadWrite.All は、 otherMails プロパティを更新するための最小特権アクセス許可です。
-
User-PasswordProfile.ReadWrite.All は、 passwordProfile プロパティを更新するための最小特権アクセス許可です。
-
User-Phone.ReadWrite.All は、businessPhone と mobilePhone のプロパティを更新するための最小特権アクセス許可です。
-
User.EnableDisableAccount.All + User.Read.All は、 accountEnabled プロパティを更新するためのアクセス許可の最小特権の組み合わせです。
-
ID プロパティを更新するには、User.ManageIdentities.All が必要です。
HTTP 要求
PATCH /users/{id | userPrincipalName}
ヘッダー |
値 |
Authorization |
ベアラー {token}。 必須です。
認証と認可についての詳細をご覧ください。 |
Content-Type |
application/json |
要求本文
要求本文で、更新するプロパティの値 のみを 指定します。 要求本文に含まれていない既存のプロパティは、以前の値を維持するか、他のプロパティ値の変更に基づいて再計算されます。
次の表に、更新できるプロパティを示します。
プロパティ |
型 |
説明 |
aboutMe |
String |
ユーザーが自分自身について記述する、フリー フォームのテキスト入力フィールド。 |
accountEnabled |
Boolean |
アカウントが有効な場合は true であり、それ以外の場合は false です。 このプロパティは、ユーザーの作成時に必要です。
User.EnableDisableAccount.All + User.Read.All は、このプロパティを更新するために必要なアクセス許可の最小特権の組み合わせです。 委任されたシナリオでは、 特権認証管理者 は、テナント 内のすべての 管理者に対してこのプロパティを更新できる最小特権ロールです。 一般に、サインインしているユーザーには、機密性の高い アクションを実行できるユーザーに関するページに示されているように、より高い特権を持つ管理者ロールが必要です。 Microsoft Graph のアクセス許可に加えてアプリのみのシナリオでは、「機密性の高い アクションを実行できるユーザー」に示されているように、アプリに高い特権管理者ロールを割り当てる必要があります。 |
ageGroup |
ageGroup |
ユーザーの年齢グループを設定します。 使用できる値: null 、Minor 、NotAdult 、および Adult 。 詳細については、「法的年齢グループ プロパティの定義」を参照してください。 |
assignedLicenses |
assignedLicense コレクション |
ユーザーに割り当てられているライセンス。 null 許容ではありません。 |
birthday |
DateTimeOffset |
ユーザーの誕生日。 Timestamp 型は、ISO 8601 形式を使用して日付と時刻の情報を表し、常に UTC 時間です。 たとえば、2014 年 1 月 1 日午前 0 時 (UTC) は、2014-01-01T00:00:00Z です。 |
businessPhones |
String collection |
ユーザーの電話番号。
手記: これは文字列コレクションですが、このプロパティに設定できる数値は 1 つだけです。
User-Phone.ReadWrite.All は、このプロパティを更新するための最小特権アクセス許可です。 |
city |
String |
ユーザーがいる都市。 |
CompanyName |
String |
ユーザーが関連付けられている会社の名前。 このプロパティは、外部ユーザーが所属する会社を記述するのに役立ちます。 最大の長さは 64 文字です。 |
consentProvidedForMinor |
consentProvidedForMinor |
未成年者について同意を得ているかどうかを設定します。 使用できる値: null 、Granted 、Denied 、および NotRequired 。 詳細については、「法的年齢グループ プロパティの定義」を参照してください。 |
country |
String |
ユーザーがいる国/地域。たとえば、US や UK です。 |
customSecurityAttributes |
customSecurityAttributeValue |
ディレクトリ オブジェクトに割り当てられたカスタム セキュリティ属性の値を保持するオープン複合型。 委任されたシナリオでこのプロパティを更新するには、呼び出し元プリンシパルに属性割り当て管理者ロールが割り当てられ、アプリに CustomSecAttributeAssignment.ReadWrite.All 委任されたアクセス許可が付与されている必要があります。Microsoft Graph のアクセス許可を持つアプリのみのシナリオでこのプロパティを更新するには、アプリに CustomSecAttributeAssignment.ReadWrite.All アプリケーションアクセス許可が付与されている必要があります。 |
department |
String |
ユーザーが働いている部門の名前。 |
displayName |
String |
アドレス帳に表示されるユーザーの名前。 これは通常、ユーザーの名前、ミドルネームのイニシャル、姓の組み合わせになります。 このプロパティは、ユーザーが作成され、更新中にクリアできない場合に必要です。 |
employeeId |
String |
組織によりユーザーに割り当てられた従業員 ID。 最大の長さは 16 文字です。 |
employeeType |
String |
エンタープライズ ワーカーの種類を取得します。 たとえば、Employee 、Contractor 、Consultant 、または Vendor です。 |
givenName |
String |
ユーザーの名。 |
employeeHireDate |
DateTimeOffset |
ユーザーの採用日付。 Timestamp 型は、ISO 8601 形式を使用して日付と時刻の情報を表し、常に UTC 時間です。 たとえば、2014 年 1 月 1 日午前 0 時 (UTC) は、2014-01-01T00:00:00Z です。 |
employeeLeaveDateTime |
DateTimeOffset |
ユーザーが退職した日時または退職する予定の日時。 タイムスタンプの種類は、ISO 8601 形式を使用して日付と時刻の情報を表し、常に UTC 時刻です。 たとえば、2014 年 1 月 1 日午前 0 時 (UTC) は、2014-01-01T00:00:00Z です。 このプロパティを更新するには、呼び出し元のアプリに User-LifeCycleInfo.Read.All アクセス許可と User.Read.All アクセス許可が割り当てられている必要があります。 委任されたシナリオでこのプロパティを更新するには、管理者にグローバル管理者ロールが必要です。 |
employeeOrgData |
employeeOrgData |
ユーザーに関連付けられた組織データ (部署や costCenter など) を表します。
employeeOrgData を更新するときに、両方のプロパティ値を含めます。省略した場合、システムはそれらをnull に設定します。 |
identities |
objectIdentity コレクション |
このユーザー アカウントへのサインインに使用できる ID を表します。 ID は、Microsoft、組織、または Facebook、Google、Microsoft などのソーシャル ID プロバイダーによって提供され、ユーザー アカウントに関連付けられます。
ID を更新するとコレクション全体が置き換えられ、コレクション内で userPrincipalName signInType ID を指定する必要があります。
手記:既存のユーザー オブジェクトへの B2C ローカル アカウントの追加は、ユーザー オブジェクトに既にローカル アカウント ID が含まれていない限り許可されません。 |
interests |
String collection |
ユーザーが自分の関心事を記述する一覧。 |
jobTitle |
String |
ユーザーの役職。 |
mail |
String |
ユーザーの SMTP アドレス (たとえば、jeff@contoso.com )。 Azure AD B2C アカウントの場合、このプロパティは、一意の SMTP アドレスを使用して最大 10 回まで更新できます。 このプロパティを変更すると、ユーザーの proxyAddresses コレクションも更新され、値が SMTP アドレスとして含まれます。
null に更新できません。 |
mailNickname |
String |
ユーザーの電子メール エイリアス。 ユーザーの作成時に、このプロパティを指定する必要があります。 |
mobilePhone |
String |
ユーザーの主な携帯電話の番号。
User-Phone.ReadWrite.All は、このプロパティを更新するための最小特権アクセス許可です。 委任されたシナリオでは、 特権認証管理者 は、テナント 内のすべての 管理者に対してこのプロパティを更新できる最小特権ロールです。 一般に、サインインしているユーザーには、機密性の高い アクションを実行できるユーザーに関するページに示されているように、より高い特権を持つ管理者ロールが必要です。 Microsoft Graph のアクセス許可に加えてアプリのみのシナリオでは、「機密性の高い アクションを実行できるユーザー」に示されているように、アプリに高い特権管理者ロールを割り当てる必要があります。 |
mySite |
String |
ユーザーの個人用サイトの URL。 |
officeLocation |
String |
ユーザーの勤務先の場所。 |
onPremisesExtensionAttributes |
onPremisesExtensionAttributes |
ユーザーの extensionAttribute 1 ~ 15 が含まれています。 個々の拡張属性は、選択またはフィルター処理できません。
onPremisesSyncEnabled ユーザーの場合、このプロパティ セットの権限ソースはオンプレミスで、読み取り専用です。 これらの拡張属性は、Exchange カスタム属性 1-15 とも呼ばれます。 |
onPremisesImmutableId |
String |
このプロパティは、オンプレミスの Active Directory ユーザー アカウントを Microsoft Entra ユーザー オブジェクトに関連付けるために使用されます。 ユーザーの userPrincipalName (UPN) プロパティにフェデレーション ドメインを使用する場合は、Graph で新しいユーザー アカウントを作成する際にこのプロパティを指定する必要があります。
大事な: このプロパティを指定する場合、 $ 文字と _ 文字は使用できません。 |
otherMails |
String collection |
ユーザーの追加のメール アドレスの一覧 (例: ["bob@contoso.com", "Robert@fabrikam.com"] )。 このプロパティを更新するには、ユーザーが持つすべての電子メール アドレスを渡します。それ以外の場合、指定した値によって既存の値が上書きされます。 最大 250 個の値を格納でき、それぞれ 250 文字の制限があります。
User-Mail.ReadWrite.All は、このプロパティを更新するための最小特権アクセス許可です。 委任されたシナリオでは、 特権認証管理者 は、テナント 内のすべての 管理者に対してこのプロパティを更新できる最小特権ロールです。 一般に、サインインしているユーザーには、機密性の高い アクションを実行できるユーザーに関するページに示されているように、より高い特権を持つ管理者ロールが必要です。 Microsoft Graph のアクセス許可に加えてアプリのみのシナリオでは、「機密性の高い アクションを実行できるユーザー」に示されているように、アプリに高い特権管理者ロールを割り当てる必要があります。 |
passwordPolicies |
String |
ユーザーのパスワード ポリシーを指定します。 この値は列挙値であり、可能な 1 つの値は DisableStrongPassword です。この場合は、既定のポリシーより弱いパスワードを指定できます。
DisablePasswordExpiration を指定することもできます。 2 つを一緒に指定できます。例: DisablePasswordExpiration, DisableStrongPassword 。 |
passwordProfile |
passwordProfile |
ユーザーのパスワード プロファイルを指定します。 プロファイルには、ユーザーのパスワードが含まれています。 プロファイルにあるパスワードは、passwordPolicies プロパティによって指定されている最小要件を満たす必要があります。 既定では、強力なパスワードが必要です。 ベスト プラクティスとして、常に forceChangePasswordNextSignIn を true に設定します。 これは、フェデレーション ユーザーには使用できません。
User-PasswordProfile.ReadWrite.All は、このプロパティを更新するための最小特権アクセス許可です。 委任されたシナリオでは、ユーザー管理者Microsoft Entraロールは、管理者以外のユーザーに対してこのプロパティを更新するためにサポートされる最小の特権管理者ロールです。
特権認証管理者 は、テナント 内のすべての 管理者に対してこのプロパティを更新できる最小特権ロールです。 一般に、サインインしているユーザーには、 パスワードをリセットできるユーザーに関するページに示されているように、より高い特権を持つ管理者ロールが必要です。 アプリのみのシナリオでは、呼び出し元のアプリにサポートされているアクセス許可と、少なくともユーザー管理者Microsoft Entraロールを割り当てる必要があります。 |
pastProjects |
String collection |
ユーザーが過去のプロジェクトを列挙する一覧。 |
postalCode |
String |
ユーザーの住所の郵便番号。 郵便番号は、ユーザーの国/地域に固有です。 アメリカ合衆国では、この属性には、ZIP コードが含まれます。 |
preferredLanguage |
String |
ユーザーが設定する言語。 ISO 639-1 コードに従う必要があります (例: en-US )。 |
responsibilities |
String collection |
ユーザーが自分の責任の範囲を列挙する一覧。 |
schools |
String collection |
ユーザーが出席した学校を列挙するためのリスト。 |
skills |
String collection |
ユーザーが自分のスキルを列挙する一覧。 |
state |
String |
ユーザーの住所の都道府県。 |
streetAddress |
String |
ユーザーの勤務先の番地。 |
surname |
String |
ユーザーの姓。 |
usageLocation |
String |
2 文字の国コード (ISO 規格 3166) 国/地域でのサービスの可用性をチェックするための法的要件のためにライセンスが割り当てられるユーザーに必要です。 たとえば、US 、JP 、GB などがあります。 null 許容ではありません。 |
userPrincipalName |
String |
ユーザーのユーザー プリンシパル名 (UPN)。 UPN は、インターネット標準 RFC 822 に基づいた、インターネット スタイルのユーザーのサインイン名です。 規則では、これはユーザーの電子メール名にマップされる必要があります。 一般的な形式は alias@___domain です。このドメインは、検証済みドメインのテナントのコレクション内に存在している必要があります。 テナントの検証済みドメインには、organization の verifiedDomains プロパティからアクセスできます。 このプロパティにアクセント文字を含めることはできません。 次の文字のみ使用することができます A - Z 、a - z 、0 - 9 、 ' . - _ ! # ^ ~ 。 許可される文字の完全なリストについては、ユーザー名ポリシーを参照してください。 |
userType |
String |
ディレクトリ内のユーザーの種類を分類するために使用する文字列値 (Member 、Guest など)。 |
ユーザー リソースは拡張機能をサポートしているため、PATCH
操作を使用して、既存のユーザー インスタンスの拡張機能のカスタム プロパティで独自のアプリ固有のデータを追加、更新、または削除できます。
注:
- 以下のプロパティは、アプリケーションのアクセス許可のみを持つアプリで更新することはできません: aboutMe、birthday、employeeHireDate、interests、mySite、pastProjects、responsibilities、schools、and skills。
- 以下のプロパティを更新するには、上記の表にリストされている他のプロパティを含めずに、独自の PATCH 要求でそれらを指定する必要があります: aboutMe、birthday、interests、mySite、pastProjects、responsibilities、schools、and skills。
拡張機能と関連データを管理する
次のように、この API を使用して、ディレクトリ、スキーマ、およびユーザーのオープン拡張機能とそのデータを管理します。
- 既存のユーザーの拡張機能にデータを追加、更新、格納する
- ディレクトリおよびスキーマ拡張機能の場合は、カスタム拡張プロパティの値を
null
に設定して、格納されているデータをすべて削除します。 オープン拡張機能の場合は、[オープン拡張機能を削除する] API を使用します。
応答
成功した場合、このメソッドは 204 No Content
応答コードを返します。
例
例 1: サインインしているユーザーのプロパティを更新する
要求
次の例は要求を示しています。
PATCH https://graph.microsoft.com/beta/me
Content-type: application/json
{
"businessPhones": [
"+1 425 555 0109"
],
"officeLocation": "18/2111"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new User
{
BusinessPhones = new List<string>
{
"+1 425 555 0109",
},
OfficeLocation = "18/2111",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.PatchAsync(requestBody);
mgc-beta users patch --user-id {user-id} --body '{\
"businessPhones": [\
"+1 425 555 0109"\
],\
"officeLocation": "18/2111"\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewUser()
businessPhones := []string {
"+1 425 555 0109",
}
requestBody.SetBusinessPhones(businessPhones)
officeLocation := "18/2111"
requestBody.SetOfficeLocation(&officeLocation)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
me, err := graphClient.Me().Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
User user = new User();
LinkedList<String> businessPhones = new LinkedList<String>();
businessPhones.add("+1 425 555 0109");
user.setBusinessPhones(businessPhones);
user.setOfficeLocation("18/2111");
User result = graphClient.me().patch(user);
const options = {
authProvider,
};
const client = Client.init(options);
const user = {
businessPhones: [
'+1 425 555 0109'
],
officeLocation: '18/2111'
};
await client.api('/me')
.version('beta')
.update(user);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\User;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new User();
$requestBody->setBusinessPhones(['+1 425 555 0109', ]);
$requestBody->setOfficeLocation('18/2111');
$result = $graphServiceClient->me()->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Users
$params = @{
businessPhones = @(
"+1 425 555 0109"
)
officeLocation = "18/2111"
}
# A UPN can also be used as -UserId.
Update-MgBetaUser -UserId $userId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.user import User
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = User(
business_phones = [
"+1 425 555 0109",
],
office_location = "18/2111",
)
result = await graph_client.me.patch(request_body)
応答
次の例は応答を示しています。
HTTP/1.1 204 No Content
例 2: 指定したユーザーのプロパティを更新する
要求
次の例は要求を示しています。
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"businessPhones": [
"+1 425 555 0109"
],
"officeLocation": "18/2111",
"authorizationInfo": {
"certificateUserIds": [
"5432109876543210@mil"
]
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new User
{
BusinessPhones = new List<string>
{
"+1 425 555 0109",
},
OfficeLocation = "18/2111",
AuthorizationInfo = new AuthorizationInfo
{
CertificateUserIds = new List<string>
{
"5432109876543210@mil",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users["{user-id}"].PatchAsync(requestBody);
mgc-beta users patch --user-id {user-id} --body '{\
"businessPhones": [\
"+1 425 555 0109"\
],\
"officeLocation": "18/2111",\
"authorizationInfo": {\
"certificateUserIds": [\
"5432109876543210@mil"\
]\
}\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewUser()
businessPhones := []string {
"+1 425 555 0109",
}
requestBody.SetBusinessPhones(businessPhones)
officeLocation := "18/2111"
requestBody.SetOfficeLocation(&officeLocation)
authorizationInfo := graphmodels.NewAuthorizationInfo()
certificateUserIds := []string {
"5432109876543210@mil",
}
authorizationInfo.SetCertificateUserIds(certificateUserIds)
requestBody.SetAuthorizationInfo(authorizationInfo)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
users, err := graphClient.Users().ByUserId("user-id").Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
User user = new User();
LinkedList<String> businessPhones = new LinkedList<String>();
businessPhones.add("+1 425 555 0109");
user.setBusinessPhones(businessPhones);
user.setOfficeLocation("18/2111");
AuthorizationInfo authorizationInfo = new AuthorizationInfo();
LinkedList<String> certificateUserIds = new LinkedList<String>();
certificateUserIds.add("5432109876543210@mil");
authorizationInfo.setCertificateUserIds(certificateUserIds);
user.setAuthorizationInfo(authorizationInfo);
User result = graphClient.users().byUserId("{user-id}").patch(user);
const options = {
authProvider,
};
const client = Client.init(options);
const user = {
businessPhones: [
'+1 425 555 0109'
],
officeLocation: '18/2111',
authorizationInfo: {
certificateUserIds: [
'5432109876543210@mil'
]
}
};
await client.api('/users/{id}')
.version('beta')
.update(user);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\User;
use Microsoft\Graph\Beta\Generated\Models\AuthorizationInfo;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new User();
$requestBody->setBusinessPhones(['+1 425 555 0109', ]);
$requestBody->setOfficeLocation('18/2111');
$authorizationInfo = new AuthorizationInfo();
$authorizationInfo->setCertificateUserIds(['5432109876543210@mil', ]);
$requestBody->setAuthorizationInfo($authorizationInfo);
$result = $graphServiceClient->users()->byUserId('user-id')->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Users
$params = @{
businessPhones = @(
"+1 425 555 0109"
)
officeLocation = "18/2111"
authorizationInfo = @{
certificateUserIds = @(
"5432109876543210@mil"
)
}
}
Update-MgBetaUser -UserId $userId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.user import User
from msgraph_beta.generated.models.authorization_info import AuthorizationInfo
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = User(
business_phones = [
"+1 425 555 0109",
],
office_location = "18/2111",
authorization_info = AuthorizationInfo(
certificate_user_ids = [
"5432109876543210@mil",
],
),
)
result = await graph_client.users.by_user_id('user-id').patch(request_body)
応答
次の例は応答を示しています。
HTTP/1.1 204 No Content
例 3: ユーザーの passwordProfile を更新し、パスワードをリセットする
次の例は、別のユーザーのパスワードをリセットする要求を示しています。 ベスト プラクティスとして、常に forceChangePasswordNextSignIn を true
に設定します。
-
User-PasswordProfile.ReadWrite.All は、 passwordProfile プロパティを更新するための最小特権アクセス許可です。
- 委任されたシナリオでは、呼び出し元のアプリに、サポートされているアクセス許可とサポートされているMicrosoft Entra ロールを割り当てる必要があります。
-
特権認証管理者 は、テナント 内のすべての 管理者に対してこのプロパティを更新できる最小特権ロールです。
- 一般に、サインインしているユーザーには、 パスワードをリセットできるユーザーに関するページに示されているように、より高い特権を持つ管理者ロールが必要です。
- Microsoft Graph アプリケーションのアクセス許可を使用するアプリのみのシナリオでは、 User-PasswordProfile.ReadWrite.All が最小特権のアクセス許可です。
要求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"passwordProfile": {
"forceChangePasswordNextSignIn": true,
"password": "xWwvJ]6NMw+bWH-d"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new User
{
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = "xWwvJ]6NMw+bWH-d",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users["{user-id}"].PatchAsync(requestBody);
mgc-beta users patch --user-id {user-id} --body '{\
"passwordProfile": {\
"forceChangePasswordNextSignIn": true,\
"password": "xWwvJ]6NMw+bWH-d"\
}\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewUser()
passwordProfile := graphmodels.NewPasswordProfile()
forceChangePasswordNextSignIn := true
passwordProfile.SetForceChangePasswordNextSignIn(&forceChangePasswordNextSignIn)
password := "xWwvJ]6NMw+bWH-d"
passwordProfile.SetPassword(&password)
requestBody.SetPasswordProfile(passwordProfile)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
users, err := graphClient.Users().ByUserId("user-id").Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
User user = new User();
PasswordProfile passwordProfile = new PasswordProfile();
passwordProfile.setForceChangePasswordNextSignIn(true);
passwordProfile.setPassword("xWwvJ]6NMw+bWH-d");
user.setPasswordProfile(passwordProfile);
User result = graphClient.users().byUserId("{user-id}").patch(user);
const options = {
authProvider,
};
const client = Client.init(options);
const user = {
passwordProfile: {
forceChangePasswordNextSignIn: true,
password: 'xWwvJ]6NMw+bWH-d'
}
};
await client.api('/users/{id}')
.version('beta')
.update(user);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\User;
use Microsoft\Graph\Beta\Generated\Models\PasswordProfile;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new User();
$passwordProfile = new PasswordProfile();
$passwordProfile->setForceChangePasswordNextSignIn(true);
$passwordProfile->setPassword('xWwvJ]6NMw+bWH-d');
$requestBody->setPasswordProfile($passwordProfile);
$result = $graphServiceClient->users()->byUserId('user-id')->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Users
$params = @{
passwordProfile = @{
forceChangePasswordNextSignIn = $true
password = "xWwvJ]6NMw+bWH-d"
}
}
Update-MgBetaUser -UserId $userId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.user import User
from msgraph_beta.generated.models.password_profile import PasswordProfile
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = User(
password_profile = PasswordProfile(
force_change_password_next_sign_in = True,
password = "xWwvJ]6NMw+bWH-d",
),
)
result = await graph_client.users.by_user_id('user-id').patch(request_body)
応答
HTTP/1.1 204 No Content
例 4: 文字列値を持つカスタム セキュリティ属性をユーザーに割り当てる
次の例では、文字列値を持つカスタム セキュリティ属性をユーザーに割り当てる方法を示します。
- 属性セット:
Engineering
- 属性:
ProjectDate
- 属性データ型: 文字列
- 属性値:
"2022-10-01"
カスタム セキュリティ属性を割り当てるには、呼び出し元のプリンシパルに属性割り当て管理者の役割を割り当て、CustomSecAttributeAssignment.ReadWrite.All 権限を付与する必要があります。
カスタム セキュリティ属性の割り当ての例については、「例: Microsoft Graph APIを使用してカスタム セキュリティ属性の割り当てを割り当て、更新、一覧表示、または削除する」を参照してください。
要求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"ProjectDate":"2022-10-01"
}
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
using Microsoft.Kiota.Abstractions.Serialization;
var requestBody = new User
{
CustomSecurityAttributes = new CustomSecurityAttributeValue
{
AdditionalData = new Dictionary<string, object>
{
{
"Engineering" , new UntypedObject(new Dictionary<string, UntypedNode>
{
{
"@odata.type", new UntypedString("#Microsoft.DirectoryServices.CustomSecurityAttributeValue")
},
{
"projectDate", new UntypedString("2022-10-01")
},
})
},
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users["{user-id}"].PatchAsync(requestBody);
mgc-beta users patch --user-id {user-id} --body '{\
"customSecurityAttributes":\
{\
"Engineering":\
{\
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",\
"ProjectDate":"2022-10-01"\
}\
}\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewUser()
customSecurityAttributes := graphmodels.NewCustomSecurityAttributeValue()
additionalData := map[string]interface{}{
engineering := graph.New()
projectDate := "2022-10-01"
engineering.SetProjectDate(&projectDate)
customSecurityAttributes.SetEngineering(engineering)
}
customSecurityAttributes.SetAdditionalData(additionalData)
requestBody.SetCustomSecurityAttributes(customSecurityAttributes)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
users, err := graphClient.Users().ByUserId("user-id").Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
User user = new User();
CustomSecurityAttributeValue customSecurityAttributes = new CustomSecurityAttributeValue();
HashMap<String, Object> additionalData = new HashMap<String, Object>();
engineering = new ();
engineering.setOdataType("#Microsoft.DirectoryServices.CustomSecurityAttributeValue");
engineering.setProjectDate("2022-10-01");
additionalData.put("Engineering", engineering);
customSecurityAttributes.setAdditionalData(additionalData);
user.setCustomSecurityAttributes(customSecurityAttributes);
User result = graphClient.users().byUserId("{user-id}").patch(user);
const options = {
authProvider,
};
const client = Client.init(options);
const user = {
customSecurityAttributes:
{
Engineering:
{
'@odata.type':'#Microsoft.DirectoryServices.CustomSecurityAttributeValue',
ProjectDate: '2022-10-01'
}
}
};
await client.api('/users/{id}')
.version('beta')
.update(user);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\User;
use Microsoft\Graph\Beta\Generated\Models\CustomSecurityAttributeValue;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new User();
$customSecurityAttributes = new CustomSecurityAttributeValue();
$additionalData = [
'Engineering' => [
'@odata.type' => '#Microsoft.DirectoryServices.CustomSecurityAttributeValue',
'projectDate' => '2022-10-01',
],
];
$customSecurityAttributes->setAdditionalData($additionalData);
$requestBody->setCustomSecurityAttributes($customSecurityAttributes);
$result = $graphServiceClient->users()->byUserId('user-id')->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Users
$params = @{
customSecurityAttributes = @{
Engineering = @{
"@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
ProjectDate = "2022-10-01"
}
}
}
Update-MgBetaUser -UserId $userId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.user import User
from msgraph_beta.generated.models.custom_security_attribute_value import CustomSecurityAttributeValue
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = User(
custom_security_attributes = CustomSecurityAttributeValue(
additional_data = {
"engineering" : {
"@odata_type" : "#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"project_date" : "2022-10-01",
},
}
),
)
result = await graph_client.users.by_user_id('user-id').patch(request_body)
応答
HTTP/1.1 204 No Content
例 5: ユーザーのスキーマ拡張機能の値を追加または更新する
拡張機能の単一のプロパティまたはすべてのプロパティに値を更新または割り当てることができます。
要求
PATCH https://graph.microsoft.com/beta/users/4562bcc8-c436-4f95-b7c0-4f8ce89dca5e
Content-type: application/json
{
"ext55gb1l09_msLearnCourses": {
"courseType": "Admin"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
using Microsoft.Kiota.Abstractions.Serialization;
var requestBody = new User
{
AdditionalData = new Dictionary<string, object>
{
{
"ext55gb1l09_msLearnCourses" , new UntypedObject(new Dictionary<string, UntypedNode>
{
{
"courseType", new UntypedString("Admin")
},
})
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users["{user-id}"].PatchAsync(requestBody);
mgc-beta users patch --user-id {user-id} --body '{\
"ext55gb1l09_msLearnCourses": {\
"courseType": "Admin"\
}\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewUser()
additionalData := map[string]interface{}{
ext55gb1l09_msLearnCourses := graph.New()
courseType := "Admin"
ext55gb1l09_msLearnCourses.SetCourseType(&courseType)
requestBody.SetExt55gb1l09_msLearnCourses(ext55gb1l09_msLearnCourses)
}
requestBody.SetAdditionalData(additionalData)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
users, err := graphClient.Users().ByUserId("user-id").Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
User user = new User();
HashMap<String, Object> additionalData = new HashMap<String, Object>();
ext55gb1l09MsLearnCourses = new ();
ext55gb1l09MsLearnCourses.setCourseType("Admin");
additionalData.put("ext55gb1l09_msLearnCourses", ext55gb1l09MsLearnCourses);
user.setAdditionalData(additionalData);
User result = graphClient.users().byUserId("{user-id}").patch(user);
const options = {
authProvider,
};
const client = Client.init(options);
const user = {
ext55gb1l09_msLearnCourses: {
courseType: 'Admin'
}
};
await client.api('/users/4562bcc8-c436-4f95-b7c0-4f8ce89dca5e')
.version('beta')
.update(user);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\User;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new User();
$additionalData = [
'ext55gb1l09_msLearnCourses' => [
'courseType' => 'Admin',
],
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->users()->byUserId('user-id')->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Users
$params = @{
ext55gb1l09_msLearnCourses = @{
courseType = "Admin"
}
}
Update-MgBetaUser -UserId $userId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.user import User
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = User(
additional_data = {
"ext55gb1l09_ms_learn_courses" : {
"course_type" : "Admin",
},
}
)
result = await graph_client.users.by_user_id('user-id').patch(request_body)
ユーザー オブジェクトからスキーマ拡張機能の値を削除するには、 ext55gb1l09_msLearnCourses プロパティを null
に設定します。
応答
HTTP/1.1 204 No Content
関連コンテンツ