Custom Middle-ware API(C#) to get forums based on different field parameters.

Shubham Salaria asked on February 7, 2018 14:51

Hello,

I need to create Custom api which provides the forums/posts/groups based on different parameters. I googled but didn't find any relevant post about it.

According to the following link https://docs.kentico.com/api10/social-and-community/forums we can create/update/delete the forum/forum post but there is nothing through which we can get multiple forums based on different parameters.

Can any one please guide me with the same or suggest me any better approach.

Thanks Shubham

Correct Answer

Trevor Fayas answered on February 7, 2018 15:32

You have a couple different options.

  1. You can create a custom web service, and leverage Kentico's API to take in whatever parameters, and put together the information. All of Kentico's objects have a ____InfoProvider.Get____s() type of method that is queriable, so you can do things like: "RoleInfoProvider.GetRoles().WhereEquals("RoleName", MyRoleNameParameter).Where("1=1")" etc
  2. Another option is you can create a custom Query with parameters, and then use the QueryInfoProvider.ExecuteQuery("Custom.Class.QueryName", MyQueryParameters, ....) to get information directly from the database and make your API off of that.

Also shameless plug, if you want to create an API in portal (without touching code), you can leverage the Repeater with Custom Query combined with the Webpart to API Converter in the marketplace, it can take the output of a repeater (rendered in XML or JSON) and convert it to an API.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Shubham Salaria answered on February 8, 2018 08:25 (last edited on February 8, 2018 08:57)

Thanks Trevor, I will try to implement the same in my dev machine. Is there any example/steps guide how we can fetch json object from outside the kentico. Like format/macro or configuration of transformation inside the webaprt. It will really help me to understand the concept and implementation.

Also I want to understand that how we can add custom fields to Forums?

Thanks Shubham

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on February 8, 2018 14:26

My blog article discussed the portal based API:

http://devtrev.com/Trev-Tips-(Blog)/January-2017/Portal-Powered-APIs-and-Feeds

Only thing you need to do is use the transformation to render your content in valid json and follow the steps in there!

As for adding fields, if you go to modules in Kentico, find the right module (I think forums), then go to classes within that forum, this is where you can find the classes, and often you can go into then and customize and add your own fields.

The strongly typed ForumInfo class will not reflect your new field but you can use the MyForumInfoObject.GetValue("my field") to retrieve and field.

0 votesVote for this answer Mark as a Correct answer

Shubham Salaria answered on February 9, 2018 11:53

I tried the Webpart to API option and it working well. very nice approach to get data without writing a code.

Forums related: I go to modules in Kentico and I found all classes are set to NO in "Is customizable" column. Is that something by default or we can change it.

Also I tried to clone the Forum module and got following error.

[DataConnection.HandleError]: Query: INSERT INTO Forums_ForumRoles ([ForumID], [RoleID], [PermissionID]) VALUES (@ForumID, @RoleID, @PermissionID); SELECT SCOPE_IDENTITY() AS [ID] Caused exception: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Forums_ForumRoles_RoleID_CMS_Role". The conflict occurred in database "Kentico10", table "dbo.CMS_Role", column 'RoleID'. The statement has been terminated.

I have no idea how to fix this.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.