Fix a bug in documents API processing