Monday, November 11, 2024

How to Create a Public Link Using the Sitecore Content Hub REST API

Creating a public link using the Sitecore Content Hub REST API is a straightforward process that enables you to share content externally while maintaining control over access. Start by authenticating your API request using your credentials to gain access to the necessary endpoints. Once authenticated, you can use the API to create a public link for specific assets or content items by sending a POST request to the designated endpoint, typically `/api/links`. In your request body, include parameters such as the asset ID, link type, and any additional metadata you want to associate with the link. After the request is processed, the API will return a response containing the generated public link, which you can then distribute as needed. It’s important to configure the permissions and expiration settings appropriately to ensure that the link aligns with your organization's security policies. By following these steps, you can efficiently create and manage public links, facilitating easy access to content while leveraging the robust capabilities of the Sitecore Content Hub REST API.  

In this blog, we will walk through how to create public links for assets, how to retrieve the public URL, and how to set expiration dates for those links to help you maintain full control over the shared content.

Content Hub allows us to create public links and integrate them with any type of web application/page.

This blog helps you to create public links using REST API.

Step 1: Authenticating and Creating a Public Link for an Asset

The first step in creating a public link is authenticating your API request. Authentication ensures that only authorized users or applications are able to interact with the Sitecore Content Hub's API. Once authenticated, you’ll be able to create a public link for a specific asset or entity.

API Request to Create Public Link

To create a public link for your selected asset, make a POST request to the following API endpoint:

  • URL: {{ChUrl}}/api/entitydefinitions/M.PublicLink/entities
  • Method: POST
  • Headers: Content-Type: application/json
  • Body (Raw JSON format):
json:
{
	"properties": {		
		"Resource": "downloadOriginal"		
	},
	"is_root_taxonomy_item": false,
	"is_path_root": false,
	"inherits_security": true,
	"entitydefinition": {
		"href": "{{ChUrl}}/api/entitydefinitions/M.PublicLink"
	},
	"relations": {
		"AssetToPublicLink": {
			"parents": [
				{
				"href": "{{ChUrl}}/api/entities/{entityid}"
				}
			]
		}
	}
}


Explanation of Parameters:

  • Resource: Defines the specific resource, such as the original download link, that is being shared.
  • is_root_taxonomy_item: Specifies whether the asset is a root taxonomy item.
  • inherits_security: Ensures that security settings (such as user permissions) are inherited by the public link.
  • entitydefinition: Refers to the entity definition for the type of public link.
  • relations: Links the public link to the selected asset using the entity ID.

Replace {{ChUrl}} with your Content Hub URL and {entityid} with the asset's unique entity ID. After sending the POST request, the API will return a successful "201 Created" response code and provide you with an identifier for the newly created public link.

Expected API Response:

If the request is successful, you will receive a response containing the public link's identifier:

{
    "id": 89358,
    "identifier": "iAOnXWcvmk6cQw"
}


Step 2: Retrieve the Public Link URL

Once the public link is created, you can retrieve the actual public URL by using the identifier you obtained in the previous step. This public URL allows you to share the asset with external parties or integrate it into other applications.

API Request to Get the Public Link URL

  • URL: {{ChUrl}}/api/entities/identifier/{identifier}
  • Method: GET

Replace {identifier} with the identifier returned from the previous API request.

Example Response:

The API will return a response with the generated public link for your asset.

{ "id": 89358, "publicLink": "https://yourcontenthuburl.com/publiclink/iAOnXWcvmk6cQw" }

With the public link, you can now easily distribute the content to your intended users or integrate the link into web applications.

Step 3: Set an Expiration Date for the Public Link

One of the key benefits of using the Sitecore Content Hub API to create public links is the ability to control the lifespan of these links. You can set an ExpirationDate to specify when the public link should no longer be valid. This feature helps enhance security by automatically revoking access to shared assets after a set period, reducing the risk of unauthorized access.

Example Request with Expiration Date:

{ "properties": { "Resource": "downloadOriginal", "ExpirationDate": "2021-11-15T10:18:45.220Z" }, "is_root_taxonomy_item": false, "is_path_root": false, "inherits_security": true, "entitydefinition": { "href": "{{ChUrl}}/api/entitydefinitions/M.PublicLink" }, "relations": { "AssetToPublicLink": { "parents": [ { "href": "{{ChUrl}}/api/entities/{entityid}" } ] } } }

  • ExpirationDate: Set this value in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmZ) to define the exact time when the public link should expire.
By specifying an expiration date, you ensure that content access is temporary and controlled. After the expiration date, the link will become invalid, and users will no longer be able to access the content.                    
                        

Importance and Benefits of Creating Public Links

Using public links through the Sitecore Content Hub REST API offers several advantages:

  1. Controlled Sharing: You can share content externally without compromising internal security. The ability to set expiration dates ensures that shared links are only valid for a limited time, reducing the risk of unauthorized access.

  2. Ease of Integration: Public links can be easily integrated into external web applications, client portals, or even marketing campaigns. This allows for seamless content distribution while maintaining centralized control over assets.

  3. Security and Compliance: Setting permissions and using expiration dates for links helps ensure that your organization remains compliant with security policies and regulatory requirements, ensuring only authorized access to sensitive content.

  4. Optimized User Experience: The public link feature enables organizations to share assets with external users or teams without the need for them to log into the Content Hub. This makes content more accessible, enhancing collaboration with external stakeholders and partners.

  5. Improved Workflow Efficiency: Automating the process of generating public links through API requests minimizes manual intervention, making the content sharing process faster and more efficient.

By leveraging Sitecore Content Hub's REST API to create public links, you can efficiently share content with external parties while maintaining strict control over access and security. The ability to set expiration dates further enhances security, ensuring that links are only valid for as long as needed.

Whether you're sharing assets for marketing, collaboration, or external distribution, public links make it easier to manage access and content flow within and outside your organization.

With Sitecore Content Hub, you can combine flexibility, security, and ease of use to enhance the way you manage and distribute content.

                                            Happy learning and sharing your assets securely!

Monday, November 4, 2024

How to Leverage Custom Search Configuration in the Sitecore Content Hub Search API

Using Custom Search Configuration in the Sitecore Content Hub Search API allows you to tailor search functionalities to meet specific business needs. To get started, define your custom search configuration in the Content Hub, where you can specify parameters such as searchable fields, filters, and sorting options. Utilize the Search API to implement these configurations by creating search queries that leverage the defined parameters, ensuring relevant results are prioritized based on your criteria. You can also enhance user experience by integrating faceted search options, allowing users to filter results dynamically based on attributes like content type or tags. Additionally, consider implementing custom ranking algorithms to further refine search results according to your organization's priorities. Testing and iterating on your custom configurations will help you optimize performance and relevance, ensuring that users can efficiently access the content they need. By leveraging Custom Search Configuration, you can significantly improve the search experience within Sitecore Content Hub. 

The Sitecore Content Hub Search API offers a powerful way to customize and fine-tune search functionalities to align with your organization’s unique business requirements. By defining a custom search configuration, you can tailor the search experience to prioritize specific criteria, filter content effectively, and enhance overall search results. In this guide, we'll walk through the process of creating a custom search configuration in Sitecore Content Hub and demonstrate how to integrate it into your search queries.

Why Use Custom Search Configuration?

Customizing your search configuration in Sitecore Content Hub allows you to:

  • Define searchable fields: Select which fields should be included in the search.
  • Apply filters: Narrow down search results based on specific criteria like content type, tags, or categories.
  • Customize sorting options: Control how search results are ranked or sorted according to your organization’s preferences.
  • Enhance user experience: By integrating features like faceted search, users can filter results dynamically based on attributes.
  • Implement custom ranking algorithms: Refine search results based on your business priorities.

By leveraging these capabilities, you can optimize the search functionality in Sitecore Content Hub to ensure that users can quickly and efficiently access relevant content.


Step 1: Creating Custom Search Configuration in Sitecore Content Hub

To begin using custom search configurations, you first need to define the configuration in Sitecore Content Hub. This involves specifying the fields, filters, and sorting options that are most relevant to your content and user base.

Follow the detailed steps in the Sitecore Content Hub Knowledge Base to learn how to create a custom search configuration. This blog will guide you through all necessary steps to get your search configuration up and running.

Once you've completed the setup, you will have a configuration that reflects your search requirements and can be easily implemented within your search queries.

Step 2: Integrating Custom Search Configuration in Your Search Queries

Once your custom search configuration is created, you can begin using it within your search queries to retrieve content that aligns with your predefined search parameters.

To test and implement your custom search configuration, use the following API details:

API Endpoint

  • URL: /api/search
  • Method: POST
  • Content-Type: application/json

Request Body (JSON Example)

{ "configuration_category": "SearchConfiguration", "defaults": "MySearchConfiguration", "name": "MySearchConfiguration", "skip": 0, "take": 10 }

Explanation of Parameters:

  • configuration_category: This specifies the category of the configuration, which is typically "SearchConfiguration".
  • defaults: The name of the default configuration you want to use for your search query.
  • name: The name of the custom search configuration that you've created in Sitecore Content Hub.
  • skip: Specifies the number of records to skip (for pagination purposes).
  • take: Defines how many records to return per query.

This API request will trigger the search functionality based on your custom configuration, returning results that align with the parameters you've set up.

Step 3: Testing and Optimizing Custom Search Configuration

Once your custom search configuration is integrated into the query, it’s crucial to test it to ensure everything is working as expected. Perform queries using different configurations and examine the results:

  • Verify Filters and Sorting: Ensure that content is being filtered and sorted correctly based on your predefined settings.
  • Check Relevance: Ensure that the most relevant results appear first, and refine the configuration if necessary.
  • Evaluate User Experience: If you’ve integrated faceted search, make sure users can easily filter results based on content type or tags.

Iterate on your configuration based on the test results to further optimize search performance and relevance. This helps ensure users can quickly find the content they need, enhancing their overall experience.

The search API return the following result, which reflects the properties mentioned in the search configuration.




By using Custom Search Configuration in the Sitecore Content Hub Search API, you can significantly improve the way content is searched, filtered, and sorted within your organization. This customization empowers you to create a more efficient and relevant search experience for your users, ensuring they can access content quickly and accurately.

With the flexibility to define parameters like searchable fields, filters, and ranking options, as well as the ability to implement faceted search and custom ranking algorithms, Sitecore Content Hub provides a highly configurable search solution. Test and iterate on your configurations regularly to continuously refine the search experience for your users.

Happy learning and optimizing your Sitecore Content Hub search functionalities!

                                                                   Learning never exhaust mind.

Friday, November 1, 2024

Sitecore instance setup : How to remove Solr services from windows?

 Follow the instructions to remove services like Solr, Sitecore running services, and any other services from Windows.

To remove Solr services from a Windows environment, you'll need to follow a series of steps to ensure a clean uninstallation. First, stop the Solr service by opening the Command Prompt as an administrator and executing the command `sc stop solr`, replacing "solr" with the actual name of your Solr service if it differs. Next, you can disable the service by running `sc delete solr`. After stopping and deleting the service, navigate to the installation directory (typically found in `C:\solr` or wherever you installed Solr) and manually delete the folder to remove all files associated with the Solr instance. Finally, check the Windows Registry for any leftover entries by opening the Registry Editor (regedit) and searching for "Solr" or related keys to ensure there are no remnants. Once you’ve completed these steps, restart your computer to finalize the removal process. This will ensure that Solr services are fully uninstalled from your Windows system.

 Download the NSSM tool from google.




        Open the below folder.



          Copy the full path like this.




        Open the Command prompt in admin mode and navigate to the folder mentioned earlier. 


        Copy the Name of the service that you want to remove from the services.




        Give the following command like “nssm remove” after that put the service name that you want to remove(which is copied from the Servies) followed by space.





        Here it will ask for confirmation, click on “Yes”.





        It will remove the service and give a message like below.





                                                         
Learning never exhausts the mind.”
                                                                             Happy learning!


How to Create a Public Link Using the Sitecore Content Hub REST API

Creating a public link using the Sitecore Content Hub REST API is a straightforward process that enables you to share content externally whi...