Quick Tip: Running the Kentico API Examples

   —   

As most developers are aware, Kentico 8.2 provides some API examples to demonstrate how to perform various tasks programmatically within the system. These examples are divided into categories and sub-categories and provide commented code for the action. In this article, I will show you how to execute these examples within your site, and how to see the results quickly.

 

Accessing the Examples

The API examples are available from within the Admin UI in the API examples module. In the tree, the provided examples are categorized by the area to which they pertain.

Examples Tree

Within each category, there may be several examples related to each topic.

Multiple Options

Running the Examples

On the Creating and managing side, clicking the desired example will execute the code on the server. These examples are focused on creating certain data elements and objects, and assigning properties or permissions.

New Poll

On the Cleanup side, each option has a “cleanup” action, which will roll back the respective change.

Delete Poll

Some actions require the previous example be run prior to executing.

Previous Action Required

Viewing the code

With every example, Kentico provides the code that will be executed. This makes it extremely useful for developers to understand what the code does as well as the expected outcome. Most examples contain comments to further describe each functionality. You can view the code for an example by clicking the ViewCode button.

View Code

Run all/Cleanup all

One nice feature of the API Examples module is the ability to execute all of the examples for the selected category. This simplifies the process of executing each one individually. Additionally, there is an option to Cleanup All examples, which rolls back all of the previous changes. 

Run All

Cleanup All

The great part about these two options is that they will execute the examples in the correct order and prevent any errors during the execution.

Conclusion

Kentico’s API Examples are a great resource for developers looking to learn how to interact with the API to achieve specific functionality. I have used these examples for years, and have found that they are often the best source of information when implementing custom functionality. I highly recommend developers look through the examples to see the best way to get their functionality in place. 

Good luck!

Share this article on   LinkedIn

Bryan Soltis

Hello. I am a Technical Evangelist here at Kentico and will be helping the technical community by providing guidance and best practices for all areas of the product. I might also do some karaoke. We'll see how the night goes...

Comments