I'm working with Hikvision Access Control devices using the ISAPI endpoint:
and querying events using
Then I loop:
Then incrementing position or serial range in a loop.
Then:
Then incrementing position or serial range in a loop.
/AccessControl/AcsEvent?format=jsonand querying events using
AcsEventCond.Problem
I'm experiencing missing records when retrieving logs. Specifically:- Some
serialNovalues are skipped (gaps in sequence) - These skipped records are being logged in my system as "missing"
- However, I’m not sure if:
- The device actually lost those records
- OR the API is not returning them due to how I'm querying
My Setup
- Using PHP (cURL) with Digest Auth
- Querying with:
searchIDsearchResultPositionmaxResults = 30major = 0 (MAJOR_ALL)
- Then filtering in code for:
major == 5 (MAJOR_EVENT)- specific
minorvalues (valid access events)
Retrieval Logic
I have two modes:1. First run → Time-based
Code:
{
"startTime": "...",
"endTime": "..."
}
2. Subsequent runs → Serial-based
Code:
{
"beginSerialNo": lastSavedSerial,
"endSerialNo": lastSavedSerial + 29
}
- Increment serial range OR
searchResultPosition - Collect results
- Track all returned
serialNo - Log missing ones like this:
Code:
$expected = range($begin, $maxRetrieved);
$missing = array_diff($expected, $retrieved);
Issue Details
- I consistently see gaps in serial numbers, e.g.:
Code:
1001
1908
...
- These gaps are:
- Logged as missing in my system
- Sometimes not visible in device Web UI either
- Sometimes appear later (inconsistent)
Questions
- Are serialNo values guaranteed to be continuous in Hikvision devices?
- Or are gaps expected due to internal behavior?
- Is it safe to rely on:beginSerialNo / endSerialNo for pagination?
- Would switching to time-based pagination only be more reliable?
- Does using:major = 0 (ALL) cause pagination to be filled with unrelated events (alarms, system logs), thus hiding access events?
- Has anyone experienced:
- Database gaps
- Missing records via API but not UI (or vice versa)
Code Snippet (Core Loop)
Initial Request Body
Code:
$body = [
'AcsEventCond'=> [
"searchID" => $this->generateGUID(),
"searchResultPosition" => 0,
"maxResults" => 30,
"major" => 0,
"minor" => 0,
]
];
Serial-Based (Subsequent Runs)
Code:
$body['AcsEventCond']['beginSerialNo'] = (int)$intSerial;
$body['AcsEventCond']['endSerialNo'] = (int)$intSerial + 29;
Code:
$intPageBeginSerial += 30;
$body['AcsEventCond']['beginSerialNo'] = $intPageBeginSerial;
$body['AcsEventCond']['endSerialNo'] = $intPageBeginSerial + 29;
$body['AcsEventCond']['searchResultPosition'] = 0;
Looking for Advice
If you've worked with Hikvision ISAPI:- How do you reliably paginate logs?
- Do you trust
serialNoat all? - Best practice to avoid missing records?