Last active
December 14, 2015 08:39
-
-
Save Kieranties/5059684 to your computer and use it in GitHub Desktop.
Using PSSitecoreItemWebAPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adding as an authorised user is much the same as getting. Just provide the template and name fields | |
Add-SitecoreItem sitecore.local -user apiuser -pass password -database master ` | |
-name "Awesome new item" -template "Sample/Sample Item" | |
<# | |
totalCount resultCount items StatusCode | |
---------- ----------- ----- ---------- | |
1 1 {@{Database=master; Displa... 200 | |
#> | |
# We can also say where we want the item created as well as set fields at the same time | |
Add-SitecoreItem sitecore.local -user apiuser -pass password -database master ` | |
-path /sitecore/content/home -name "Awesome new item" -template "Sample/Sample Item" ` | |
-itemFields @{title="This is a title"; text="<h1>Rich text ahoy!</h1>"} | |
<# | |
totalCount resultCount items StatusCode | |
---------- ----------- ----- ---------- | |
1 1 {@{Database=master; Displa... 200 | |
#> | |
# Use "Get-Help Add-SitecoreItem" to see what else you can do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# As an anoymous user | |
Get-SitecoreItem sitecore.local | select -expand items | |
<# | |
Database : web | |
DisplayName : Home | |
HasChildren : False | |
ID : {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} | |
Language : en | |
LongID : /{11111111-1111-1111-1111-111111111111}/{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} | |
Path : /sitecore/content/Home | |
Template : Sample/Sample Item | |
Version : 1 | |
Fields : @{{75577384-3C97-45DA-A847-81B00500E250}=; {A60ACD61-A6DB-4182-8329-C957982CEC74}=} | |
#> | |
# As an authorised user getting content from a particular database | |
Get-SitecoreItem sitecore.local -user apiuser -pass password -database master | select -expand items | |
<# | |
Database : master | |
DisplayName : Home | |
HasChildren : False | |
ID : {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} | |
Language : en | |
LongID : /{11111111-1111-1111-1111-111111111111}/{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} | |
Path : /sitecore/content/Home | |
Template : Sample/Sample Item | |
Version : 1 | |
Fields : @{{75577384-3C97-45DA-A847-81B00500E250}=; {A60ACD61-A6DB-4182-8329-C957982CEC74}=} | |
#> | |
# You can also provide -path / -query / -item / -scope and many more to filter items | |
# Use "Get-Help Get-SitecoreItem" to see what is available to you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Removing an item is as easy as you'd expect | |
Remove-SitecoreItem sitecore.local -user apiuser -pass password -database master ` | |
-item "{544F86D9-B0B2-497F-8E73-61531708CEFA}" | |
<# | |
totalCount resultCount items StatusCode | |
---------- ----------- ----- ---------- | |
1 1 {@{ID={544F86D9-B0B2-497F-... 200 | |
#> | |
# Note: the api only returns the ID of the items removed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setting properties on an item is much the same as adding an item. This time the name and template are not needed | |
# Note: here we're using the -item parameter to ensure we are setting on this specific item | |
Set-SitecoreItem sitecore.local -user apiuser -pass password -database master ` | |
-item "{544F86D9-B0B2-497F-8E73-61531708CEFA}" ` | |
-itemFields @{ Text = "<strong>updated</strong> with something <em>else</em>"} | |
<# | |
totalCount resultCount items StatusCode | |
---------- ----------- ----- ---------- | |
1 1 {@{Database=master; Displa... 200 | |
#> | |
# Again you can get fancy here and use -query / -scope etc to update multiple items in one go! | |
# Use "Get-Help Set-SitecoreItem" to see what is available to you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment