Error Cannot access a closed Stream, when editing a file

I am trying to add data to the first row in the table, but I get an error

error: HTTP code 403. answer: {“status”:1,“statusCode”:403,“error”:{“message”:“Cannot access a closed Stream.”,“hresult”:-2146232798,“data”:{}}}

can you tell me how to solve this problem?

<?php define('ONLYOFFICE_API_URL', 'http://localhost/api/2.0/authentication.json'); define('ONLYOFFICE_FILES_URL', 'http://localhost/api/2.0/files/@share'); define('USERNAME', 'email'); define('PASSWORD', 'pwd'); function sendCurlRequest($url, $method = 'GET', $postData = null, $headers = []) { $curl = curl_init(); $options = [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => $method, CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYPEER => false ]; if ($postData) { $options[CURLOPT_POSTFIELDS] = json_encode($postData); } curl_setopt_array($curl, $options); $response = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if (!in_array($httpCode, [200, 201])) { die("error: HTTP code $httpCode. answer: " . print_r($response, true)); } return json_decode($response, true); } // get token function getOnlyOfficeToken() { $authData = [ 'userName' => USERNAME, 'password' => PASSWORD ]; $response = sendCurlRequest(ONLYOFFICE_API_URL, 'POST', $authData, ['Content-Type: application/json']); if (!isset($response['response']['token'])) { die("error: " . print_r($response, true)); } return $response['response']['token']; } function getOnlyOfficeFiles($token) { return sendCurlRequest(ONLYOFFICE_FILES_URL, 'GET', null, ["Authorization: Bearer $token"])["response"]["files"] ?? []; } // edit function startEditFile($token, $fileId) { $url = "http://localhost/api/2.0/files/file/$fileId/startedit"; $postData = ['editingAlone' => true, 'doc' => '']; return sendCurlRequest($url, 'POST', $postData, ["Authorization: Bearer $token", 'Content-Type: application/json']); } // update function updateSpreadsheet($fileId, $token, $data) { $url = "http://localhost/api/2.0/files/file/$fileId"; $headers = [ "Authorization: Bearer $token", 'Content-Type: application/json' ]; echo "URL: $url\n"; echo "Headers: " . print_r($headers, true) . "\n"; echo "Data: " . json_encode($data) . "\n"; return sendCurlRequest($url, 'PUT', $data, $headers); } // save function saveFileChanges($token, $fileId) { $url = "http://localhost/api/2.0/files/file/$fileId/saveediting"; $postData = [ 'fileExtension' => 'xlsx', 'forcesave' => true ]; $response = sendCurlRequest($url, 'PUT', $postData, [ 'Authorization: Bearer ' . $token, 'Content-Type: application/json' ]); return json_decode($response, true); } $token = getOnlyOfficeToken(); if (!$token) die("error."); $files = getOnlyOfficeFiles($token); if (empty($files)) die("error."); echo "list:\n"; foreach ($files as $file) { echo "ID: {$file['id']}, name: {$file['name']}\n"; } $fileId = $files[0]['id'] ?? 20; echo "select ID: $fileId\n"; $startEditResult = startEditFile($token, $fileId); var_dump($startEditResult); $data = [ 'cells' => [ ['row' => 1, 'col' => 1, 'value' => 'New Value 1'], ['row' => 1, 'col' => 2, 'value' => 'New Value 2'] ] ]; //$data = '22'; $response = updateSpreadsheet($fileId, $token, $data); var_dump($response); $saveResult = saveFileChanges($token, $fileId); var_dump($saveResult); ?>

Hello @kato
Sorry for the late reply.
Please clarify your Workspace version. Do I understand it right that you’re using ’ Start file editing’ and ’ Save file edits’ methods in your API requests?

Is the situation reproducible with any files or specific ones?