Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label api. Show all posts
Showing posts with label api. Show all posts

Wednesday, May 31, 2023

Webhooks in Sitecore 10.3




Today we are going to see new features of Sitecore called Web Hooks. Before understanding web hooks, let's try to understand the concept of hooks in general life. Just like we have hooks in our home to hang clothes or fishing hooks, these hooks can hold two different things and join them. Similarly, in programming, web hooks can allow interaction between different applications.

When two different web applications are present, they can be interacted through a callback function. One application can receive real-time notifications through an event. For instance, if something is happening in application one, it will trigger a notification for the other application, which will receive it in code terms. Web hooks can be used in two places: events and workflows. Whenever an item is created, deleted, copied, published or a workflow is submitted, these actions are considered events.

Web hooks can be used to track these events. Sitecore will send information about the event in terms of a JSON request payload to the other application. The Sitecore HTTP post request will be sent to the other application with the payload in JSON or XML format. The other application will receive the request and further process it. There are three types of web hooks that can be created: web hook event handler, workflow, and validation actions.

Here are the steps to implement

·       In Sitecore, web hooks can be created through the System section and Web Hooks option.

·       To create a web event handler, select a specific event (item added, copied, deleted, etc.).

·       Specify the URL for the other application and enable the event.

·       A demo was shown with a method created in the Target application to receive input from Sitecore and save it to a file.

·       When an item was added in Sitecore, the event was triggered and a file was created on the local machine with the input received from Sitecore.

Here is my YouTube video for the same

 



 

Stay tuned for more such articles, tips and tricks.

Thursday, February 23, 2023

OData Services in Sitecore

Today, we will be exploring one of the coolest features on the Sitecore: OData Services.

This feature allows you to expose your item data in JSON format in read-only mode. It is incredibly easy to use and configure. To do so, you need to create an OData item API at the settings, services API key section. After you have created it, you can specify its fields, for example, core, allowed control. You can also specify the database to which you want to get the item details. In a production environment, it is mostly on the web.

Once you have configured it, you can access your items by using the Sitecore domain name followed by the OData services API and the item ID or item path. You also need to pass the OData services API key. For example, if you want to access the details of a home item with ID and three fields (title, text, and address), you can use this URL and pass the API key. You will get the item properties such as the item name, path, language, template, creation date, and ID.

http://xp103sc.dev.local/sitecore/api/ssc/aggregate/content/Items('%7B%3Citem%20id%3E%7D')?sc_apikey=%3Capi%20key%3E

To get the field values, you need to pass the query string "$expand=field value".

Here is my YouTube video for the same



Stay tuned for more such articles, tips and tricks.