Erstellen einer SelfServePolicy

In diesem Artikel wird erläutert, wie Sie eine neue Selbstbedienungsrichtlinie erstellen.

Voraussetzungen

  • Anmeldeinformationen, wie unter Partner Center-Authentifizierung beschrieben. Dieses Szenario unterstützt die Authentifizierung mit Anwendungs- und Benutzeranmeldeinformationen.

C#

Erstellen Sie eine Self-Service-Richtlinie:

  1. Rufen Sie die IAggregatePartner.SelfServePolicies.Create - oder IAggregatePartner.SelfServePolicies.CreateAsync-Methode mit den Informationen zur Self-Serve-Richtlinie auf.
// 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);

Ein Beispiel finden Sie im Folgenden:

  • „Beispiel: Konsolentest der App
  • Projekt: PartnerSDK.FeatureSamples
  • Klasse: CreateSelfServePolicies.cs

REST-Anforderung

Anforderungssyntax

Methode Anforderungs-URI
POST {baseURL}/v1/SelfServePolicy HTTP/1.1

Anforderungsheader

  • Eine Anforderungs-ID und eine Korrelations-ID sind erforderlich.
  • Weitere Informationen finden Sie unter Partner Center-REST-Header.

Anforderungstext

In dieser Tabelle werden die erforderlichen Eigenschaften im Anforderungstext beschrieben.

Name Typ BESCHREIBUNG
SelfServePolicy Objekt (object) Die Self-Service-Richtlinieninformationen.

SelfServePolicy

In dieser Tabelle werden die mindestens erforderlichen Felder aus der SelfServePolicy-Ressource beschrieben, die zum Erstellen einer neuen Self-Serve-Richtlinie erforderlich sind.

Eigenschaft Typ BESCHREIBUNG
SelfServeEntity SelfServeEntity Die Selbstbedienungsentität, der Zugriff gewährt wird.
Grantor Grantor Der Empfänger, der Zugriff gewährt.
Berechtigungen Ein Array von Permission Ein Array von Berechtigungsressourcen .

Anforderungsbeispiel

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-Antwort

Bei erfolgreicher Ausführung gibt diese API eine SelfServePolicy-Ressource für die neue Self-Serve-Richtlinie zurück.

Erfolgs- und Fehlercodes der Antwort

Jede Antwort enthält einen HTTP-Statuscode, der Aufschluss darüber gibt, ob der Vorgang erfolgreich war, sowie ggf. zusätzliche Debuginformationen. Verwende ein Tool für die Netzwerkablaufverfolgung, um diesen Code, den Fehlertyp und zusätzliche Parameter zu lesen. Die vollständige Liste finden Sie unter Partner Center-REST-Fehlercodes.

Diese Methode gibt die folgenden Fehlercodes zurück:

HTTP-Statuscode Fehlercode BESCHREIBUNG
409 600041 Die Self-Service-Richtlinie ist bereits vorhanden.

Antwortbeispiel

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"
    }
}