Creating and publishing a Content Hub custom connector – Func app integration testing

In my previous blog post, I covered how to configure your Function app for debugging within your local development environment. In this blog post, we are going to carry on from where I left and look at how to start doing some end-to-end integrations tests with your Func app.

Getting your Sitecore Content Hub ready

As explained in my YouTube video – 3 Content Hub: API call action set-up, you need to set up an API call action within Content Hub. This is the action that will trigger the execution of our Func app.

Below are steps to follow to accomplish this.

  • Using Manage -> Actions menu, click on ‘New action’ button to launch the create New action popup, similar to the one shown below.
  • Populate all the required details as shown above:
    • Name: Specify the name of the API call
    • Label: Specify the display label for the API call
    • Type: Select API call from the Type dropdown list, similar to one shown below
    • Method: Select POST. This means a POST request will be sent to our Func app when this action is executed
    • API URL: Specify your Func app URL. I will provide further details later on how to obtain your Func app URL in your local Dev environment
    • Timeout: Specify a value of timeout in milliseconds. Content Hub provide a choice of 30, 60, 90, 120, 300 and 600 as of writing this blog
    • Headers: Add any custom HTTP Headers for the POST request. In my case, I have a custom X-Api-Key which I am using to specify the Func app Api key
    • Values: Add any additional meta data that you want passed into the Func app.

Getting your local Dev Func app ready for testing and debugging

As explained in my previous blog, you need to ensure your local.settings.json has all the required application settings. This is to ensure we can establish an integration between Func app and your Content Hub instance.

Then you need to build your Visual Studio project and ensure you have no Build errors. You can do this using Build -> Rebuild solution option. Alternatively, right-click on your project, and select Rebuild

Your Visual Studio Output window will show Rebuild All succeeded message, similar to the one below.

Setting up Breakpoint within the code files

To be able to debug and step-into your code files, add the relevant Breakpoints on a particular line of code using Debug -> Toggle Breakpoint menu or F9 shortcut key. In my example below, I have togged a Breakpoint on line 32.

Start running your local Dev Func app in Debug mode

We are now ready to execute our local Dev Func app in debug mode. From Debug menu, click on Start Debugging menu or select F5 shortcut key.

This will launch a Func app runtime command window, similar to the one shown below:

Your local Dev Func app is now ready to process your POST requests. The URL is indicated using the arrow above. Remember earlier on we needed to configure the Content Hub API call URL, this will be the value to use. Copy and apply this in your Content Hub accordingly.

Triggering your local Dev Func app from Content Hub

As I demonstrated in my YouTube video – 1 Cloudflare Stream connector demo, I am triggering the API call using a custom button. In my use case, I have added this button to the Blog details page. Clicking on ‘Send to Cloudflare’ button, will trigger the local Func app.

You will notice the local Func app will have activated any Breakpoints you have set up within the Visual Studio project. This will allow you to step into any lines of code that you would like to inspect at debug-level.

Sample active Breakpoint with request Debug details

Below you can see my Breakpoint on line 32, where I am inspecting debug-level details of my POST request.

Next steps

In this blog post, we have explored how to prepare both your Sitecore Content Hub API call and your local Dev Function app for integration testing. We also looked at steps of configuring and triggering the Func app whilst in debug mode. Feel free to watch the rest of my YouTube playlist where I am demonstrating the end-to-end custom connector in action. Stay tuned.

Creating and publishing a Content Hub custom connector – Func app settings and debugging

Introduction

In my previous blog post, I covered how to set-up your Func app within Visual Studio. In this post, I would like to walk you through how to configure your Func app to allow you to run and debug it in your local development environement.

Func app local.settings.json file

Within your Visual Studio project, create local.settings.json file at the root of the project. A sample json file is shown below. This will be used to configure all the configuration settings to allow you to run and debug the Func app locally.

The local.settings.json file stores app settings and settings used by local development tools. Settings in the local.settings.json file are used only when you’re running your project locally.

Because the local.settings.json may contain secrets, such as connection strings, you should never store it in a remote repository.

DevOps best practices

Microsoft Azure portal func app application settings

Similarly, you will need to configure all the configuration setting on your Microsoft Azure portal for your test or production Func app instances.

Clicking on Configuration menu, then Application settings tab will launch the page similar to the one shown below.

Depending on your needs, these application settings can be managed manually or very easily automated using DevOps pipelines.

List of required application settings

Below is a complete list of the Func app application settings

  • cf_account_id your Cloudflare account identifier
  • cf_api_base_url your Cloudflare API base URL
  • cf_api_token your Cloudflare API token
  • cf_webhook_url your Cloudflare webhook URL
  • ch_base_url your Content Hub instance base URL
  • ch_client_id your Content Hub instance client identifier
  • ch_client_secret your Content Hub instance client secret
  • ch_create_publiclinks_script_id your Content Hub action scrip identifier for creating public links
  • ch_get_data_script_id your Content Hub action scrip identifier for getting data
  • ch_password your Content Hub integration user password
  • ch_username your Content Hub integration user username
  • funcapp_api_key your custom Func app API key configured within your Content Hub integration

Next steps

In this blog post, we have explored at how to configure your Function app application settings to allow you to run and debug it in your local development environment. We also looked at configuring them on your published Func app on your Microsoft Azure portal.

Feel free to watch the rest of my YouTube playlist where I am demonstrating the end-to-end custom connector in action. Stay tuned.