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:
	# Login
		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)

	# Get Child Items
		sUrl = sHost + "item/{C4EA14BD-4F2F-4306-8E7F-A922B9C67E7E}/children?fields=ItemID,ItemName,Active Flag,Search Flag" # /sitecore/content/Global/Facets/Tags
		print(sUrl)
		
		resp = req.get(sUrl)
		if resp.ok:
			sText = resp.text
			print (sText)
			data = json.loads(sText)
			for x in data:
				if x["Active Flag"]=="Y" and x["Search Flag"]=="Y":
					print(x["ItemName"] + " " + x["ItemID"]);			
		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