Search code examples
c#apikentico

Understanding the API


So I understand the basic principle of an API, to provide me with access to the core data and functions of the system - in this case Kentico. For example I wanted to get all of the data from the "CMS_Membership" database table, so I started at https://devnet.kentico.com/docs/8_2/api/html/N_CMS_Membership.htm and there are hundreds of different classes and functions - I tried a few that looked like they might return what I want but no joy.

Do you really use and API by looking for a method name that sounds like what you want? I have heard about "providers" in kentico, are these an easier way to preform common functions? In the end I just wrote a SQL query to go direct to the table which I know is probably wrong.


Solution

  • Kentico does provide documentation for the API (which is to be used as a reference to specific classes, members etc), such as the page you referenced; https://devnet.kentico.com/docs/8_2/api/html/N_CMS_Membership.htm

    Kentico also provides separate development documentation on using the API such as; https://docs.kentico.com/display/K82/Retrieving+database+data+using+ObjectQuery+API

    Summarizing what you can read in the link above. For every CMS object you will find;

    • A Table in the database. Eg. CMS_Membership
    • An Info class in the API that represents the Table. Eg. MembershipInfo
    • An InfoProvider class in the API that provides functions to work with the Info class. Eg. MembershipInfoProvider

    You can use the ObjectQuery method on the InfoProvider class to return a list of the Info class. Eg. MembershipInfoProvider.GetMemberships()

    I'm not sure what specifically you want to do with the CMS_Membership table so I will provide an example of getting MembershipInfo data and iterating over it;

    var members = MembershipInfoProvider.GetMemberships();
    foreach (MembershipInfo mi in members)
    {
       //iterate over your results
    }
    

    That is a very simple ObjectQuery, you can expand on this to build complex queries that specify Columns, Where, Order, Top, Join etc.

    You may also find these articles on DataQuery helpful;