It is possible to query license and activation information using the Software Potential Web API.
License and Activation Query API
The following methods are available to submit license queries to Software Potential:
- GetLicenseById
- GetLicenseByActivationKey
- GetLicensesByFilter
- GetCountOfLicensesByFilter
- GetLicenseSummariesByFilter
To retrieve Activations use
- Get ActivationsByFilter
At present, activations can only be queried on an individual license basis. It is not possible to retrieve all activations in a Software Potential account or all activations for a given Product Version.
See the API documentation on LicenseManagement interface.
Pagination
License and activation queries are paginated returning a default 100 records per page, and there is currently no way to override this deffault.
Query Filters
License Filter
Defines a number of search criteria which are used in license queries. The available filter properties are:
- ProductId - by product Id
- SKUId - by license SKU
- ExcludeTrial
- ExcludeCommercial
- IssueDateRange - by license issue date
- ActivationDateRange - by last activation date
- ExpirationDataRange - by expiration date
Filter properties may be combined to reduce the scope of a license query. For example if both an ExpirationDateRange and an ActivationDateRange are supplied ExpirationDates AND LatestSuccessfulActivationDates will be used to qualify the returned search values.
See the API documentation for more details LicenseFilter
ActivationFilter
Defines a number of search criterial to reduce the scope of an activations query. The available properties are:
- LicenseId - the ReferenceId of the license whose activations are being queried
See the API documentation for more details ActivationFilter
SKU Unique Identifier
The SKUs unique identifier SKUId can be used to recover all licenses issued from that SKU. The SKUId is displayed at the bottom of the SKU Details page or can also be retrieved via the Web API GetSkusByFilter
ProductId
Each product version has a unique product identified, that can be used to query licenses associated with a given product. Call GetProducts to get a list of products including product id, and from that identify the id of the relevant product
DateRange
Specifies a range of dates to be used when querying for licenses by issue, expiration or activation date. Its defined with a Start and an End date. The Start value can be set to System.DateTime.MinValue, in which case no constraint is placed on the starting date (all dates are included). The End value can be set to System.DateTime.MaxValue, in which case no constraint is placed on the ending date (all dates are included).
Retrieval Options
License Retrieval Options
To retrieve a basic license summary data without the license details set options to Basic; to retrieve the detailed license data set it to LicenseInfo. o retrieve both summary and details you will need to included both enums e.g. Basic || LicenseInfo
See LicenseRetrievalOptions for more details
Activation Retrieval Options
See ActivationRetrievalOptions for more details
Query License by Product
To query license issued within a given date range for a given product:
- Call
GetProductsto retrieve ProductId - Create a LicenseFilter and set the ProductId property.
- Call GetLicensesByFilter with the LicenseFilter
The following code snippet retrieves licenses issued in a given date range (StartDate, endDate) for a given product (productId):
....
LicenseFilter filter = new LicenseFilter();
filter.ProductId = productId;
filter.IssueDateRange = new DateRange();
filter.IssueDateRange.Start = startDate;
filter.IssueDateRange.End = endDate;
// Fetch all licenses across multiple pages
int currentPage = 0;
List<License> allLicenses = new List<License>();
while (currentPage >= 0)
{
var result = service.GetLicensesByFilterPaginated(filter, options, currentPage);
allLicenses.AddRange(result.Licenses);
currentPage = result.NextPageIndex;
}
// Or using HasMorePages:
var pagedResult = service.GetLicensesByFilterPaginated(filter, options, 0);
while (pagedResult.HasMorePages)
{
allLicenses.AddRange(pagedResult.Licenses);
pagedResult = service.GetLicensesByFilterPaginated(filter, options, pagedResult.NextPageIndex);
}
.....
.....
/// <summary>
/// Retrieves a single page of licenses matching the specified filter
/// </summary>
/// <param name="filter">License filter criteria (date ranges, product ID, etc.)</param>
/// <param name="options">Retrieval options (Basic, LicenseInfo, etc.)</param>
/// <param name="pageIndex">Current page index (use 0 for first page)</param>
/// <returns>Paged result containing licenses and pagination information</returns>
public PagedLicenseResult GetLicensesByFilterPaginated( LicenseFilter filter, LicenseRetrievalOptions options, int pageIndex )
{
return _api.Execute( client =>
{
var request = new GetLicensesByFilterRequest( filter, options, pageIndex );
var response = client.GetLicensesByFilter( request );
return new PagedLicenseResult
{
Licenses = response.GetLicensesByFilterResult.ToList(),
NextPageIndex = response.pageIndex
};
} );
}
You will need to implement the appropriate pagination logic in your application code.
It is also to simplify pagination when retrieve all licenses for a product as follows:
/// <summary>
/// Retrieves all licenses matching the specified filter
/// </summary>
/// <param name="filter">License filter criteria (date ranges, product ID, etc.)</param>
/// <param name="options">Retrieval options (Basic, LicenseInfo, etc.)</param>
/// <returns>List of licenses matching the filter</returns>
public List<License> GetLicensesByFilter( LicenseFilter filter, LicenseRetrievalOptions options )
{
return _api.Execute( client =>
{
List<License> licenses = new List<License>();
int pageIndex = 0;
var request = new GetLicensesByFilterRequest( filter, options, pageIndex );
while( pageIndex >= 0 )
{
request.pageIndex = pageIndex;
var response = client.GetLicensesByFilter( request );
licenses.AddRange( response.GetLicensesByFilterResult );
pageIndex = response.pageIndex;
}
return licenses;
} );
}
Query Activations By License
The following code snippet retrieves a page of activations for a given license (licenseId):
.....
ActivationFilter filter = new ActivationFilter();
filter.LicenseId = licenseId;
var retreivealOption = ActivationRetrievealOption.Basic
// Fetch all activations across multiple pages
int currentPage = 0;
List<Activations> allActivations = new List<Activations>();
while (currentPage >= 0)
{
var result = service.GetActivationsByFilterPaginated(filter, options, currentPage);
allActivations.AddRange(result.Activations);
currentPage = result.NextPageIndex;
}
// Or using HasMorePages:
var pagedResult = service.GetActivationsByFilterPaginated(filter, options, 0);
while (pagedResult.HasMorePages)
{
allActivations.AddRange(pagedResult.Activations);
pagedResult = service.GetActivationsByFilterPaginated(filter, options, pagedResult.NextPageIndex);
}
....
....
/// <summary>
/// Retrieves a single page of activations matching the specified filter
/// </summary>
/// <param name="filter">Activation filter criteria (license ID, etc.)</param>
/// <param name="options">Retrieval options (Basic, etc.)</param>
/// <param name="pageIndex">Current page index (use 0 for first page)</param>
/// <returns>Paged result containing activations and pagination information</returns>
public PagedActivationResult GetActivationsByFilterPaginated( ActivationFilter filter, ActivationRetrievalOptions options, int pageIndex )
{
return _api.Execute( client =>
{
var request = new GetActivationsByFilterRequest( filter, options, pageIndex );
var response = client.GetActivationsByFilter( request );
return new PagedActivationResult
{
Activations = response.GetActivationsByFilterResult.ToList(),
NextPageIndex = response.pageIndex
};
} );
}
Comments
0 comments
Please sign in to leave a comment.