Reading Content Types

Reading Content Types

Using the Administration API in combination with master key authentication you can read individual or multiple content type objects from your code.

Read All Content Types

You can use either the App ID or the Project ID to get all content types of an application. Here is code using the App ID. To use the Project ID, simply substitute it for the App ID in the code.

public async Task<IEnumerable<ContentType>> GetContentTypes(Guid applicationId, string masterKey)
{
    var metadata = new EverliveAccount(new EverliveAccountSettings(AuthorizationStrategy.MasterKey, masterKey));
    return await metadata.WorkWith().Application(your-app-id).Types().GetAll().ExecuteAsync();
}

Read a Content Type by ID

To get content type info by id use the following code.

public async Task<ContentType> GetContentTypeById(Guid applicationId, Guid contentTypeId, string masterKey)
{
    var metadata = new EverliveAccount(new EverliveAccountSettings(AuthorizationStrategy.MasterKey, masterKey));
    return await metadata.WorkWith().Application(applicationId).Types().GetById(contentTypeId).ExecuteAsync();
}

Read a Content Type by Name

You can also get the content type info by name.

public async Task<ContentType> GetContentTypeByName(Guid applicationId, string contentTypeName, string masterKey)
{
    var metadata = new EverliveAccount(new EverliveAccountSettings(AuthorizationStrategy.MasterKey, masterKey));
    return await metadata.WorkWith().Application(applicationId).Types().GetByName(contentTypeName).ExecuteAsync();
}

Read Content Types by Filter

By adding the X-Everlive-Filter header in the request you can supply a filter for the content types.

public async Task<IEnumerable<ContentType>> GetUserDefinedContentTypes(Guid applicationId, string masterKey)
{
    var metadata = new EverliveAccount(new EverliveAccountSettings(AuthorizationStrategy.MasterKey, masterKey));
    return await metadata.WorkWith().Application(applicationId).Types().GetAll().Where(ct => ct.Kind == ObjectKind.UserDefined).ExecuteAsync();
}

See Also


Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.