How to Use Content Service API in Umbraco CMS

How to Use Content Service API in Umbraco CMS

Umbraco is an open-source Content Management System ( CMS ) for managing dynamic content on any site. It manages content from the admin panel and displays it on the front side. It is very easy to create content from the admin panel. Sometimes we need to create content from the front side. For example, we need to save testimonials for the site then it will be submitted from the front side. In this case, we need to save content from the front end. Umbraco CMS also provides us with Content Service API to manage content. We can use that content service API to create content from the front-end side.

There are some steps to create content using Content Service API.

  • Create a surface Controller.
  • Add a method for creating content.
  • Set generic properties of the content.
  • Add method in Umbraco form.

Do You Need Help From Our Dedicated Umbraco CMS Developer for Hire?

Hire our best Umbraco CMS developer on an hourly, Full-time, and Part-time basis. We are ready to help you resolve the problems for Umbraco CMS web app development. Hire Now!

Example:

For Example, If we need to add testimonials data to our site then, First of all, we need to create a Surface Controller in the Umbraco CMS project. Then we need to add the method as below to add testimonial data in the Umbraco CMS site. We need to set the value of generic properties that we had defined while creating document types of testimonials.


public ActionResult AddTestimonial(string Name = "", string Description = "")
{
	var contentService = new ContentService();
	var user = contentService.CreateContent(
		Name, // Node Name - what I want to call the new child node
		1115, // Parent Node we want to add to
		"umbTestimonial", // The alias of the Document Type
		0 // Umbraco User ID this will be created by, default 0
	);

	user.SetValue("name", Name);
	user.SetValue("description", Description);
	contentService.SaveAndPublish(user);

	return this.Redirect("/testimonial-list");
}

Now, We can post the data using BeginUmbracoForm method of Umbraco cms.


@using (Html.BeginUmbracoForm("AddTestimonial", "TestimonialSurface", FormMethod.Post))
{
	// Add your form code here
}

Now, We can post the data using BeginUmbracoForm method of Umbraco cms.


@using (Html.BeginUmbracoForm("AddTestimonial", "TestimonialSurface", FormMethod.Post))
{
	// Add your form code here
}

I hope that this article will make your Umbraco CMS integration as easy as. Get in touch, if you would like to support in Umbraco CMS development. You may also Hire Umbraco CMS Developers from our company for Help and Support.

Article by

Jignasha Rathod

Jignasha Rathod is a Technical Analyst with over a decade of experience in the IT industry. She excels in .NET, CI/CD, GitHub, Azure. and has a proven track record in project management, leadership, API integrations, and Azure AI and ML.net . Jignasha is focused on performance enhancement and possesses deep domain expertise in open source CMS ( umbraco, orchard cms ) accounting, CRM, ERP (SAP, NetSuite, Business Central) and e-commerce. Her extensive experience spans across both B2B and B2C e-commerce platforms, and she is leveraging AI and ML technologies to drive innovation and efficiency in client projects.