This API allows you to create custom JavaScript-based validation hooks that execute during the bulk content ingestion process. Validation hooks enable organizations to enforce specific business rules, verify metadata compliance, and perform complex data integrity checks that go beyond standard system validation.
To ensure successful hook creation and execution, please adhere to the following:
fileObject.file.content property must be a Base64 encoded string of your JavaScript logic..js extension.result object containing a boolean success property.import_pre_validation_hook): These execute before the standard system validation. They are ideal for enforcing custom business rules, such as ensuring all articles contain specific metadata.import_post_validation_hook): These execute after the standard system validation. They have access to the validationResults from the system check, allowing you to block an import based on the severity of errors found.Hooks run in a secure, sandboxed JavaScript environment (ES5/ES6).
fs), network access (HTTP requests), and module loading (require).console.log() for debugging, and a specialized helpers utility library for safe data access.This example demonstrates checking that every article contains a specific metadata field.
// Initialize result
var result = { success: true };
// Verify data exists
if (helpers.hasField(data, 'articles') && helpers.isNotEmpty(data.articles)) {
var invalidArticles = [];
for (var i = 0; i < data.articles.length; i++) {
var article = data.articles[i];
if (!helpers.hasField(article, 'name')) {
invalidArticles.push({ index: i, issue: "Missing name" });
continue;
}
// Custom Rule: Check if 'description' exists in metadata
if (!helpers.hasField(article, 'metadata') ||
!helpers.hasField(article.metadata, 'description') ||
helpers.isEmpty(article.metadata.description)) {
invalidArticles.push({
name: article.name,
issue: "Missing required description metadata"
});
}
}
if (invalidArticles.length > 0) {
result = {
success: false,
error: 'Articles failed custom metadata validation',
details: { count: invalidArticles.length, errors: invalidArticles }
};
}
}
result;
This example checks the standard validation results. If there are standard errors, it logs them and fails the job explicitly.
var result = { success: true };
// Check if standard validation found errors
if (helpers.hasField(validationResults, 'errors') && validationResults.errors.length > 0) {
var errorCount = validationResults.errors.length;
console.log('Standard validation found ' + errorCount + ' errors.');
var errorTypes = {};
validationResults.errors.forEach(function(err) {
var type = err.type || 'unknown';
errorTypes[type] = (errorTypes[type] || 0) + 1;
});
result = {
success: false,
error: 'Standard validation failed with ' + errorCount + ' errors.',
details: {
summary: errorTypes,
firstError: validationResults.errors[0].message
}
};
}
result;
For more detailed context on available objects (data, metadata, helpers) and best practices, refer to the Validation Hook Guide.
Hook created.
Bad Request
{- "type": "import_post_validation_hook",
- "fileObject": {
- "file": {
- "name": "check_dept_tags.js",
- "content": "dmFyIGl0ZW0gPSBjb250ZXh0Lml0ZW07"
}
}
}{- "code": "400-101",
- "developerMessage": "Unsupported query parameter(s) supplied: '<query_parameter>'."
}