Delen via


Een SelfServePolicy maken

In dit artikel wordt uitgelegd hoe u een nieuw beleid voor zelfbediening maakt.

Vereisten

  • Referenties zoals beschreven in Partnercentrum-verificatie. Dit scenario ondersteunt verificatie met Application+User-referenties.

C#

Een selfservicebeleid maken:

  1. Roep de methode IAggregatePartner.SelfServePolicies.Create of IAggregatePartner.SelfServePolicies.CreateAsync aan met de beleidsinformatie voor selfservice.
// 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);

Zie het volgende voor een voorbeeld:

  • Voorbeeld: Consoletest-app
  • Project: PartnerSDk.featureSamples
  • Klasse: CreateSelfServePolicies.cs

REST-aanvraag

Aanvraagsyntaxis

Methode Aanvraag-URI
VERZENDEN {baseURL}/v1/SelfServePolicy HTTP/1.1

Aanvraagheaders

Aanvraagbody

In deze tabel worden de vereiste eigenschappen in de aanvraagbody beschreven.

Naam Type Beschrijving
SelfServePolicy object De beleidsinformatie voor selfservice.

SelfServePolicy

In deze tabel worden de minimaal vereiste velden van de SelfServePolicy-resource beschreven die nodig zijn om een nieuw selfservicebeleid te maken.

Eigenschap Type Beschrijving
SelfServeEntity SelfServeEntity De selfservice-entiteit die toegang krijgt.
Grantor Grantor De schenker die toegang verleent.
Machtigingen Matrix van machtigingen Een matrix met machtigingsresources .

Voorbeeld van aanvraag

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

Als dit lukt, retourneert deze API een SelfServePolicy-resource voor het nieuwe selfservicebeleid.

Geslaagde respons- en foutcodes

Elk antwoord wordt geleverd met een HTTP-statuscode die een geslaagde of mislukte status aangeeft en aanvullende informatie over foutopsporing. Gebruik een hulpprogramma voor netwerktracering om deze code, het fouttype en aanvullende parameters te lezen. Zie Partner Center REST-foutcodes voor de volledige lijst.

Deze methode retourneert de volgende foutcodes:

HTTP-statuscode Foutcode Beschrijving
409 600041 Selfservicebeleid bestaat al.

Voorbeeld van antwoord

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