Get validation hooks
Retrieve all validation hooks configured for the current environment. Only the current version of each hook is returned.
Authorization
accessToken JWT Bearer Token authentication for API access
In: header
Query Parameters
Filter by hook type.
Value in
- "import_pre_validation_hook"
- "import_post_validation_hook"
Response Body
application/json
application/json
curl -X GET "https://example.com/knowledge/contentmgr/v4/import/config/hooks"{ "hooks": [ { "hookID": 10050, "name": "Dept-Tag-Validator", "type": "import_post_validation_hook", "fileObject": { "fileID": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "createdDate": "2024-03-15T10:30:00.000Z", "createdBy": { "id": "500", "userName": "jdoe", "firstName": "John", "lastName": "Doe" }, "modifiedDate": "2024-03-20T14:15:00.000Z", "modifiedBy": { "id": "501", "userName": "asmith", "firstName": "Alice", "lastName": "Smith" }, "version": { "versionID": 2, "isCurrent": true }, "file": { "name": "check_dept_tags_v2.js", "content": "dmFyIGl0ZW0gPSBjb250ZXh0Lml0ZW07", "contentUrl": "https://api.egain.cloud/knowledge/contentmgr/v4/import/config/hooks/10050/version/2" } } }, { "hookID": 10051, "name": "Filename-Sanitizer", "type": "import_pre_validation_hook", "fileObject": { "fileID": "9b2c3d4e-5717-4562-b3fc-2c963f66afa6", "createdDate": "2024-03-10T09:00:00.000Z", "createdBy": { "id": "500", "userName": "jdoe", "firstName": "John", "lastName": "Doe" }, "modifiedDate": "2024-03-10T09:00:00.000Z", "modifiedBy": { "id": "500", "userName": "jdoe", "firstName": "John", "lastName": "Doe" }, "version": { "versionID": 1, "isCurrent": true }, "file": { "name": "clean_filenames.js", "content": "ZnVuY3Rpb24gdmFsaWRhdGUuLi4=", "contentUrl": "https://api.egain.cloud/knowledge/contentmgr/v4/import/config/hooks/10051/version/1" } } } ]}Create Import Job POST
# Import Content ## Overview This API initiates a bulk content import operation from Data Sources. It creates an asynchronous import job that processes content in the background, allowing you to import large volumes of content without blocking your application. ## Pre-requisties 1. Content in Data Source needs to be in this format: [Guide to Data Import Format](https://apidev.egain.com/developer-portal/guides/ingestion/data-import-format-guide/) ## How It Works 1. **Job Creation**: The API creates an import job and returns a unique job ID 2. **Content Processing**: Content is processed asynchronously in the background 3. **Status Monitoring**: Use the job ID to monitor progress via the Status API 4. **Completion**: Job completes when all content is processed or errors occur **Note:** After a successful import, please allow for a brief delay before the content is fully available for use. The system's search service synchronizes all new and updated content every 30 minutes. ## Supported Operations - **Import**: Add new content to the knowledge base - **Update**: Modify existing content ## Data Source Types - AWS S3 bucket - Shared file path ## Best Practices - **Scheduling**: Use scheduleTime for off-peak imports to minimize system impact. Please note that jobs can only be scheduled for a maximum of 7 days from the current date and time. - **Monitoring**: Regularly check job status and logs for any issues - **Error Handling**: Review failed items and retry with corrections ## Job Timing Controls - **scheduleTime.stopDate**: Defines a specific date time to cease operations regardless of progress (e.g., "Stop exactly at 5:00 PM").
Create validation hook POST
# Create Validation Hook ## Overview 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. ## Usage Requirements To ensure successful hook creation and execution, please adhere to the following: - **Content Encoding**: The `fileObject.file.content` property must be a **Base64 encoded** string of your JavaScript logic. - **File Naming**: The filename should use the `.js` extension. - **Logic Return**: Your script must return a `result` object containing a boolean `success` property. - **Size Limit**: The encoded content must not exceed 1.5MB. ## Hook Types - **Pre-Validation Hooks (`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. - **Post-Validation Hooks (`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. ## Execution Environment Hooks run in a secure, sandboxed JavaScript environment (ES5/ES6). - **Prohibited**: File system access (`fs`), network access (HTTP requests), and module loading (`require`). - **Supported**: Standard JavaScript logic, `console.log()` for debugging, and a specialized `helpers` utility library for safe data access. ## Implementation Examples ### Example: Pre-Validation Logic This example demonstrates checking that every article contains a specific metadata field. ```javascript // 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; ``` ### Example: Post-Validation Logic This example checks the standard validation results. If there are standard errors, it logs them and fails the job explicitly. ```javascript 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; ``` ## Further Documentation For more detailed context on available objects (`data`, `metadata`, `helpers`) and best practices, refer to the [Validation Hook Guide](https://apidev.egain.com/developer-portal/guides/ingestion/validation-hook-guide/#example-pre-validation-logic).

