このサンプル グループでは、Microsoft Dataverse Web API を使用して、バインドされた関数とバインドされていない関数とアクション (カスタム アクションを含む) を実行する方法を示します。 このサンプルは、次の言語に対する別個のプロジェクトとして実装されます。
この記事では、より高い言語に依存しないレベルでのサンプルの構造と内容について説明します。 この記事で説明する操作の実行方法に関する言語固有の実装の詳細については、上記のリンクされたサンプル記事を参照してください。
対象
このサンプルは、関連する概念に関する記事で詳しく説明されている Web API 関数とアクション操作を含む、次の主要なセクションに分かれています。
次のセクションには、Dataverse Web API 操作の実行に関する簡単な説明が、対応する HTTP メッセージおよび関連するコンソール出力と共に含まれています。
セクション 1: Unbound 関数 WhoAmI
WhoAmI 関数 は、単純で一般的に使用される非連結関数です。
要求:
GET [Organization Uri]/api/data/v9.2/WhoAmI HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
応答:
HTTP/1.1 200 OK
OData-Version: 4.0
{
"@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.WhoAmIResponse",
"BusinessUnitId": "11bb11bb-cc22-dd33-ee44-55ff55ff55ff",
"UserId": "22cc22cc-dd33-ee44-ff55-66aa66aa66aa",
"OrganizationId": "00aa00aa-bb11-cc22-dd33-44ee44ee44ee"
}
コンソール出力:
WhoAmI tells us:
WhoAmIResponse.BusinessUnitId:11bb11bb-cc22-dd33-ee44-55ff55ff55ff
WhoAmIResponse.UserId:22cc22cc-dd33-ee44-ff55-66aa66aa66aa
WhoAmIResponse.OrganizationId:00aa00aa-bb11-cc22-dd33-44ee44ee44ee
ここで取得した BusinessUnitId 値は、「 セクション 8: バインドされたアクション AddPrivilegesRole」で使用されます。
セクション 2: バインドされていない関数 FormatAddress
FormatAddress 関数 は、パラメーターを設定する必要があるバインドされていない関数です。 国/地域形式固有の要件に従ってアドレスを表す文字列を返します。
この例では、パラメーターはクエリ文字列パラメーター値を使用して設定されます。
米国内の住所の要求:
要求:
GET [Organization Uri]/api/data/v9.2/FormatAddress(Line1=@p1,City=@p2,StateOrProvince=@p3,PostalCode=@p4,Country=@p5)?@p1='123%20Maple%20St.'&@p2='Seattle'&@p3='WA'&@p4='98007'&@p5='USA' HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json応答:
HTTP/1.1 200 OK OData-Version: 4.0 { "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.FormatAddressResponse", "Address": "123 Maple St.\r\nSeattle, WA 98007\r\nUSA" }コンソール出力:
USA Formatted Address: 123 Maple St. Seattle, WA 98007 USA日本の住所の要求。
要求:
GET [Organization Uri]/api/data/v9.2/FormatAddress(Line1=@p1,City=@p2,StateOrProvince=@p3,PostalCode=@p4,Country=@p5)?@p1='1-2-3%20Sakura'&@p2='Nagoya'&@p3='Aichi'&@p4='455-2345'&@p5='JAPAN' HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json応答:
HTTP/1.1 200 OK OData-Version: 4.0 { "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.FormatAddressResponse", "Address": "455-2345\r\nAichi\r\nNagoya\r\n1-2-3 Sakura\r\nJAPAN" }コンソール出力:
JAPAN Formatted Address: 455-2345 Aichi Nagoya 1-2-3 Sakura JAPAN
セクション 3: Unbound Function InitializeFrom
InitializeFrom 関数 は、パラメーターを必要とするバインドされていない関数です。 この関数は、既存のレコードのコンテキストで作成する新しいレコードのデータを返します。 コピー先のデータを制御する構成データに応じて、返されるレコード データには元のレコードからコピーされたデータが含まれます。
詳細情報:
元のレコードとなるレコードを作成します。
要求:
POST [Organization Uri]/api/data/v9.2/accounts HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json { "accountcategorycode": 1, "address1_addresstypecode": 3, "address1_city": "Redmond", "address1_country": "USA", "address1_line1": "123 Maple St.", "address1_name": "Corporate Headquarters", "address1_postalcode": "98000", "address1_shippingmethodcode": 4, "address1_stateorprovince": "WA", "address1_telephone1": "555-1234", "customertypecode": 3, "description": "Contoso is a business consulting company.", "emailaddress1": "info@contoso.com", "industrycode": 7, "name": "Contoso Consulting", "numberofemployees": 150, "ownershipcode": 2, "preferredcontactmethodcode": 2, "telephone1": "(425) 555-1234" }応答:
HTTP/1.1 204 NoContent OData-Version: 4.0 OData-EntityId: [Organization Uri]/api/data/v9.2/accounts(22cc22cc-dd33-ee44-ff55-66aa66aa66aa)InitializeFromを使用して、元のレコードから新しいレコードのデータを取得します。要求:
GET [Organization Uri]/api/data/v9.2/InitializeFrom(EntityMoniker=@p1,TargetEntityName=@p2,TargetFieldType=@p3)?@p1={'@odata.id':'accounts(22cc22cc-dd33-ee44-ff55-66aa66aa66aa)'}&@p2='account'&@p3=Microsoft.Dynamics.CRM.TargetFieldType'ValidForCreate' HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json応答:
HTTP/1.1 200 OK Preference-Applied: return=representation OData-Version: 4.0 { "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#accounts/$entity", "@odata.type": "#Microsoft.Dynamics.CRM.account", "parentaccountid@odata.bind": "accounts(22cc22cc-dd33-ee44-ff55-66aa66aa66aa)" }コンソール出力:
New data based on original record: { "@odata.context": "[Organization URI]/api/data/v9.2/$metadata#accounts/$entity", "@odata.type": "#Microsoft.Dynamics.CRM.account", "parentaccountid@odata.bind": "accounts(22cc22cc-dd33-ee44-ff55-66aa66aa66aa)" }注
このリレーションシップにマップされた列がない場合は、上記のように最小列の値のみが含まれます。 この場合、新しいレコードを元のレコードに関連付ける
parentaccountid参照のみが行われます。このリレーションシップに対して使用可能なすべての列がマップされている場合、返される値には元のレコードのデータが追加されます。次に例を示します。
{ "@odata.context": "[Organization URI]/api/data/v9.2/$metadata#accounts/$entity", "@odata.type": "#Microsoft.Dynamics.CRM.account", "territorycode": 1, "address2_freighttermscode": 1, "address2_shippingmethodcode": 1, "address1_telephone1": "555-1234", "accountclassificationcode": 1, "creditonhold": false, "donotbulkemail": false, "donotsendmm": false, "emailaddress1": "info@contoso.com", "address1_line1": "123 Maple St.", "customertypecode": 3, "ownershipcode": 2, "businesstypecode": 1, "donotpostalmail": false, "donotbulkpostalmail": false, "name": "Contoso Consulting", "address1_city": "Redmond", "description": "Contoso is a business consulting company.", "donotemail": false, "address2_addresstypecode": 1, "donotphone": false, "statuscode": 1, "address1_name": "Corporate Headquarters", "followemail": true, "preferredcontactmethodcode": 2, "numberofemployees": 150, "industrycode": 7, "telephone1": "(425) 555-1234", "address1_shippingmethodcode": 4, "donotfax": false, "address1_addresstypecode": 3, "customersizecode": 1, "marketingonly": false, "accountratingcode": 1, "shippingmethodcode": 1, "address1_country": "USA", "participatesinworkflow": false, "accountcategorycode": 1, "address1_postalcode": "98000", "address1_stateorprovince": "WA", "parentaccountid@odata.bind": "accounts(fe9873ac-2f1b-ed11-b83e-00224837179f)" }InitializeFromで返されたデータを使用して新しいレコードを作成します。要求:
POST [Organization Uri]/api/data/v9.2/accounts HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json { "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#accounts/$entity", "@odata.type": "#Microsoft.Dynamics.CRM.account", "parentaccountid@odata.bind": "accounts(22cc22cc-dd33-ee44-ff55-66aa66aa66aa)", "name": "Contoso Consulting Chicago Branch", "address1_city": "Chicago", "address1_line1": "456 Elm St.", "address1_name": "Chicago Branch Office", "address1_postalcode": "60007", "address1_stateorprovince": "IL", "address1_telephone1": "(312) 555-3456", "numberofemployees": 12 }応答:
HTTP/1.1 204 NoContent OData-Version: 4.0 OData-EntityId: [Organization Uri]/api/data/v9.2/accounts(33dd33dd-ee44-ff55-aa66-77bb77bb77bb)コンソール出力:
New Record: { "@odata.context": "[Organization URI]/api/data/v9.2/$metadata#accounts/$entity", "@odata.type": "#Microsoft.Dynamics.CRM.account", "parentaccountid@odata.bind": "accounts(22cc22cc-dd33-ee44-ff55-66aa66aa66aa)", "name": "Contoso Consulting Chicago Branch", "address1_city": "Chicago", "address1_line1": "456 Elm St.", "address1_name": "Chicago Branch Office", "address1_postalcode": "60007", "address1_stateorprovince": "IL", "address1_telephone1": "(312) 555-3456", "numberofemployees": 12 }
セクション 4: Unbound 関数 RetrieveCurrentOrganization
RetrieveCurrentOrganization 関数 は、現在の組織に関する情報を返します。 パラメーターとして EndpointAccessType 列挙型 の値が必要です。
RetrieveCurrentOrganization は、RetrieveCurrentOrganizationResponse 複合型 を返します。この型には、Detail プロパティが含まれており、これは OrganizationDetail 複合型 です。EndpointCollection 複合型、EndpointType 列挙型 および OrganizationState 列挙型 を使用する複合プロパティを持ちます。
注
URL で AccessTypeEndpointAccessType 列挙型 パラメーター値がどのように渡されるかに注目してください。 選択したメンバー名を持つ完全修飾名が必要です。
要求:
GET [Organization Uri]/api/data/v9.2/RetrieveCurrentOrganization(AccessType=@p1)?@p1=Microsoft.Dynamics.CRM.EndpointAccessType'Default' HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
応答:
HTTP/1.1 200 OK
OData-Version: 4.0
{
"@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.RetrieveCurrentOrganizationResponse",
"Detail": {
"OrganizationId": "11bb11bb-cc22-dd33-ee44-55ff55ff55ff",
"FriendlyName": "[Organization Name]",
"OrganizationVersion": "9.2.22074.168",
"EnvironmentId": "Default-aaaabbbb-0000-cccc-1111-dddd2222eeee",
"DatacenterId": "695014e1-bafd-4d7e-9d3d-2261d4aaf780",
"Geo": "NA",
"TenantId": "aaaabbbb-0000-cccc-1111-dddd2222eeee",
"UrlName": "org619726b5",
"UniqueName": "org0335df44",
"State": "Enabled",
"Endpoints": {
"Count": 3,
"IsReadOnly": false,
"Keys": [
"WebApplication",
"OrganizationService",
"OrganizationDataService"
],
"Values": [
"[Organization URI]/",
"[Organization URI]/XRMServices/2011/Organization.svc",
"[Organization URI]/XRMServices/2011/OrganizationData.svc"
]
}
}
}
コンソール出力:
Data returned with RetrieveCurrentOrganizationResponse:
{
"OrganizationId": "11bb11bb-cc22-dd33-ee44-55ff55ff55ff",
"FriendlyName": "[Organization Name]",
"OrganizationVersion": "9.2.22074.168",
"EnvironmentId": "Default-aaaabbbb-0000-cccc-1111-dddd2222eeee",
"DatacenterId": "695014e1-bafd-4d7e-9d3d-2261d4aaf780",
"Geo": "NA",
"TenantId": "aaaabbbb-0000-cccc-1111-dddd2222eeee",
"UrlName": "org619726b5",
"UniqueName": "org0335df44",
"Endpoints": {
"Count": 3,
"IsReadOnly": false,
"Keys": [
"WebApplication",
"OrganizationService",
"OrganizationDataService"
],
"Values": [
"[Organization URI]/",
"[Organization URI]/XRMServices/2011/Organization.svc",
"[Organization URI]/XRMServices/2011/OrganizationData.svc"
]
},
"State": "Enabled"
}
セクション 5: Unbound 関数 RetrieveTotalRecordCount
RetrieveTotalRecordCount 関数 は、特定のエンティティのレコードの合計数に関するデータを返します。 取得されたデータは過去 24 時間以内のスナップショットから取得されるため、特定の時点での正確なカウントではありません。
要求:
GET [Organization Uri]/api/data/v9.2/RetrieveTotalRecordCount(EntityNames=@p1)?@p1=["account","contact"] HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
応答:
HTTP/1.1 200 OK
OData-Version: 4.0
{
"@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.RetrieveTotalRecordCountResponse",
"EntityRecordCountCollection": {
"Count": 2,
"IsReadOnly": false,
"Keys": [
"account",
"contact"
],
"Values": [
19,
3
]
}
}
コンソール出力:
The number of records for each table according to RetrieveTotalRecordCount:
account:19
contact:3
セクション 6: バインドされた関数 IsSystemAdmin カスタム API
バインドされた関数を示すために、このサンプルでは、サンプルのこの部分を実行する前に、ソリューション内で定義されたカスタム メッセージをインポートします。
このサンプルでは、sample_IsSystemAdmin を使用して定義されたカスタム メッセージを使用します。 このカスタム API の詳細については、 サンプル: IsSystemAdmin カスタム API を参照してください。
注
バインドされた関数またはアクションを使用する場合は、url に Microsoft.Dynamics.CRM.+ <関数またはアクション名> 含む完全修飾名を含める必要があります。
要求:
GET [Organization Uri]/api/data/v9.2/systemusers(ce31e691-f559-ec11-8f8f-000d3a308de4)/Microsoft.Dynamics.CRM.sample_IsSystemAdmin HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
応答:
HTTP/1.1 200 OK
OData-Version: 4.0
{
"@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.sample_IsSystemAdminResponse",
"HasRole": false
}
このサンプルでは、10 個のユーザー レコードを取得し、それぞれをテストして、各ユーザーがシステム管理者セキュリティ ロールを持っているかどうかを判断します。
コンソール出力:
実際の名前は、環境内のユーザーによって異なります。
Top 10 users and whether they have System Administrator role.
Gediminas Matulis does not have the System Administrator role.
Gaby Frost does not have the System Administrator role.
Henrikas Martinkus does not have the System Administrator role.
Alain Davignon HAS the System Administrator role.
Isobel Macintyre HAS the System Administrator role.
Ale Laukaitiene HAS the System Administrator role.
Rudabeh Yekta HAS the System Administrator role.
Grazina Januliene HAS the System Administrator role.
Pranciskus Sukys HAS the System Administrator role.
Asha Sawant HAS the System Administrator role.
バインドされた関数の別の例については、次の例の RetrievePrincipalAccess 関数 の使用を参照してください。
セクション 7: 制約のないアクション GrantAccess
GrantAccess アクション は、ユーザーが環境内の他のユーザーに特定の特権を共有することを許可するバインドされていないアクションです。
サンプル コードでは、次の操作を示します。
共有するレコードを作成します。
現在のユーザー以外の有効なユーザーを検索します。
RetrievePrincipalAccess 関数を使用して、ユーザーが作成したレコードに対して持っているアクセス権を決定します。
要求:
GET [Organization Uri]/api/data/v9.2/systemusers(ce31e691-f559-ec11-8f8f-000d3a308de4)/Microsoft.Dynamics.CRM.RetrievePrincipalAccess(Target=@p1)?@p1={'@odata.id':'accounts(659876fd-6d29-ed11-9db1-00224804f8e2)'} HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json応答:
HTTP/1.1 200 OK OData-Version: 4.0 { "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.RetrievePrincipalAccessResponse", "AccessRights": "ShareAccess" }コンソール出力:
Testing user: Gediminas Matulis Current users access: ShareAccessユーザーが AccessRights.
DeleteAccessを持っていない場合は、GrantAccessアクションを使用してこのアクセス権をユーザーに付与します。要求:
POST [Organization Uri]/api/data/v9.2/GrantAccess HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json { "Target": { "accountid": "659876fd-6d29-ed11-9db1-00224804f8e2", "@odata.type": "Microsoft.Dynamics.CRM.account" }, "PrincipalAccess": { "AccessMask": "DeleteAccess", "Principal": { "systemuserid": "ce31e691-f559-ec11-8f8f-000d3a308de4", "@odata.type": "Microsoft.Dynamics.CRM.systemuser" } } }応答:
HTTP/1.1 204 NoContent OData-Version: 4.0DeleteAccessが許可されると、RetrievePrincipalAccess 関数に対する同じ呼び出しで、このレコードを削除するアクセス権が付与されたことが示されます。要求:
GET [Organization Uri]/api/data/v9.2/systemusers(ce31e691-f559-ec11-8f8f-000d3a308de4)/Microsoft.Dynamics.CRM.RetrievePrincipalAccess(Target=@p1)?@p1={'@odata.id':'accounts(659876fd-6d29-ed11-9db1-00224804f8e2)'} HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json応答:
HTTP/1.1 200 OK OData-Version: 4.0 { "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.RetrievePrincipalAccessResponse", "AccessRights": "DeleteAccess, ShareAccess" }コンソール出力:
Gediminas Matulis was granted DeleteAccess
セクション 8: バインドされたアクション AddPrivilegesRole
AddPrivilegesRole アクション は、 ロール エンティティ型にバインドされたアクションです。 セキュリティ ロールに特権を追加する方法です。
サンプル コードでは、次の操作を実行します。
セキュリティ ロールを作成します。 ロールは、部署に関連付けられている必要があります。 部署 ID の値は 、「セクション 1: Unbound Function WhoAmI」で取得されました。
要求:
POST [Organization Uri]/api/data/v9.2/roles HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json { "businessunitid@odata.bind": "businessunits(cca3985e-c618-ea11-a811-000d3a33f066)", "name": "Test Role" }応答:
HTTP/1.1 204 NoContent OData-Version: 4.0 OData-EntityId: [Organization Uri]/api/data/v9.2/roles(44ee44ee-ff55-aa66-bb77-88cc88cc88cc)ロールを取得し、ロールに含まれる特権を含めるためにコレクション値のナビゲーション プロパティ
roleprivileges_associationを展開します。要求:
GET [Organization Uri]/api/data/v9.2/roles(44ee44ee-ff55-aa66-bb77-88cc88cc88cc)?$select=roleid&$expand=roleprivileges_association($select=name) HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json応答:
HTTP/1.1 200 OK ETag: W/"13278232" OData-Version: 4.0 { "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#roles(roleid,roleprivileges_association(name))/$entity", "@odata.etag": "W/\"13278232\"", "roleid": "44ee44ee-ff55-aa66-bb77-88cc88cc88cc", "roleprivileges_association": [ { "@odata.etag": "W/\"142279\"", "name": "prvReadSharePointData", "privilegeid": "fecbd29c-df64-4ede-a611-47226b402c22" }, { "@odata.etag": "W/\"142304\"", "name": "prvReadSdkMessage", "privilegeid": "94c3ac2c-eb23-41cb-a903-4e2e49e910b4" }, { "@odata.etag": "W/\"142421\"", "name": "prvWriteSharePointData", "privilegeid": "cfdd12cf-090b-4599-8302-771962d2350a" }, { "@odata.etag": "W/\"142477\"", "name": "prvReadSdkMessageProcessingStepImage", "privilegeid": "122e085f-8c52-47e8-8415-875dee1c961e" }, { "@odata.etag": "W/\"142695\"", "name": "prvReadSdkMessageProcessingStep", "privilegeid": "db10a828-ec49-4035-8b7e-c58efaf169ec" }, { "@odata.etag": "W/\"142713\"", "name": "prvReadPluginAssembly", "privilegeid": "f5b50296-a212-488a-be92-cbcca8971717" }, { "@odata.etag": "W/\"142735\"", "name": "prvCreateSharePointData", "privilegeid": "5eb85025-363b-46ea-a77e-ce24159cd231" }, { "@odata.etag": "W/\"142740\"", "name": "prvReadPluginType", "privilegeid": "9365005c-4703-473b-8d3c-d073cfd8670c" }, { "@odata.etag": "W/\"142761\"", "name": "prvReadSharePointDocument", "privilegeid": "d71fc8d0-99bc-430e-abd7-d95c64f11e9c" } ] }新しいロールに対して既定で作成された特権の数を表示します。
コンソール出力:
Number of privileges in new role: 9 prvReadSharePointData prvReadSdkMessage prvWriteSharePointData prvReadSdkMessageProcessingStepImage prvReadSdkMessageProcessingStep prvReadPluginAssembly prvCreateSharePointData prvReadPluginType prvReadSharePointDocumentprvCreateAccountからprvReadAccountおよび特権の定義を取得します。要求:
GET [Organization Uri]/api/data/v9.2/privileges?$select=name&$filter=name eq 'prvCreateAccount' or name eq 'prvReadAccount' HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json応答:
HTTP/1.1 200 OK OData-Version: 4.0 { "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#privileges(name)", "value": [ { "@odata.etag": "W/\"142189\"", "name": "prvReadAccount", "privilegeid": "886b280c-6396-4d56-a0a3-2c1b0a50ceb0" }, { "@odata.etag": "W/\"142359\"", "name": "prvCreateAccount", "privilegeid": "d26fe964-230b-42dd-ad93-5cc879de411e" } ] }プロパティを
prvCreateAccountに設定して、prvReadAccountおよびDepth特権の RolePrivilege ComplexType インスタンスの一覧を準備します。'Basic'。リストを
AddPrivilegesRole.Privilegesパラメーターとして渡します。要求:
POST [Organization Uri]/api/data/v9.2/roles(44ee44ee-ff55-aa66-bb77-88cc88cc88cc)/Microsoft.Dynamics.CRM.AddPrivilegesRole HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json { "Privileges": [ { "Depth": "Basic", "PrivilegeId": "886b280c-6396-4d56-a0a3-2c1b0a50ceb0", "BusinessUnitId": "cca3985e-c618-ea11-a811-000d3a33f066", "PrivilegeName": "prvReadAccount" }, { "Depth": "Basic", "PrivilegeId": "d26fe964-230b-42dd-ad93-5cc879de411e", "BusinessUnitId": "cca3985e-c618-ea11-a811-000d3a33f066", "PrivilegeName": "prvCreateAccount" } ] }応答:
HTTP/1.1 204 NoContent OData-Version: 4.0ロールに関連付けられている特権をもう一度取得して、追加されたことを確認します。
要求:
GET [Organization Uri]/api/data/v9.2/roles(44ee44ee-ff55-aa66-bb77-88cc88cc88cc)?$select=roleid&$expand=roleprivileges_association($select=name) HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json応答:
HTTP/1.1 200 OK ETag: W/"13278248" OData-Version: 4.0 { "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#roles(roleid,roleprivileges_association(name))/$entity", "@odata.etag": "W/\"13278248\"", "roleid": "44ee44ee-ff55-aa66-bb77-88cc88cc88cc", "roleprivileges_association": [ { "@odata.etag": "W/\"142189\"", "name": "prvReadAccount", "privilegeid": "886b280c-6396-4d56-a0a3-2c1b0a50ceb0" }, { "@odata.etag": "W/\"142279\"", "name": "prvReadSharePointData", "privilegeid": "fecbd29c-df64-4ede-a611-47226b402c22" }, { "@odata.etag": "W/\"142304\"", "name": "prvReadSdkMessage", "privilegeid": "94c3ac2c-eb23-41cb-a903-4e2e49e910b4" }, { "@odata.etag": "W/\"142359\"", "name": "prvCreateAccount", "privilegeid": "d26fe964-230b-42dd-ad93-5cc879de411e" }, { "@odata.etag": "W/\"142421\"", "name": "prvWriteSharePointData", "privilegeid": "cfdd12cf-090b-4599-8302-771962d2350a" }, { "@odata.etag": "W/\"142477\"", "name": "prvReadSdkMessageProcessingStepImage", "privilegeid": "122e085f-8c52-47e8-8415-875dee1c961e" }, { "@odata.etag": "W/\"142695\"", "name": "prvReadSdkMessageProcessingStep", "privilegeid": "db10a828-ec49-4035-8b7e-c58efaf169ec" }, { "@odata.etag": "W/\"142713\"", "name": "prvReadPluginAssembly", "privilegeid": "f5b50296-a212-488a-be92-cbcca8971717" }, { "@odata.etag": "W/\"142735\"", "name": "prvCreateSharePointData", "privilegeid": "5eb85025-363b-46ea-a77e-ce24159cd231" }, { "@odata.etag": "W/\"142740\"", "name": "prvReadPluginType", "privilegeid": "9365005c-4703-473b-8d3c-d073cfd8670c" }, { "@odata.etag": "W/\"142761\"", "name": "prvReadSharePointDocument", "privilegeid": "d71fc8d0-99bc-430e-abd7-d95c64f11e9c" } ] }コンソール出力:
Number of privileges after: 11 prvReadAccount prvReadSharePointData prvReadSdkMessage prvCreateAccount prvWriteSharePointData prvReadSdkMessageProcessingStepImage prvReadSdkMessageProcessingStep prvReadPluginAssembly prvCreateSharePointData prvReadPluginType prvReadSharePointDocument
セクション 9: サンプル レコードを削除
このサンプルで作成された各レコードは、最後に削除されるリストに追加されました。 これらのレコードは、 $batch 要求を使用して削除されます。
要求:
POST [Organization Uri]/api/data/v9.2/$batch HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
--batch_d6010246-cd97-429f-bc05-cf20054cfe8a
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121
DELETE /api/data/v9.2/accounts(22cc22cc-dd33-ee44-ff55-66aa66aa66aa) HTTP/1.1
--batch_d6010246-cd97-429f-bc05-cf20054cfe8a
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121
DELETE /api/data/v9.2/accounts(33dd33dd-ee44-ff55-aa66-77bb77bb77bb) HTTP/1.1
--batch_d6010246-cd97-429f-bc05-cf20054cfe8a
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 122
DELETE /api/data/v9.2/solutions(b37bc86a-4c3a-41be-b35d-ddfd129276c5) HTTP/1.1
--batch_d6010246-cd97-429f-bc05-cf20054cfe8a
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 121
DELETE /api/data/v9.2/accounts(659876fd-6d29-ed11-9db1-00224804f8e2) HTTP/1.1
--batch_d6010246-cd97-429f-bc05-cf20054cfe8a
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Length: 118
DELETE /api/data/v9.2/roles(44ee44ee-ff55-aa66-bb77-88cc88cc88cc) HTTP/1.1
--batch_d6010246-cd97-429f-bc05-cf20054cfe8a--
応答:
HTTP/1.1 200 OK
OData-Version: 4.0
--batchresponse_cb852192-c300-4ed7-a54f-dc5fc7ee27c3
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 204 No Content
OData-Version: 4.0
--batchresponse_cb852192-c300-4ed7-a54f-dc5fc7ee27c3
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 204 No Content
OData-Version: 4.0
--batchresponse_cb852192-c300-4ed7-a54f-dc5fc7ee27c3
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 204 No Content
OData-Version: 4.0
--batchresponse_cb852192-c300-4ed7-a54f-dc5fc7ee27c3
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 204 No Content
OData-Version: 4.0
--batchresponse_cb852192-c300-4ed7-a54f-dc5fc7ee27c3
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 204 No Content
OData-Version: 4.0
--batchresponse_cb852192-c300-4ed7-a54f-dc5fc7ee27c3--
コンソール出力:
Deleting created records.
こちらも参照ください
Dataverse Web API を使用する
Web API 関数を使用する
Web API アクションの使用
Web API 機能およびアクションのサンプル (C#)