Python Consume Sitecore ItemService

The Sitecore ItemService provides a RESTful API that you use to interact directly with Sitecore items.


import requests

sHost = "https://cms.bangtech.com/sitecore/api/ssc/"

def JSSGetItem():
	sUrl = sHost + "auth/login"
	print (sUrl)
	
	headers = {"Content-Type" : "application/json"}
	data = {"domain": "sitecore", "username": "uid",  "password": "pwd" }
		
	# Use 'with' to ensure the session context is closed after use.
	with requests.Session() as req:
		resp = req.post(sUrl, headers = headers, json = data)
		if resp.ok:
			sText = resp.text
			print (sText)
			#print(resp.headers)
		else:
			print ("Boo! {}".format(resp.status_code))
			print (resp.text)

		sUrl = sHost + "item/9E1CD652-81B6-4E33-B495-09F34CE1DE9B/children" # /sitecore/content/Global/Facets/Modes
		print(sUrl)
		
		resp = req.get(sUrl)
		if resp.ok:
			sText = resp.text
			print (sText)
		else:
			print ("Boo! {}".format(resp.status_code))
			print (resp.text)

JSSGetItem()


Operation

Query string

Get item

/sitecore/api/ssc/item/110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9

Get item including metadata

/sitecore/api/ssc/item/110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9?includeMetadata=true

Get item including standard template fields

/sitecore/api/ssc/item/110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9?includeStandardTemplateFields=true

Get item with field projection

/sitecore/api/ssc/item/110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9?fields=ItemID,ItemName,TemplateName

Search

/sitecore/api/ssc/item/search?term=Home

Search with paging and field projection

/sitecore/api/ssc/item/search?includeStandardTemplateFields=false&fields=ItemID%2CItemName&page=1&term=sitecore

Get media item

/sitecore/api/ssc/item/C19E9164-FF99-4A05-B8C0-E9C931DA111F

Get item using the content path

/sitecore/api/ssc/item/?path=/sitecore/content/Home