Surendra Sharma

Surendra Sharma

Search This Blog

Saturday, February 23, 2019

How to execute Sitecore GraphQL query in Postman


GraphQL is querying technic to get the result in JSON format. 

It means now you can get Sitecore items in JSON format using GraphQL.

You can test your GraphQL query either directly on browser or on POSTMAN.
This article highlight how you can do the same using Postman GET and POST method.

Using POST Request

1.   Open Postman and create new Request
 
New Request Window
New Request Window

 
2.   Save Request by providing Request name, description etc.

Save Request Window
Save Request Window


3.   Select POST request type and enter request URL with “sc_apikey” query string as

Params in POST request
Params in POST request

4.    Select Body tab and select “raw” and format type as “JSON(application/json)”. Write your GraphQL query in body textbox as

Query in Body section
Query in Body section

This action add “Content-Type” as "application/json" in “Headers” tab.

5.   Click on “Send” button and you should get your query JSON result as

Post Request
Post Request


Using GET Request


1.   Open Postman and create new Request
2.   Save Request by providing Request name, description etc.
3.   Select GET request type and enter request URL with “sc_apikey” and “query” query string as “http://my-first-jss-app.dev.local/sitecore/api/graph/mygraphapi?sc_apikey={D259F575-F8E2-452F-8A1B-AB699CC6503C}&query={ search(fieldsEqual: [], first: 10, after: "3") { results { items {item {id name itemPath: path url } } } }}”. This will add key "sc_apikey" and “query” in “Params” section.

 
4.    Click on “Send” button and you should get your query JSON result as

Get Request
Get Request
Note:- While writing your query, just remove all escape lines. In other words, you must write your query in single line without any truncation.

That's it.
I hope you will use Postman for executing Sitecore GraphQL query.

Stay tuned for more such cool tricks.

Saturday, February 9, 2019

Multiple bucketing structure in single Sitecore instance

When you are bucketing items in Sitecore, by default it will be reorganized all child items by creating folders according to datetime order in year, month, day, hour, and minute.

Datetime Structure
Datetime Structure
But what if you want one datetime order at one place and for some other items you want all child items should rearranged in alphabetic order or may be by creating folders according to GUID characters.
How to achieve it?
 

To create a multiple bucketing structure in Sitecore:

1.    Visit to the “/sitecore/system/Settings/Buckets/Item Buckets Settings”. Click on Edit rule in Rules for Resolving the Bucket Folder Path field:
 
Item Bucket Settings
Item Bucket Settings


2.    Create rules by selecting a condition and an action.
 

Here action specifies the bucket folder structure. Only bucket items that match the condition will use the action.

Bucket Rule
Bucket Rule

For example, above rule creates alphabetic bucket structure as:

Alphabetic Ordering of bucket items
Alphabetic Ordering of bucket items

Now you have bucketing structure according to datetime and alphabetic order in one Sitecore instance. However you can create any number of such ordering by using such rules.

Isn’t that a cool feature???

Saturday, February 2, 2019

Sitecore Headless architecture in Ravana ways


With version 9.1, Sitecore officially started to support JSS(Java Script Services) which bring a capability of true headless CMS.
 
But headless is still a new concept for many developers and if you questioned them during interview what is headless, many developers just started to feel uncomfortable.

This article may help you to understand headless architecture through Ravana(Wikipedia) way.

In India we have one of the greatest epic called Ramayana.

In short it's an epic about lord Rama, Sita, Ravana etc. This Ravana is very interesting mythological character and help me to understand headless architecture.

In many temples, Ravana showed with all his weapons and with 10 heads as

Ravan
Ravan

Ravana kidnapped Sita, so there was a war between Rama and Ravana. During that war Rama cut his head as

Headless Ravan
Headless Ravan


But Ravana was blessed with boon from Brahma and nobody can kill him in normal way.

Here you can imagine Ravana legs as Sitecore databases, his middle body as Sitecore XP and his all weapons represented as xConnect, Sitecore analytics and services, etc. 

But any living creature can't be survive well without any head. Similarly Sitecore can be headless but your final product or website can't be headless. It must have at least one or more head. It's something like

Depicting Sitecore and Ravan

Ravana had 10 heads which were different in look and shape. Each head was master in one field but ultimately, they all were face of Ravana. 

Similarly there are different front-end technologies with different features and uses. Where front end technologies can be angular, React, Vue.js, knockout, ASP.Net, MVC, Ruby etc. 

In short Ravana body represent Sitecore backend parts while his heads represent front end technologies.

That’s it.

I hope Ravana's character help you to understand Headless architecture. So next time someone ask you about headless explain him through Ravana's way.

Happy headless.

Friday, January 25, 2019

Sitecore error - You must remove all users with password before setting the containment property to NONE

I was installing Sitecore 9 and received some SOLR CORE errors so I again re-execute the script and this time received new error “You must remove all users with password before setting the containment property to NONE”.
 
I google it and found out that it’s because of users are exist in Sitecore databases.

So I created this handy SQL script where you have to specify database prefix only and it will remove particular users from all necessary databases.

--Specify your Sitecore instance prefix here
DECLARE @prefix NVARCHAR(50) = 'sc9u2com';
DECLARE @query NVARCHAR(MAX);
SET @query = 'Use [' + @prefix + '_MarketingAutomation]; DROP USER [marketingautomationuser];'
SET @query = @query + 'Use [' + @prefix + '_Messaging];DROP USER [messaginguser];'
SET @query = @query + 'Use [' + @prefix + '_Processing.Pools];DROP USER [poolsuser];'
SET @query = @query + 'Use [' + @prefix + '_ReferenceData];DROP USER [referencedatauser];'
Select @query
exec(@query)

I hope this script will help developers who are facing same issues.