Content Management Sample
Learn how to access and work with the Content Management API on your Umbraco Heartcore project.
This sample guide will cover how you can access and work with the Content Management API from the client library.
Requirements
.NET/.NET Core (2.0 or newer) or .NET Framework (4.6.1 or newer)
Getting Started
Add the
Umbraco.Headless.Client.Net
package to your project.dotnet add package Umbraco.Headless.Client.Net
Add environment variables for your project alias and your API key.
appsettings.jsonRegister the
ContentManagementService
to your dependency injection container. The registration of theContentManagementService
is handled by theAddUmbracoHeartcore
extension method.
Inject the
ContentManagementService
into your non-static class.
If you don't want to use dependency injection, you can manually create an instance of the ContentManagementService
class. The constructor requires that you know the project alias and your API key.
Now you are ready to start using the ContentManagementService
.
Content
When working with content, the ContentManagementService
can Get, Create, Update, Publish, Unpublish, and Delete content.
Get Content
The ContentManagementService
has three methods for getting content.
GetRoot()
GetRoot()
Gets all content at the root of the tree.
To use this method, call the method on the ContentManagementService
instance:
GetById(Guid id)
GetById(Guid id)
Gets a specific content item matching a GUID.
To use this method, call the method on the ContentManagementService
instance and pass in the GUID of the content item you want to get:
GetChildren(Guid id)
GetChildren(Guid id)
Gets all content that is a child of a specific content item.
To use this method, call the method on the ContentManagementService
instance and pass the GUID of the content item to get the children:
Create Content
The ContentManagementService
has one method for creating content.
Create(Content content)
Create(Content content)
Creates a new content item based on the passed-in Content
object.
To use this method, call the method on the ContentManagementService
instance and pass in the content item you want to create:
Update Content
The ContentManagementService
has one method for updating content.
Update(Content content)
Update(Content content)
Updates an existing content item based on the passed-in Content
object.
To use this method, call the method on the ContentManagementService
instance and pass in the content item you want to update:
Publish Content
The ContentManagementService
has one method for publishing content.
Publish(Guid id, string culture = "*")
Publish(Guid id, string culture = "*")
Publishes an existing content item based on the passed-in GUID and culture.
To use this method, call the method on the ContentManagementService
instance and pass in the GUID of the content item you want to publish:
Optionally, you can also pass in the culture of the content item you want to publish:
Unpublish Content
The ContentManagementService
has one method for unpublishing content.
Unpublish(Guid id, string culture = "*")
Unpublish(Guid id, string culture = "*")
Unpublishes an existing content item based on the passed-in GUID and culture.
To use this method, call the method on the ContentManagementService
instance and pass in the GUID of the content item you want to unpublish:
Optionally, you can also pass in the culture you want to unpublish the content item in:
Delete Content
The ContentManagementService
has one method for deleting content.
Delete(Guid id)
Delete(Guid id)
Deletes an existing content item based on the passed-in GUID.
To use this method, call the method on the ContentManagementService
instance and pass in the GUID of the content item you want to delete:
Media
When working with media, the ContentManagementService
can Get, Create, Update and Delete media.
For Media you create programmatically, you have to use the "raw" property values that Umbraco expects for the specific property editor.
The different scenarios are:
File Upload (A File Upload property editor)
When uploading a file, you must specify the file name for the
umbracoFile
property alias.Image Upload (A Image Cropper property editor)
When uploading an Image (by default, it uses the Image Cropper property editor), you must specify the source's file name for the
umbracoFile
property alias.
Get Media
The ContentManagementService
has three methods for getting media.
GetRoot()
GetRoot()
Gets all media at the root of the tree.
To use this method, call the method on the ContentManagementService
instance:
GetById(Guid id)
GetById(Guid id)
Gets a specific media item matching a GUID.
To use this method, call the method on the ContentManagementService
instance and pass in the GUID of the media item you want to get:
GetChildren(Guid id)
GetChildren(Guid id)
Gets all media that is a child of a specific media item.
To use this method, call the method on the ContentManagementService
instance and pass in the GUID of the media item to get the children:
Create Media
The ContentManagementService
has one method for creating media.
Create(Media media)
Create(Media media)
Creates a new media item based on the passed-in Media
object.
To use this method, call the method on the ContentManagementService
instance and pass in the media item you want to create:
Update Media
The ContentManagementService
has one method for updating media.
Update(Media media)
Update(Media media)
Updates an existing media item based on the passed-in Media
object.
To use this method, call the method on the ContentManagementService
instance and pass in the media item you want to update:
Delete Media
The ContentManagementService
has one method for deleting media.
Delete(Guid id)
Delete(Guid id)
Deletes an existing media item based on the passed-in GUID.
To use this method, call the method on the ContentManagementService
instance and pass in the GUID of the media item you want to delete:
Further reading
Learn how to Create content programmatically.
Last updated