Get a list of customers filtered by a search field

Applies to: Partner Center | Partner Center operated by 21Vianet | Partner Center for Microsoft Cloud for US Government

Gets a collection of Customer resources that match a filter. You can optionally set a page size. You can filter by company name, domain, indirect reseller, or indirect cloud solution provider (CSP).

Prerequisites

  • Credentials as described in Partner Center authentication. This scenario supports authentication with both standalone App and App+User credentials.

  • A user-constructed filter.

C#

To get a collection of customers that match a filter, first instantiate a SimpleFieldFilter object to create the filter. You'll need to pass a string that contains the CustomerSearchField, and indicate the type of filter operation as FieldFilterOperation.StartsWith. That's the only field filter operation supported by the customers end point. You'll also need to provide the string to filter by.

Next, instantiate an iQuery object to pass to the query by calling the BuildSimpleQuery method and passing it the filter. BuildSimplyQuery is just one of the query types supported by the QueryFactory class.

Finally, to execute the filter and get the result, first use IAggregatePartner.Customers to get an interface to the partner's customer operations. Then call the Query or QueryAsync method.

IAggregatePartner partnerOperations;

// Specify the partial string to filter by (to match Contoso).
string searchPrefix = "cont"

// Create a simple field filter.
var fieldFilter = new SimpleFieldFilter(
    CustomerSearchField.CompanyName.ToString(),
    FieldFilterOperation.StartsWith,
    searchPrefix);

// Create an iQuery object to pass to the Query method.
var myQuery = QueryFactory.Instance.BuildSimpleQuery(fieldFilter);

// Get the collection of matching customers.
var customers = partnerOperations.Customers.Query(myQuery);

Sample: Console test app. Project: Partner Center SDK Samples Class: FilterCustomers.cs

REST request

Request syntax

Method Request URI
GET {baseURL}/v1/customers?size={size}&filter={filter} HTTP/1.1

URI parameters

Use the following query parameters.

Name Type Required Description
size int No The number of results to be displayed at one time. This parameter is optional.
filter filter Yes The filter to apply to customers. This must be an encoded string.

Filter Syntax

You must compose the filter parameter as a series of comma separated, key-value pairs. Each key and value must be individually quoted and separated by a colon. The entire filter must be encoded.

An unencoded example looks like this:

?filter{"Field":"CompanyName","Value":"cont","Operator":"starts_with"}

The following table describes the required key-value pairs:

Key Value
Field The field to filter. The valid values can be found in CustomerSearchField.
Value The value to filter by. The case of the value is ignored.
Operator The operator to apply. The only supported value for this customer scenario is "starts_with".

Request headers

For more information, see Partner Center REST headers.

Request body

None.

Request example

GET https://api.partnercenter.microsoft.com/v1/customers?size=0&filter=%7B%22Field%22%3A%22CompanyName%22%2C%22Value%22%3A%22Cont%22%2C%22Operator%22%3A%22starts_with%22%7D HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 5ce66de5-eea9-486f-a11c-c852aa3d1502
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
Host: api.partnercenter.microsoft.com
Connection: Keep-Alive

REST response

If successful, this method returns a collection of matching Customer resources in the response body.

Response success and error codes

Each response comes with an HTTP status code that indicates success or failure and additional debugging information. Use a network trace tool to read this code, error type, and additional parameters. For the full list, see Partner Center REST error codes.

Response example

HTTP/1.1 200 OK
Content-Length: 1839
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: dfeda56c-1af5-43fc-a9c0-346b9e85dc96
MS-CV: n0lMNyJtaUC802pO.0
MS-ServerId: 202010223
Date: Fri, 24 Feb 2017 22:08:20 GMT

{
    "totalCount": 3,
    "items": [{
            "id": "aaaabbbb-0000-cccc-1111-dddd2222eeee",
            "companyProfile": {
                "tenantId": "aaaabbbb-0000-cccc-1111-dddd2222eeee",
                "domain": "contoso190.onmicrosoft.com",
                "companyName": "Contoso190",
                "links": {
                    "self": {
                        "uri": "/customers/aaaabbbb-0000-cccc-1111-dddd2222eeee/profiles/company",
                        "method": "GET",
                        "headers": []
                    }
                },
                "attributes": {
                    "objectType": "CustomerCompanyProfile"
                }
            },
            "relationshipToPartner": "reseller",
            "links": {
                "self": {
                    "uri": "/customers/aaaabbbb-0000-cccc-1111-dddd2222eeee",
                    "method": "GET",
                    "headers": []
                }
            },
            "attributes": {
                "objectType": "Customer"
            }
        }, {
            "id": "bbbbcccc-1111-dddd-2222-eeee3333ffff",
            "companyProfile": {
                "tenantId": "bbbbcccc-1111-dddd-2222-eeee3333ffff",
                "domain": "ContosoCorpCo.onmicrosoft.com",
                "companyName": "Contoso",
                "links": {
                    "self": {
                        "uri": "/customers/bbbbcccc-1111-dddd-2222-eeee3333ffff/profiles/company",
                        "method": "GET",
                        "headers": []
                    }
                },
                "attributes": {
                    "objectType": "CustomerCompanyProfile"
                }
            },
            "relationshipToPartner": "reseller",
            "links": {
                "self": {
                    "uri": "/customers/bbbbcccc-1111-dddd-2222-eeee3333ffff",
                    "method": "GET",
                    "headers": []
                }
            },
            "attributes": {
                "objectType": "Customer"
            }
        }, {
            "id": "ccccdddd-2222-eeee-3333-ffff4444aaaa",
            "companyProfile": {
                "tenantId": "ccccdddd-2222-eeee-3333-ffff4444aaaa",
                "domain": "contosocorpdemo.onmicrosoft.com",
                "companyName": "Contoso",
                "links": {
                    "self": {
                        "uri": "/customers/ccccdddd-2222-eeee-3333-ffff4444aaaa/profiles/company",
                        "method": "GET",
                        "headers": []
                    }
                },
                "attributes": {
                    "objectType": "CustomerCompanyProfile"
                }
            },
            "relationshipToPartner": "reseller",
            "links": {
                "self": {
                    "uri": "/customers/ccccdddd-2222-eeee-3333-ffff4444aaaa",
                    "method": "GET",
                    "headers": []
                }
            },
            "attributes": {
                "objectType": "Customer"
            }
        }
    ],
    "links": {
        "self": {
            "uri": "/customers?size=0&filter=%7B%22Field%22%3A%22Domain%22%2C%22Value%22%3A%22cont%22%2C%22Operator%22%3A%22starts_with%22%7D",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Collection"
    }
}