Get a record of Partner Center activity
Applies to: Partner Center | Partner Center for Microsoft Cloud for US Government
This article describes how to retrieve a record of operations that was performed by a partner user or application over a period of time.
Use this API to retrieve audit records for the previous 30 days from the current date, or for a date range specified by including the start date and/or the end date. Note, however, that for performance reasons activity log data availability is limited to the previous 90 days. Requests with a start date greater than 90 days prior to the current date will receive a bad request exception (error code: 400) and an appropriate message.
Prerequisites
- Credentials as described in Partner Center authentication. This scenario supports authentication with both standalone App and App+User credentials.
C#
To retrieve a record of Partner Center operations, first establish the date range for the records you want to retrieve. The following code example only uses a start date, but you can also include an end date. For more information, see the Query method. Next, create the variables you need for the type of filter you want to apply, and assign the appropriate values. For example, to filter by company name substring, create a variable to hold the substring. To filter by customer ID, create a variable to hold the ID.
In the following example, sample code is provided to filter by a company name substring, customer ID, or resource type. Choose one and comment out the others. In each case, you first instantiate a SimpleFieldFilter object using its default constructor to create the filter. You'll need to pass a string that contains the field to search, and the appropriate operator to apply, as shown. You also must provide the string to filter by.
Next, use the AuditRecords property to get an interface to audit record operations, and call the Query or QueryAsync method to execute the filter and get the collection of AuditRecord's that represent the first page of the result. Pass the method the start date, an optional end date not used in the example here, and an IQuery object that represents a query on an entity. The IQuery object is created by passing the filter created above to the QueryFactory's BuildSimpleQuery method.
Once you have the initial page of items, use the Enumerators.AuditRecords.Create method to create an enumerator that you can use to iterate through the remaining pages.
// IAggregatePartner partnerOperations;
var startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01);
// First perform the query, then get the enumerator. Choose one of the following and comment out the other two.
// To retrieve audit records by company name substring (for example "bri" matches "Fabrikam, Inc.").
var searchSubstring="bri";
var filter = new SimpleFieldFilter(AuditRecordSearchField.CompanyName.ToString(), FieldFilterOperation.Substring, searchSubstring);
var auditRecordsPage = partnerOperations.AuditRecords.Query(startDate.Date, query: QueryFactory.Instance.BuildSimpleQuery(filter));
// To retrieve audit records by customer ID.
var customerId="bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f";
var filter = new SimpleFieldFilter(AuditRecordSearchField.CustomerId.ToString(), FieldFilterOperation.Equals, customerId);
var auditRecordsPage = partnerOperations.AuditRecords.Query(startDate.Date, query: QueryFactory.Instance.BuildSimpleQuery(filter));
// To retrieve audit records by resource type.
int resourceTypeInt = 3; // Subscription Resource.
string searchField = Enum.GetName(typeof(ResourceType), resourceTypeInt);
var filter = new SimpleFieldFilter(AuditRecordSearchField.ResourceType.ToString(), FieldFilterOperation.Equals, searchField);
var auditRecordsPage = partnerOperations.AuditRecords.Query(startDate.Date, query: QueryFactory.Instance.BuildSimpleQuery(filter));
var auditRecordEnumerator = partnerOperations.Enumerators.AuditRecords.Create(auditRecordsPage);
int pageNumber = 1;
while (auditRecordEnumerator.HasValue)
{
// Work with the current page.
foreach (var c in auditRecordEnumerator.Current.Items)
{
// Display some info, such as operation type, operation date, and operation status.
Console.WriteLine(string.Format("{0} {1} {2}.", c.OperationType, c.OperationDate, c.OperationStatus));
}
// Get the next page of audit records.
auditRecordEnumerator.Next();
}
Sample: Console test app. Project: Partner Center SDK Samples Folder: Auditing
REST request
Request syntax
Method | Request URI |
---|---|
GET | {baseURL}/v1/auditrecords?startDate={startDate} HTTP/1.1 |
GET | {baseURL}/v1/auditrecords?startDate={startDate}&endDate={endDate} HTTP/1.1 |
GET | {baseURL}/v1/auditrecords?startDate={startDate}&endDate={endDate}&filter={"Field":"CompanyName","Value":"{searchSubstring}","Operator":"substring"} HTTP/1.1 |
GET | {baseURL}/v1/auditrecords?startDate={startDate}&endDate={endDate}&filter={"Field":"CustomerId","Value":"{customerId}","Operator":"equals"} HTTP/1.1 |
GET | {baseURL}/v1/auditrecords?startDate={startDate}&endDate={endDate}&filter={"Field":"ResourceType","Value":"{resourceType}","Operator":"equals"} HTTP/1.1 |
URI parameter
Use the following query parameters when creating the request.
Name | Type | Required | Description |
---|---|---|---|
startDate | date | No | The start date in yyyy-mm-dd format. If none is provided, the result set will default to 30 days prior to the request date. This parameter is optional when a filter is supplied. |
endDate | date | No | The end date in yyyy-mm-dd format. This parameter is optional when a filter is supplied. When the end date is omitted or set to null, the request returns the max window or uses today as the end date, whichever is less. |
filter | string | No | The filter to apply. This parameter must be an encoded string. This parameter is optional when the start date or end date are supplied. |
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":"bri","Operator":"substring"}
The following table describes the required key-value pairs:
Key | Value |
---|---|
Field | The field to filter. The supported values can be found in Request syntax. |
Value | The value to filter by. The case of the value is ignored. The following value parameters are supported as shown in Request syntax: searchSubstring - Replace with the name of the company. You can enter a substring to match part of the company name (for example, bri will match Fabrikam, Inc ).Example: "Value":"bri" customerId - Replace with a GUID formatted string that represents the customer identifier. Example: "Value":"bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f" resourceType - Replace with the type of resource for which to retrieve audit records (for example, Subscription). The available resource types are defined in ResourceType. Example: "Value":"Subscription" |
Operator | The operator to apply. The supported operators can be found in Request syntax. |
Request headers
- For more information, see Parter Center REST headers.
Request body
None.
Request example
GET https://api.partnercenter.microsoft.com/v1/auditrecords?startDate=6/1/2017%2012:00:00%20AM&filter=%7B%22Field%22:%22CustomerId%22,%22Value%22:%220c39d6d5-c70d-4c55-bc02-f620844f3fd1%22,%22Operator%22:%22equals%22%7D HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 127facaa-e389-41f8-8bb7-1d1af99db893
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 set of activities that meet the filters.
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: 2859
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: 127facaa-e389-41f8-8bb7-1d1af99db893
MS-CV: 4xDKynq/zE2im0wj.0
MS-ServerId: 030011719
Date: Tue, 27 Jun 2017 22:19:46 GMT
{
"totalCount": 2,
"items": [{
"partnerId": "aaaabbbb-0000-cccc-1111-dddd2222eeee",
"customerId": "bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f",
"customerName": "Relecloud",
"userPrincipalName": "admin@domain.onmicrosoft.com",
"resourceType": "order",
"resourceNewValue": "{\"Id\":\"cccc2c2c-dd3d-ee4e-ff5f-aaaaaa6a6a6a\",\"ReferenceCustomerId\":\"bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f\",\"BillingCycle\":\"none\",\"LineItems\":[{\"LineItemNumber\":0,\"OfferId\":\"C0BD2E08-11AC-4836-BDC7-3712E744922F\",\"SubscriptionId\":\"aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e\",\"ParentSubscriptionId\":null,\"FriendlyName\":\"Office 365 Business Premium Trial\",\"Quantity\":25,\"PartnerIdOnRecord\":null,\"Links\":{\"Subscription\":{\"Uri\":\"/customers/bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e\",\"Method\":\"GET\",\"Headers\":[]}}}],\"CreationDate\":\"2017-06-15T15:56:04.077-07:00\",\"Links\":{\"Self\":{\"Uri\":\"/customers/bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f/orders/cccc2c2c-dd3d-ee4e-ff5f-aaaaaa6a6a6a\",\"Method\":\"GET\",\"Headers\":[]}},\"Attributes\":{\"Etag\":\"eyJpZCI6ImQ1MWEwNTJlLTA0M2MtNGEyYS1hYTM3LTJiYjkzOGNlZjZjMSIsInZlcnNpb24iOjF9\",\"ObjectType\":\"Order\"}}",
"operationType": "create_order",
"operationDate": "2017-06-15T22:56:05.0589308Z",
"operationStatus": "succeeded",
"customizedData": [{
"key": "OrderId",
"value": "cccc2c2c-dd3d-ee4e-ff5f-aaaaaa6a6a6a"
}, {
"key": "BillingCycle",
"value": "None"
}, {
"key": "OfferId-0",
"value": "C0BD2E08-11AC-4836-BDC7-3712E744922F"
}, {
"key": "SubscriptionId-0",
"value": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e"
}, {
"key": "SubscriptionName-0",
"value": "Office 365 Business Premium Trial"
}, {
"key": "Quantity-0",
"value": "25"
}, {
"key": "PartnerOnRecord-0",
"value": null
}
],
"attributes": {
"objectType": "AuditRecord"
}
}, {
"partnerId": "aaaabbbb-0000-cccc-1111-dddd2222eeee",
"customerId": "bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f",
"customerName": "Relecloud",
"userPrincipalName": "admin@domain.onmicrosoft.com",
"applicationId": "Partner Center Native App",
"resourceType": "license",
"resourceNewValue": "{\"LicensesToAssign\":[{\"ExcludedPlans\":null,\"SkuId\":\"efccb6f7-5641-4e0e-bd10-b4976e1bf68e\"}],\"LicensesToRemove\":null,\"LicenseWarnings\":[],\"Attributes\":{\"ObjectType\":\"LicenseUpdate\"}}",
"operationType": "update_customer_user_licenses",
"operationDate": "2017-06-01T20:09:07.0450483Z",
"operationStatus": "succeeded",
"customizedData": [{
"key": "CustomerUserId",
"value": "482e2152-4b49-48ec-b715-823365ce3d4c"
}, {
"key": "AddedLicenseSkuId",
"value": "efccb6f7-5641-4e0e-bd10-b4976e1bf68e"
}
],
"attributes": {
"objectType": "AuditRecord"
}
}
],
"links": {
"self": {
"uri": "/auditrecords?startDate=2017-06-01&size=500&filter=%7B%22Field%22%3A%22CustomerId%22%2C%22Value%22%3A%220c39d6d5-c70d-4c55-bc02-f620844f3fd1%22%2C%22Operator%22%3A%22equals%22%7D",
"method": "GET",
"headers": []
}
},
"attributes": {
"objectType": "Collection"
}
}