为间接经销商的客户创建订单
如何为间接经销商的客户创建订单。
先决条件
合作伙伴中心身份验证中所述的凭据。 此方案只支持使用应用凭据和用户凭据进行身份验证。
客户 ID (
customer-tenant-id
)。 如果不知道客户的 ID,可以通过选择“客户”工作区,然后从客户列表中选择客户,然后选择“帐户”,在合作伙伴中心中查找该 ID。 在客户的“帐户”页上,在“客户帐户信息”部分查找 Microsoft ID。 Microsoft ID 与客户 ID (customer-tenant-id
) 相同。要购买的项目的产品/服务标识符。
间接经销商的租户标识符。
C#
为间接经销商的客户创建订单:
获取与登录的合作伙伴建立了关系的间接经销商的集合。
获取集合中与间接经销商 ID 匹配的项的局部变量。 此步骤有助于在创建订单时访问经销商的 MpnId 属性。
创建 OrderLineItem 对象列表,并将该列表分配给订单的 LineItems 属性。 每个订单明细项目都包含一种套餐的购买信息。 请务必使用间接经销商的 PartnerID 填充 每个行项中的 PartnerIdOnRecord 属性。 必须具有至少一个订单明细项目。
通过使用客户 ID 调用 IAggregatePartner.Customers.ById 方法来获取订单操作的接口,然后从 Orders 属性检索接口。
调用 Create 或 CreateAsync 方法以创建订单。
C# 示例
// IAggregatePartner partnerOperations;
// string customerId;
// string offerId;
// string indirectResellerId;
// Get the indirect resellers with a relationship to the signed-in partner.
var indirectResellers = partnerOperations.Relationships.Get(PartnerRelationshipType.IsIndirectCloudSolutionProviderOf);
// Find the matching reseller in the collection.
var selectedIndirectReseller = (indirectResellers != null && indirectResellers.Items.Any()) ?
indirectResellers.Items.FirstOrDefault(reseller => reseller.Id.Equals(indirectResellerId, StringComparison.OrdinalIgnoreCase)) :
null;
// Prepare the order and populate the PartnerIdOnRecord with the reseller's Partner Id.
var order = new Order()
{
ReferenceCustomerId = customerId,
LineItems = new List<OrderLineItem>()
{
new OrderLineItem()
{
OfferId = offerId,
FriendlyName = "New offer purchase.",
Quantity = 5,
PartnerIdOnRecord = selectedIndirectReseller != null ? selectedIndirectReseller.MpnId : null
}
}
};
// Place the order.
var createdOrder = partnerOperations.Customers.ById(customerId).Orders.Create(order);
示例: 控制台测试应用项目:合作伙伴中心 SDK 示例 类:PlaceOrderForCustomer.cs
REST 请求
请求语法
方法 | 请求 URI |
---|---|
POST | {baseURL}/v1/customers/{customer-id}/orders HTTP/1.1 |
URI 参数
请使用以下路径参数来标识客户。
名称 | 类型 | 必需 | 说明 |
---|---|---|---|
customer-id | string | 是 | 标识客户的 GUID 格式字符串。 |
请求标头
有关详细信息,请参阅合作伙伴中心 REST 标头。
请求正文
下单(O)
下表描述了 请求正文中的 Order 属性。
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
id | string | 否 | 成功创建订单时提供的订单标识符。 |
referenceCustomerId | string | 是 | 客户标识符。 |
billingCycle | string | 否 | 针对此订单向合作伙伴收费的频率。 默认值为“Monthly”,在成功创建订单时应用。 支持的值是在 BillingCycleType 中找到的成员名称。 注意:年度计费功能尚未正式发布。 很快将支持按年计费。 |
lineItems | 对象数组 | 是 | OrderLineItem 资源的数组。 |
creationDate | string | 否 | 订单的创建日期,格式为日期-时间。 成功创建订单时应用。 |
attributes | object | 否 | 包含“ObjectType”:“Order” |
OrderLineItem
下表描述了 请求正文中的 OrderLineItem 属性。
名称 | 类型 | 必需 | 说明 |
---|---|---|---|
lineItemNumber | int | 是 | 集合中的每个明细项目都将获得一个唯一的行号,行号的范围为从 0 到 count-1。 |
offerId | string | 是 | 套餐标识符。 |
subscriptionId | string | 否 | 订阅标识符。 |
parentSubscriptionId | string | 否 | 可选。 附加产品套餐中的父订阅的 ID。 仅适用于 PATCH。 |
friendlyName | string | 否 | 可选。 合作伙伴定义的订阅的友好名称,以帮助消除歧义。 |
quantity | int | 是 | 基于许可证的订阅的许可证数量。 |
partnerIdOnRecord | string | 否 | 当间接提供商代表间接经销商下订单时,仅使用间接经销商的 PartnerID 填充此字段(从不为间接提供商的 ID)。 这可以确保正确地针对奖励进行记账。 未能提供经销商 PartnerID 不会导致订单失败。 但是,经销商不会记录,因此奖励计算可能不包括销售。 |
attributes | object | 否 | 包含“ObjectType”:“OrderLineItem”。 |
请求示例
POST https://api.partnercenter.microsoft.com/v1/customers/c501c3c4-d776-40ef-9ecf-9cefb59442c1/orders HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 02109f46-3ff2-4be4-9f37-b2eb6d58d542
MS-CorrelationId: 85195ae6-3de5-4978-abd4-7be2fbfe4c84
X-Locale: en-US
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 410
Expect: 100-continue
{
"Id": null,
"ReferenceCustomerId": "c501c3c4-d776-40ef-9ecf-9cefb59442c1",
"BillingCycle": "unknown",
"LineItems": [{
"LineItemNumber": 0,
"OfferId": "DB2E705F-B82A-4024-A3D5-D88E12F2DB35",
"SubscriptionId": null,
"ParentSubscriptionId": null,
"FriendlyName": "New offer purchase.",
"Quantity": 5,
"PartnerIdOnRecord": "4847383",
"Attributes": {
"ObjectType": "OrderLineItem"
}
}
],
"CreationDate": null,
"Attributes": {
"ObjectType": "Order"
}
}
REST 响应
如果成功,响应正文将包含填充的 Order 资源。
响应的成功和错误代码
每个响应都带有一个 HTTP 状态代码,用于指示成功或失败以及其他调试信息。 请使用网络跟踪工具来读取此代码、错误类型和其他参数。 有关完整列表,请参阅 合作伙伴中心错误代码。
响应示例
HTTP/1.1 201 Created
Content-Length: 831
Content-Type: application/json; charset=utf-8
MS-CorrelationId: 85195ae6-3de5-4978-abd4-7be2fbfe4c84
MS-RequestId: 02109f46-3ff2-4be4-9f37-b2eb6d58d542
MS-CV: Nd3Oum/L5EywtKQK.0
MS-ServerId: 020021921
Date: Mon, 10 Apr 2017 23:02:24 GMT
{
"id": "3eddcac6-63b2-4c40-b0b6-f47e18301492",
"referenceCustomerId": "c501c3c4-d776-40ef-9ecf-9cefb59442c1",
"billingCycle": "monthly",
"lineItems": [{
"lineItemNumber": 0,
"offerId": "DB2E705F-B82A-4024-A3D5-D88E12F2DB35",
"subscriptionId": "42226ED6-070A-4E0F-B80C-4CDFB3E97AA7",
"friendlyName": "New offer purchase.",
"quantity": 5,
"partnerIdOnRecord": "4847383",
"links": {
"subscription": {
"uri": "/customers/c501c3c4-d776-40ef-9ecf-9cefb59442c1/subscriptions/42226ED6-070A-4E0F-B80C-4CDFB3E97AA7",
"method": "GET",
"headers": []
}
}
}
],
"creationDate": "2017-04-10T16:02:25.983-07:00",
"links": {
"self": {
"uri": "/customers/c501c3c4-d776-40ef-9ecf-9cefb59442c1/orders/3eddcac6-63b2-4c40-b0b6-f47e18301492",
"method": "GET",
"headers": []
}
},
"attributes": {
"etag": "eyJpZCI6IjNlZGRjYWM2LTYzYjItNGM0MC1iMGI2LWY0N2UxODMwMTQ5MiIsInZlcnNpb24iOjF9",
"objectType": "Order"
}
}
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈