获取客户列表

适用于:合作伙伴中心 | 由世纪互联运营的合作伙伴中心 | Microsoft Cloud for US Government 合作伙伴中心

本文介绍如何获取代表合作伙伴所有客户的资源集合。

提示

还可以在合作伙伴中心执行此操作。 在主页上,选择“ 客户 ”工作区,然后使用菜单中的“ 客户”列表查看客户

必备条件

C#

获取所有客户的列表:

  1. 使用 IAggregatePartner.Customers 集合创建 IPartner 对象。

  2. 使用 Query () QueryAsync () 方法检索客户列表。 (有关创建查询的说明,请参阅 QueryFactory class.)

// IAggregatePartner partnerOperations;

// 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()));

// read customers into chunks of 40s
var customersBatch = scopedPartnerOperations.Customers.Query(QueryFactory.Instance.BuildIndexedQuery(40));
var customersEnumerator = scopedPartnerOperations.Enumerators.Customers.Create(customersBatch);

有关示例,请参阅以下内容:

Java

合作伙伴中心 Java SDK 可用于管理合作伙伴中心资源。 这是一个开源项目,由合作伙伴社区维护,不受 Microsoft 正式支持。 如果遇到问题,可以从社区获取帮助在 GitHub 上创建问题

获取所有客户的列表:

  1. 使用 [IAggregatePartner.getCustomers] 函数获取对客户操作的引用。

  2. 使用 query () 函数检索客户列表。

// Query the customers, get the first page if a page size was set, otherwise get all customers
SeekBasedResourceCollection<Customer> customersPage = partnerOperations.getCustomers().query(QueryFactory.getInstance().buildIndexedQuery(40));

// Create a customer enumerator which will aid us in traversing the customer pages
IResourceCollectionEnumerator<SeekBasedResourceCollection<Customer>> customersEnumerator =
    partnerOperations.getEnumerators().getCustomers().create( customersPage );

int pageNumber = 1;

while (customersEnumerator.hasValue())
{
    /*
     * Use the customersEnumerator.getCurrent() function to
     * access the current page of customers.
     */

    // Get the next page of customers
    customersEnumerator.next();
}

PowerShell

合作伙伴中心 PowerShell 模块可用于管理合作伙伴中心资源。 这是一个开源项目,由合作伙伴社区维护,不受 Microsoft 正式支持。 如果遇到问题,可以从社区获取帮助在 GitHub 上创建问题

执行不带参数的 Get-PartnerCustomer 命令以获取客户的完整列表。

Get-PartnerCustomer

REST 请求

请求语法

方法 请求 URI
GET {baseURL}/v1/customers?size={size} HTTP/1.1

URI 参数

使用以下查询参数获取客户列表。

名称 类型 必须 说明
size int Y 一次要显示的结果数。

请求标头

有关详细信息,请参阅合作伙伴中心 REST 标头

请求正文

无。

请求示例

GET https://api.partnercenter.microsoft.com/v1/customers?size=40 HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 3705fc6d-4127-4a87-bdba-9658f73fe019
MS-CorrelationId: b12260fb-82de-4701-a25f-dcd367690645

REST 响应

如果成功,此方法在响应正文中返回 Customer 资源的集合。

响应的成功和错误代码

每个响应都带有一个 HTTP 状态代码,用于指示成功或失败以及其他调试信息。 请使用网络跟踪工具来读取此代码、错误类型和其他参数。 有关完整列表,请参阅 错误代码

响应示例

HTTP/1.1 200 OK
Content-Length: 15650
Content-Type: application/json
MS-CorrelationId: b12260fb-82de-4701-a25f-dcd367690645
MS-RequestId: 3705fc6d-4127-4a87-bdba-9658f73fe019
Date: Fri, 20 Nov 2015 01:08:23 GMT

{
    "totalCount": 2,
    "items": [{
        "id": "b44bb1fb-c595-45b0-9e09-d657365580bf",
        "companyProfile": {
            "tenantId": "<guid>",
            "domain": "domain",
            "companyName": "companyName",
            "attributes": {
                "objectType": "CustomerCompanyProfile"
            }
        },
        "relationshipToPartner": "reseller",
        "attributes": {
            "objectType": "Customer"
        }
    },
    {
        "id": "45c44870-ef77-4fdd-b6fe-3dacb075cff2",
        "companyProfile": {
            "tenantId": "<guid>",
            "domain": "domain",
            "companyName": "companyName",
            "attributes": {
                "objectType": "CustomerCompanyProfile"
            }
        },
        "relationshipToPartner": "reseller",
        "attributes": {
            "objectType": "Customer"
        }
    }],
    "links": {
        "self": {
            "uri": "/v1/customers?size=40",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Collection"
    }
}