In a recent integration project we worked on, we used Sitecore Content Hub (CH) Wen client SDK to build a web PI application to serve as middle point between Sitecore CH and a third party application, we learned a lot through this project, and one of these learning lessons is the speed of pulling data from CH and how CH aggregates would be great help while working on such implementation, in this post I'll introduce aggregates and discuss how it could help enhance your application performance, excited? keep reading :)
When you work on pulling data from CH, you will run into some limitations when it comes to speed and the number of requests limits, CH has a 15 calls per second per API integration user, Exceeding this rate will result in "429 too many requests" error responses, and this is called "Throttling" , CH apply it when the backend is receiving too many requests from one specific user/client it will return responses with status code 429 (Too Many Requests). These responses will not contain the requested payload.
Another issue you may notice is the response time, at least in our case we noticed that each request you do to CH API through the Web Client SDK will cost you some time which depends on your environment status at that time, with more requests you run, more time your users will wait for your API response.
In another post, I'll provide some workarounds and enhancement tips that you can use to enhance your API requests, but in this post I'll focus on a functionality that can save you many requests to Sitecore CH, it called "Aggregates".
You can access Aggregates from the Manage Menu, as you can see from the following screenshot:
With aggregates, you can define a configuration in Sitecore, for your main Entity (the entity you want to retrieve) with all its needed related relations, in our case, as example we need to get M.Asset entity, then, we need other entities related to this entity, and for each one we need an API call, which was bad for the application performance. so, using aggregates, you can define an aggregate in CH, define you entities and related entities in a JSON configuration form, and you will get a URL format which you can call in your code to get you're needed data.
you can find more information and example of how the configuration look like if you click here. Now, After you defined your aggregates, you can call the aggregates using the following API format:
https://YourEnvDomain/api/aggregates/YourAggregateName/YourEntityId
And you check the provided Json response and verify that all the information you need has been retrieved using one single request.
Now the question is, How you can call this from code or using web client SDK? the unfortunate news here that there is no specific API you can use to get the data modeled and ready for your use, you can to build your own models and map the data, you can use some online model builder which you can provide your Json response and they will generate the models for you and after that you can just clean your model per the needed data.
Here is how you can call aggregates to get the response result:
Hope this helped you, if you have any suggestions or questions, please reach out by comment or by email.
No comments:
Post a Comment