Developer Guide
This is the API documentation for MetaDefender Cluster API Gateway Public API. If you would like to evaluate or have any questions about this documentation, please contact us via our Contact Us form.
How to Interact with MetaDefender Cluster API Gateway using REST API
MetaDefender Cluster API Gateway is used to submit files for analysis, retrieve scan results, manage file processing, download processed files, and manage file batches. OPSWAT recommends using the JSON-based REST API. The available methods are documented below.
Note: MetaDefender Cluster API doesn't support chunk upload, however is recommended to stream the files to MetaDefender Cluster API Gateway as part of the upload process.
File Analysis Process
MetaDefender Cluster is a system with multiple components that work together to utilize the power of multiple MetaDefender Core instances. The system is designed to handle large volumes of files and provide high throughput for file analysis. The system can be deployed in a distributed manner, allowing for horizontal scaling and load balancing across multiple MetaDefender Core instances.
Below is a brief description of the API integration flow:
Upload a file for analysis to MetaDefender Cluster API Gateway (
POST /file), which returns thedata_id: File Analysis.The following method can be used to retrieve the analysis report:
- Polling: Fetch the result with previously received data_id (
GET /file/{data_id}resource) until scan result belonging to data_id doesn't reach the 100 percent progress_percentage: (Fetch analysis result)
Note: Too many data_id requests can reduce performance. It is enough to just check every few hundred milliseconds.
- Polling: Fetch the result with previously received data_id (
Retrieve the analysis results anytime after the analysis is completed with hash for files (md5, sha1, sha256, sha512) by calling Fetch analysis result by hash.
- The hash can be found in the scan results
Retrieve processed file (sanitized, redacted, watermarked, etc.) after the analysis is complete.
Note: Based on the configured retention policy, the files might be available for retrieval at a later time.
OPSWAT provides some sample codes on GitHub to make it easier to understand how the MetaDefender REST API works.
Auth
Authentication APIs
User authentication is done via username & password.
Login
Initiate a new session. Required for using protected REST APIs.
OK
Invalid credentials
Unexpected event on server.
Logout
Destroy session for not using protected REST APIs.
OK
Bad Request.
Invalid user information.
Unexpected event on server.
Analysis
File analysis APIs
Submit each file to MetaDefender Cluster API Gateway individually or group them in batches. Each file submission will return a data_id which will be the unique identifier used to retrieve the analysis results.
Note: MetaDefender API doesn't support chunk upload. You shouldn't load the file in memory, is recommended to stream the files to MetaDefender Cluster API Gateway as part of the upload process.
Analyze File (Asynchronous mode)
Scanning a file using a specified workflow. Scan is done asynchronously and each scan request is tracked by data id of which result can be retrieved by API Fetch Scan Result.
Note: Chunked transfer encoding (applying header Transfer-Encoding: Chunked) is not supported on
/fileAPI. API Gateway only accepts file uploads with a known content length and a content type ofapplication/octet-stream
Successful file submission
Invalid user information or Not Allowed
Content-Length header is missing from the request.
Body input is empty.
Unexpected event on server.
Server is too busy. Try again later.
Fetch Analysis Result
Retrieve scan results.
Scan is done asynchronously and each scan request is tracked by a data ID.
Initiating file scans and retrieving the results need to be done using two separate API calls.
This request needs to be made multiple times until the scan is complete.
Scan completion can be traced using scan_results.progress_percentage value from the response.
Note: The REST API also supports pagination for archive file result. A completed response description with archive detection:
- extracted_files: information about extracted files
- files_extracted_count: the number of extracted files
- files_in_archive: array of files in archive
- detected_by: number of engines reported threat
- scanned_with: number of engines used for scanning the file
- first_index: it tells that from which file (index of the file, 0 is the first) the result JSON contains information about extracted files. (default=0, min=0)
- page_size: it tells how many files the result JSON contains information about (default=50, min=0, max=2000). So by default, the result JSON contains information about the first 50 extracted files.
- worst_data_id: data id of the file that has the worst result in the archive
- scan_results
- last_file_scanned (stored only in memory, not in database): If available, the name of the most recent processed file
Entire analysis report generated by MetaDefender Core
Bad Request (e.g. header is invalid, apikey is missing or invalid, parameter value is invalid or out of range, etc).
The user has no rights for this operation.
Unexpected event on server.
Fetch Analysis Result By Hash
Retrieve analysis result by hash
Get information of file
Invalid hash format
Fetching Available Analysis Rules
Retrieve all available rules with their custom configurations. Fetching available processing rules.
Returns the list of available rules.
Unexpected event on server.
Download Sanitized Files
Retrieve sanitized file based on the data_id
Returns the sanitized content.
Requests resource was not found.
The user has no rights for this operation.
Unexpected event on server.
Download either sanitized files or DLP processed files
Retrieve sanitized file based on the data_id.
In case there's no sanitized file, and DLP processed file is available, user will retrieve DLP processed file.
Returns the sanitized or DLP processed content.
File could not be found
The user has no rights for this operation.
Unexpected event on server.
Cancel File Analysis
When cancelling a file analysis, the connected analysis (e.g. files in an archive) that are still in progress will be cancelled also.
The cancelled analysis will be automatically closed.
Analysis was sucessfully cancelled.
Bad Request (e.g. header is invalid, apikey is missing or invalid, parameter value is invalid or out of range, etc).
Invalid user information or Not Allowed
Data ID not found (invalid id) or Requests resource was not found
The user has no rights for this operation.
Unexpected event on server.
Fetch the Top 100 Extraction Errors in an Archive
Returns up to 100 extraction errors found while processing the archive identified by data_id, including errors from nested archives.
The response includes:
total: Number of archives (root and nested) that reported extraction errors.root_archive: Extraction error details for the top-level archive. Omitted if no root-level errors exist.nested_archives: Extraction error details for nested archives.
If no extraction errors are found:
totalis 0.nested_archivesmay be empty.root_archivemay be omitted.
Extraction error information for the specified archive.
Invalid request (e.g. malformed data_id or bad query parameters).
Requests resource was not found.
The user has no rights for this operation.
The file is still being processed; extraction errors not finalized yet.
Unexpected event on server.
Query webhook status
Prior to being notified when webhook mode is enabled, the client can request MetaDefender Cluster API Gateway for the file processing webhook status at any time.
Webhook status is fetched successfully.
Bad Request (e.g. header is invalid, apikey is missing or invalid, parameter value is invalid or out of range, etc).
Invalid user information or Not Allowed
Requests resource was not found.
Unexpected event on server.
Batch
Group the analysis requests in batches. Supported with endpoints: MetaDefender Cluster API Gateway.
Initiate Batch
Create a new batch and retrieve the batch_id
Batch created successfully.
Bad Request (e.g. header is invalid, apikey is missing or invalid, parameter value is invalid or out of range, etc).
Invalid user information or Not Allowed
Unexpected event on server.
Close Batch
The batch will be closed and files can no longer be added to the current batch.
Batch successfully closed.
Bad Request (e.g. header is invalid, apikey is missing or invalid, parameter value is invalid or out of range, etc).
Invalid user information or Not Allowed
Requests resource was not found.
Unexpected event on server.
Status of Batch Analysis
Retrieve status report for the entire batch
Batch progress paginated report (50 entries/page).
Bad Request (e.g. header is invalid, apikey is missing or invalid, parameter value is invalid or out of range, etc).
Invalid user information or Not Allowed
Requests resource was not found.
Unexpected event on server.
Download Signed Batch Result
Download digitally signed status report for the entire batch
Signed batch result and certificate are sent back in response body (YAML format).
Bad Request (e.g. header is invalid, apikey is missing or invalid, parameter value is invalid or out of range, etc).
Invalid user information or Not Allowed
Requests resource was not found.
Unexpected event on server.
Cancel Batch
When cancelling a batch, the connected analysis that are still in progress will be cancelled also.
The cancelled batch will be closed.
Batch cancelled.
Bad Request (e.g. header is invalid, apikey is missing or invalid, parameter value is invalid or out of range, etc).
Invalid user information or Not Allowed
Batch not found (invalid id)
Unexpected event on server.
License
Retrieve the current license information.
Get current license information
Fetch details about the longest expiry active license among all activated licenses.
Information about the licensed product (product type, number of activations, deploymentId, expiration date and days left)
Invalid user information or Not Allowed
The user has no rights for this operation.
Unexpected event on server.
Stats
Health check and statistics about MetaDefender Core instance usage.
Engine Status
Return the status of the latest engines between the MetaDefender Core instances.
An array with all the engines and their details.
Instance Status Overview
Retrieve status details of all available MetaDefender Core instances.
Status details of MetaDefender Core instances.
Invalid user information or Not Allowed
The user has no rights for this operation.
Get health check status
Fetch current status of system health.
System is currently healthy.
Unexpected event on server.
System is currently unhealthy.