logo
logo

Best practices

To improve the usability and performance of triggers, follow these best practices.

  • Configure the condition at the trigger level rather than at the Azure Function level to avoid unnecessary execution time.

  • Use timeouts at the action level. Whenever an action fails or when the timeout is exceeded at the action level, the trigger is re-invoked. By default, the maximum retry count of a trigger is set to 3. You can change this by modifying the TriggersConfiguration setting in Sitecore Content Hub™.

  • To set up the API call action to invoke an Azure Function, use an HttpTrigger Azure Function and specify the URL of the function into the action. You can find this URL in the Azure portal where your Azure Function is deployed.

  • To validate the connection between Content Hub and the Azure Function, ensure to use the HEAD request header. You can configure this at the function level. When you click Test connection, a HEAD request is sent to the provided URL.

    public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "head", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
    {
    // Allow head request to test connectivity with the Markting Content Hub
      if (req.Method == HttpMethod.Head) return req.CreateResponse(HttpStatusCode.OK);
    }
  • When you select the Azure Service Bus as an action, the message (that is, the detailed event) from Content Hub is put on the Azure Service Bus queue for which connection details have been provided in the action.

  • Supported methods are GET, PUT and POST. Request headers are passed along for every request. When you use PUT or POST, the request body also contains a detailed overview of the event or message (SaveEntityMessage or DeleteEntityMessage). This is a serialized JSON string:

    • Example of SaveEntityMessage:

      {
          "saveEntityMessage": {
              "MessageId": 0,
              "IsNew": false,
              "TargetId": 6334,
              "TargetIdentifier": "FLikN0zW8EGZaaUQedirJA",
              "UserId": 6,
              "Version": 12,
              "TargetDefinition": "M.Asset",
              "ChangeSet": {
                  "Culture": "(Default)",
                  "PropertyChanges": [{
                      "Property": "ReleaseDate",
                      "Type": "System.DateTime",
                      "OriginalValue": "2017-12-04T08:17:59.178",
                      "NewValue": "2017-12-24T08:29:08.297Z"
                  }],
                  "RelationChanges": [],
                  "OriginalInheritsSecurity": true,
                  "NewInheritsSecurity": true,
                  "OriginalIsRootTaxonomyItem": false,
                  "NewIsRootTaxonomyItem": false
              },
              "TimeStamp": "2017-12-11T08:30:12.2817117Z",
              "EventType": "EntityUpdated"
          }
      }
    • Example of DeleteEntityMessage:

      {
          "deleteEntityMessage": "{\"MessageId\":0,\"TargetId\":7932,\"TargetIdentifier\":\"2iil0h79OUKZ3WmgaVCxiA\",\"TargetLabel\":\"497632384.mp4\",\"UserId\":7469,\"TargetDefinition\":\"M.Asset\",\"TimeStamp\":\"2017-12-07T16:24:44.769357Z\",\"EventType\":\"EntityDeleted\"}"
      }

Can we improve this article ? Provide feedback

IN THIS ARTICLE