Updating page via API
This article describes how to update a page via API
There are two ways of updating a page via API.
- The Page entity can be updated directly
- The DraftPage entity can be used for updating
In the first case, update Page entity, and then use the Update method from the PageService.
The page information is now updated and visible on a public site or in a data base, PageFieldData table.
In this case the DraftPage information is not updated which means that old information will be reflected in backoffice when you edit the page.
Example:
var page = _pageService.Get(new Guid("f1392d9b-aa12-48c2-9b9d-5fb59633e325")).MakeWritableClone();
page.Localizations.CurrentCulture.Name = "Article";
page.Fields.AddOrUpdateValue("Title", CultureInfo.CurrentCulture, "UpdatePage");
_pageService.Update(page);
Note:
If you Quick publish from backoffice, information will be overridden by the information in the draft page. In the second case it is possible to update DraftPage entity with new information and then use Publish method from the DraftPageService to update the page with correct information.
Then both the page and the draft page will be updated, and the information is correct both on the public site and backoffice.
Example:
var draftPage = _draftPageService.Get(new Guid("f1392d9b-aa12-48c2-9b9d-5fb59633e325")).MakeWritableClone();
draftPage.Localizations.CurrentCulture.Name = "Article";
page.Fields.AddOrUpdateValue("Title", CultureInfo.CurrentCulture, "UpdatePage");
_draftPageService.Update(draftPage);
_draftPageService.Publish(draftPage);