YouTube Integration

YouTube is the world’s second-biggest search engine behind Google. People search for how-to videos, reviews, and to see products and services in action. By integrating YouTube with Sitecore Content Hub via webMethods.io there is a simplified method of uploading final and approved video content.

logos of sitecore youtube and webmethods

By integrating Sitecore Content Hub with YouTube via webMethods.io users can easily upload their video content to YouTube. This integration with YouTube reduces the bandwidth costs of streaming video content directly from the Cloud.

Note

This connector is an illustrative example of a generic connector between Sitecore Content Hub and any external system (for example, YouTube). It aims to help developers better understand how to create their own custom connector.

Warning

This connector is for illustration purposes only. It will not be supported for all versions of Sitecore Content Hub.

webMethods.io are market leaders and recognized experts in integration with iPaaS, hybrid integration, APIs, B2B, cloud integration, and on-premises integration offerings.

webmethods diagram role

Example

In the following example, a Video asset will be uploaded to YouTube when the Type is modified to Social Media. Social Media is a user-created value for Type property.

Navigate to the Manage page and scroll down to Triggers:

triggers is found under manage

Open the Triggers page which displays the Triggers Overview. On the Triggers Overview page, click on the new trigger button button:

triggers overview

General settings

On the General tab of the new Trigger complete the form with the following details:

  • Name is a mandatory text field.

  • Description is an optional text field

  • Objective has three options on the entity event that the trigger will fire:

    • Entity creation
    • Entity modification
    • Entity deletion
  • Execution type:

    • In process
    • In background

    In this example, the trigger is to run In background:

general setting new trigger

Once the required details have been input click on the Conditions tab:

conditions tab option shown in the general settings.

Conditions

The Conditions tab requires that an entity definition is chosen to be used for the Trigger.

Click on the Add definition button:

add definition button

Search for and select the required definition from the returned list. In this example, the needed definition is Asset (M.Asset):

search for and select the needed definition

Once the definition has been input, the condition or conditions can be set by clicking on the + condition button:

add condition to the definition selected

After clicking to add a condition:

  • Select the property of the entity to be the subject of the condition. In this example two conditions are created with the properties of Asset Media (AssetMediaToAsset) and Type (AssetTypeToAsset):

  • The value or state requires a choice from the dropdown menu of:

    value or state of the condition

    In this example, current value is chosen for both conditions.

  • The available Clauses / Operators for the conditions are. In this example, both the conditions use the contains clause:

    options for clause or operator

  • The subject of the condition is selectable from the values of the entity property. In this example the values of Mp4 for Asset media and Social Media for Type are selected.

adding conditions

Once the condition or conditions have been inserted, click on the Actions tab.

completed conditions tab

Actions

On the Actions tab, click on the Manage actions button:

manage actions button

On the new modal that lists the existing actions, click on the New action button:

new action modal

A new modal form will open in which the details of the new action are to be input:

  • Name is a mandatory text field.
  • Label is an optional text field.
  • Action type is a drop down option with the following values:

    • Action script
    • API call
    • Azure Event Hub
    • Azure Service Bus
    • M Azure Service Bus
    • Print Entity Generation
    • Reporting channel
    • Start state machine

    As this is an integration with the YouTube API, the action type is API call:

new modal form

Selecting the API call action type changes the form, with new fields shown:

api call action type form changes

  • Method with the choice of:

    • POST

    • PUT

    • GET

    In this example, the POST method is to be used.

  • API URL, the API required is found when creating a webhook in the webMethods.io workflow. This URL is available once a workflow has been created, and a webhook is covered in more detail in the next section.

  • Timeout can be set for the API call, after which the call fails if no response returns. The timeout values are expressed in seconds:

    img

Input the required values for the new Action and then create the URL via the configuration of a webhook in webMethods.io:

create a new action

By creating workflows in webMethods.io, Integration tasks can be automated.

Creating the first workflow

  1. Select or add a project via the add new project

  2. Provide a name for the new project:

    add new project name

  3. To create the new workflow, click on the new workflow button.

  4. On the Workflow option, click on the create new workflow button button:

    create new workflow button

  5. On the workflow, click on the top of the start point of the workflow and select the settings icon:

    settings on the start point of the workflow

  6. On the Trigger modal select the Webhook option:

    webhooks on trigger modal

  7. On the Webhook, use the copy icon to copy the URL.

    webhook url

  8. The complete process is as follows:

    webhook process url complete

    Now return to the Action and paste in the URL copied from the Webhook.

    And proceed to save the new action via the save button button.

  9. The newly created Action can then be added to the Trigger using the Add action button located under Post actions:

    add actions under post actions

  10. The Trigger can now be saved. Click on one of the ![save and save and close buttons] buttons.

  11. Before leaving the Trigger, activate the trigger:

    activate trigger button

The complete process of adding the Action and activating the Trigger is as follows:

add action and activate trigger process

The default headers of this action are subsequently pulled into the action.

Configuring Webhook

In this example, the Sitecore Content Hub entity modification triggers an action. i.e., an API call to webhook endpoint exposed by webMethods.io.

On the workflow, click on the top of the start point of the workflow and select the settings icon: settings on the start point of the workflow

Activate the Webhook Payload:

activate the webhook payload

In the Body of the Webhook payload, enter the payload. The most basic payload is:

{ "saveEntityMessage": { "TargetId": XXXXX} }

In this example: { "saveEntityMessage": { "TargetId": 13522} }

entity id

Where the value of the TargetId is the entity id of the asset to be uploaded:

body of the webhook payload

Click on Next:

click on next

The payload is displayed. If correct, click on Done:

click on done

The complete configuration of the Webhook is as follows:

webhook configuration process

HTTP Request

webMethods requires additional information about the entity by making HTTP request to content hub. The URL of request is: {contentHubEndpoint}/api/entities/{TargetId}

​ e.g. https://sitecoreInstance.com/api/entities/11915

Sitecore Content Hub responds to this request by returning the entity details in JSON format, e.g., the EntityResponse.json.

The JSON file contains the relevant entity information required for download and storage i.e., URL and filename.

To create an HTTP Request, search for an HTTP Request component and pull this component into the workflow:

http request component

The new HTTP Request auto-links with the Webhook configuration created previously.

In the top left corner of the HTTP request component click on the settings icon http request settings:

settings of http request

A new modal opens which allows a custom name to be given to the HTTP Request:

http request name

On the next modal the Action of the HTTP Request can be configured with the Incoming Data from the Webhook:

http request configuration

Enter the URL of the Sitecore Content Hub instance into the URL field on the Action Configure side of the form:

url field

On the Incoming Data side click on $request - Webhook field to extend this field and show the sub-values via the downward-pointing arrowhead:

request webhook folder

Again on the Incoming Data side click on the body field to extend out thereby showing the sub-values via the downward-pointing arrowhead:

body field on incoming data

Underneath the extended body field extend SaveEntityMessage to show the TargetId. The TargetId is generated from the webhook:

target http request

Click on the TargetId and this target id is appended to the URL previously included in the Action Configure field:

target request-id added to the url

On the Action Configure section click on the headers button button underneath Headers field:

headers action configure

The values required for the Headers object are a Key-Value pair.

headers object

The Key is X-Auth-Token.

The Value is the API token generated in Sitecore Content Hub.

Token Value

Create a token for use in the HTTP Request, navigate to Users under Manage.

On the Superuser who is building the integration, click on the key icon.

Click the Create button to generate the API token and once the new Token is created, click on Copy token:

generating a token

Once the Token has been inserted into the header, the HTTP Request process is complete:

http request process completed

The HTTP Request can then be tested to check that the values are correct. Click on the Test button and a statusCode is returned to show success or failure of the HTTP Request:

testing the http request

Download

webMethods.io executes the Download File part of the workflow. The video file is downloaded using the URL extracted from the HTTP Request workflow component. The video file is saved locally in the webMethods.io workflow storage with filename retrieved from the HTTP Request response.

Search for a Download File component and drag this component in the workflow.

Once the component is included in the workflow, click on the Settings option in the top left corner download component.

A custom name can be entered, click on Next:

download component in workflow

Click in the Add URL field and then extend the HTTP Request in the Incoming Data section to display the responseObject.

Extend the renditions field and then extend the downloadOriginal field before selecting the href to complete the Add URL field:

include href as url

Once the URL has been added the scroll back to the properties object and select the filename incoming data into the File Name Action configuration:

filename property

Click on Next.

The Download File component can then be tested using the Test button:

download component testing

Upload File

If the output includes the correct download original URL, the correct filename and the filepath (the video file is saved locally in the webMethods.io workflow storage with the filename extracted) then click on Done. The file downloaded from the Download file workflow component is now uploaded to YouTube. The file name and file path are extracted from the Download file workflow component output.

Upload requires OAuth tokens associated with the target YouTube account. They need to be obtained separately before configuring workflow in webMethods.io. More details can be found at https://developers.google.com/identity/protocols/OAuth2WebServer.

Search for a YouTube component and drag this component into the webMethods.io workflow:

youtube component being included in the workflow

Once the YouTube component has been included in the workflow, select the Settings option on the component settings on youtube component.

On the new modal, click on the plus button displayed at the end of the Authorize YouTube field to display the fields to define the YouTube account details:

youtube settings

Complete the forms with the details from the Google API account and the required Access and Refresh tokens described at https://developers.google.com/identity/protocols/OAuth2WebServer.

The Refresh URL to be used is https://www.webmethods.io.

The Grant Type is authorization_code.

Once the details have been inserted click on Save:

completing the youtube account

On the new modal extend the Download File in the Incoming Data section:

  • Link the filepath to the Source File Path field in the Action Configure section.

  • Link the filename to the Title field in the Action Configure section.

  • Link the filename to the Description field in the Action Configure section.

configure the incoming data

Once complete, click on Next.

The configuration of the YouTube component can then be tested.

If the Output is satisfactory click on Done:

youtube testing

Once the YouTube component has been saved, it can be joined to the stop button workflow:

connect the youtube and save the workflow

In this example, the video Asset is modified to include the Type of Social Media in Sitecore Content Hub. This modification fires the Trigger in Sitecore Content Hub, which activates the Webhook in webMethods.io workflow. The workflow downloads the video from Sitecore Content Hub and uploads the video to YouTube.

modify the entity and refresh youtube studio

Note

Metadata fields inside Sitecore Content Hub can be be used for YouTube’s Title, Description, and Tags fields, enabling users to provide the SEO-optimized content they need to make sure their videos are found.