SelfServePolicy を作成する

この記事では、新しいセルフサービス ポリシーを作成する方法について説明します。

前提条件

  • パートナー センターの認証に関するページで説明している資格情報。 このシナリオでは、Application+User 資格情報を使用した認証がサポートされています。

C#

セルフサービス ポリシーを作成します。

  1. セルフサービス ポリシー情報を使用して 、IAggregatePartner.SelfServePolicies.Create メソッドまたは IAggregatePartner.SelfServePolicies.CreateAsync メソッドを呼び出します。
// IAggregatePartner partnerOperations;
string customerIdAsEntity;

var selfServePolicy = new SelfServePolicy
{
    SelfServeEntity = new SelfServeEntity
    {
        SelfServeEntityType = "customer",
        TenantID = customerIdAsEntity,
    },
    Grantor = new Grantor
    {
        GrantorType = "billToPartner",
        TenantID = partnerIdAsGrantor,
    },
    Permissions = new Permission[]
    {
        new Permission
        {
        Action = "Purchase",
        Resource = "AzureReservedInstances",
        },
    },
    {
        new Permission
        {
        Action = "Purchase",
        Resource = "AzureSavingsPlan",
        },
    },
};

// All the operations executed on this partner operation instance will share the same correlation Id but will differ in request Id
IPartner scopedPartnerOperations = partnerOperations.With(RequestContextFactory.Instance.Create(Guid.NewGuid()));

// creates the self-serve policy
SelfServePolicy createdSelfServePolicy = scopedPartnerOperations.selfServePolicies.Create(selfServePolicy);

例については、次を参照してください。

REST 要求

要求の構文

認証方法 要求 URI
POST {baseURL}/v1/SelfServePolicy HTTP/1.1

要求ヘッダー

[要求本文]

次の表では、要求本文で必要なプロパティについて説明します。

名前 Type 説明
SelfServePolicy object セルフサービス ポリシー情報。

SelfServePolicy

次の表では、新しいセルフサービス ポリシーを作成するために必要な SelfServePolicy リソースの最小必須フィールドについて説明します。

プロパティ Type 説明
SelfServeEntity SelfServeEntity アクセス権が付与されているセルフサービス エンティティ。
Grantor Grantor アクセス権を付与している権限付与者。
アクセス許可 アクセス許可の配列 Permission リソースの配列。

要求の例

POST https://api.partnercenter.microsoft.com/v1/SelfServePolicy HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 94e4e214-6b06-4fb7-96d1-94d559f9b47f
MS-CorrelationId: ab993325-1605-4cf4-bac4-fb584142a31b
X-Locale: en-US
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 789
Expect: 100-continue
Connection: Keep-Alive

{
    "selfServeEntity": {
        "selfServeEntityType": "customer",
        "tenantID": "0431a72c-7d8a-4393-b25e-ef63f5efb415"
    },
    "grantor": {
        "grantorType": "billToPartner",
        "tenantID": "634f6379-ad54-449b-9821-564f737158ab"
    },
    "permissions": [
        {
            "resource": "AzureReservedInstances",
            "action": "Purchase"
        },
        {
            "resource": "AzureSavingsPlan",
            "action": "Purchase"
        }
    ]
}

REST 応答

成功した場合、この API は新しいセルフサービス ポリシーの SelfServePolicy リソースを返します。

応答の成功とエラーのコード

各応答には、成功または失敗を示す HTTP ステータス コードと、追加のデバッグ情報が付属しています。 このコード、エラーの種類、追加のパラメーターを読み取るには、ネットワーク トレース ツールを使用します。 完全な一覧については、パートナー センターの REST エラーコードに関する記事を参照してください。

このメソッドは、次のエラー コードを返します。

HTTP 状態コード エラー コード 説明
409 600041 セルフサービス ポリシーは既に存在します。

応答の例

HTTP/1.1 201 Created
Content-Length: 834
Content-Type: application/json; charset=utf-8
MS-CorrelationId: ab993325-1605-4cf4-bac4-fb584142a31b
MS-RequestId: 94e4e214-6b06-4fb7-96d1-94d559f9b47f
Date: Tue, 14 Feb 2017 20:06:02 GMT

{
    "id": "634f6379-ad54-449b-9821-564f737158ab_0431a72c-7d8a-4393-b25e-ef63f5efb415",
    "selfServeEntity": {
        "selfServeEntityType": "customer",
        "tenantID": "0431a72c-7d8a-4393-b25e-ef63f5efb415"
    },
    "grantor": {
        "grantorType": "billToPartner",
        "tenantID": "634f6379-ad54-449b-9821-564f737158ab"
    },
    "permissions": [
        {
            "resource": "AzureReservedInstances",
            "action": "Purchase"
        },
        {
            "resource": "AzureSavingsPlan",
            "action": "Purchase"
        }
    ],
    "attributes": {
        "etag": "\"933523d1-3f63-4fc3-8789-5e21c02cdaed\"",
        "objectType": "SelfServePolicy"
    }
}