Monday, 21 December 2020

Sitecore Content Hub :: Passing Data to Script from External System

If you worked with Sitecore Content Hub you may cross the need of scheduling a trigger for some scripts you have running in Content Hub, and you probably found that Sitecore Content Hub doesn't offer a schedule tasks for running scripts, so you need to integrate with external system, and Azure function is one of the external systems/services that you could use, in this post, I will show how you can trigger a script in Content Hub from azure function as well as how you can pass parameters into the script. keep reading! 




First of all you should know that each script in Sitecore Content Hub has a URL, you can go to the scripts list, find your targeted script and click on [share URL], then copy the URL, this will be the URL that you should use in your POST request, see the following screenshot for more information:




In order to execute this script from external source you can use as example Postman or azure function, check the following screenshot from Postman, notice that you need to pass X-Auth-Token in your POST request header to Content Hub to allow the request: 




If you need to pass some parameters to your script from your external source, you can use that using the body part, you need to use Json format for the body and pass your needed info, here is a screenshot for more information:



But How you can get these in your script code? that should be easy couple of lines, in your script Context, there is a Data object that you can use to get all these passed parameters, see the following for more information:  



Same approach applies when your external system is azure function, if you need a schedule task (CRON Job), you can use azure function Timer Function to accomplish this, also, you can pass data through your request body/content, see the following for more information: 



Hope the above helped, if you have any question, feel free to comment or send me an email.

No comments:

Post a Comment