sitecore item api using powershell




Here is an interesting problem, using powershell to call sitecore api's item. First we need to authenticate ourselves.

To Authenticate

# Your sitecore api login

$loginurl = 'https://yourserver/sitecore/api/ssc/auth/login'

# Converting object into a JSON

$Body = @{
    domain = "sitecore"
    username = "admin"
    password = "mradmin" 
}

$json = $Body | convertto-json


# Call to authenticate and store into session variable call "mysession". Please note that we do not put $ in front of it.

Invoke-WebRequest -Uri $loginurl -ContentType 'application/json' -Method 'POST' -Body $json -usebasicparsing -sessionvariable mysession

You should get something like this.




Next, we pass our session variable into our websession parameter (shown in bold).

$jsonContent = Invoke-WebRequest 'https:/yourserver/sitecore/api/ssc/item/%7B95FD0E53-0466-49A6-BB24-F5D2FE996393%7D' -WebSession $mysession -METHOD 'GET' -usebasicparsing




You can always convert $jsonContent , into powershell object. 


 $jsonContent .content | convertfrom-json






Comments

Popular posts from this blog

ionic2 cordova build android - Unable resolve gradle 2.2.3

A quick tutorial for OWASP ZAP tool for beginners