1

So I am faced with a challenge. I need to create a REST Services that will allow me to serialize Sitecore tree from outside the Sitecore. Is there some kind of service like this in place? Or this need to custom made? If yes, could please provide resources or steps that should be taken to create this. Ultimate goal is to hit the URL

(something.com/sitecore/serialize&database=master&user=admin&password=pass)

Something like this.

  • You might look into Unicorn which already has something very similar and could be adapted as it's open source. – Richard Hauer Feb 11 '17 at 0:04
3

There isn't anything OOTB that will allow you to hit a rest service. You have a couple of options:

Sitecore PowerShell Extensions

You could use Sitecore PowerShell Extensions remoting to do that fairly easily. Syntax to serialize an item is:

serialize-item -path "master:\content"

If you want children included, then:

get-childitem "master:\content\home" -recurse | where-object { $_."__Created By" -eq "sitecore\admin" } | serialize-item

So using SPE remoting you could do something like:

Set-SitecoreConfiguration –SitecoreHost 'http://hostname' `
    -User 'admin' –Password 'b'
$path= "master:\content\home"
Invoke-SitecoreScript –Command { Serialize-Item $params.scPath }`
    -Params @{ scPath = $path}

Custom REST Service

If you can't use SPE - then your other option would be to write your own rest service that takes in the path to serialize and some credentials. You can use the Serialization API in Sitecore to do this:

public void SerializeItem(string itemId)
{
    if (Sitecore.Data.ID.IsID(itemId))
    {
        Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master");
        Item item = masterDB.GetItem(Sitecore.Data.ID.Parse(itemId));
        if (item != null)
        {
            Sitecore.Data.Serialization.Manager.DumpItem(item);
        }
    }
}

Credits:

3

Sitecore PowerShell Extensions - Web API

As pointed out by Richard, SPE comes with some ways to do this. You can find more details about the latest version of SPE Remoting here.

For now we will stick the Web API option which will give you a url similar to that in your example.

Here are some steps to get you going:

  • Install SPE 4.3+.
  • Enable the Web API service RESTful v2 using a configuration patch. You'll be happy to know that it's disabled by default.
  • Create a new module and integration point library called Web API.
  • Create a new script called Serialize.
  • Add your script to serialize items using the Export-Item command.
  • Query using the api url.

Sample Response

Example: The following url assumes the admin user is authorized to login to Sitecore and execute against the v2 REST API.

http://testspe/-/script/v2/master/serialize?user=sitecore\admin&password=b

Here's a picture to help with the above instructions: Script

Example: The following exports all of the descendants of the home item.

Get-Childitem "master:\content\home" -Recurse | 
    Where-Object { $_."__Created By" -eq "sitecore\admin" } | 
    Export-Item

Note:

  • Web API uses the restfulv2 service.
  • SPE Remoting uses the remoting, fileUpload, fileDownload, mediaUpload, mediaDownload services.
  • The module in the script library needs to be enabled otherwise you'll recieve a 404 error. Notice how X-Demo shows a jar with a bean while others above have an x.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.