Problem in callback is not triger

Hi,i have problem with callback is not trigger when change in Document
the configration is
const payload = {
document: {
fileType: “docx”,
key: “Khirz6x2Pvmd5”,
title: “sample5”,
url: “http://localhost:3001/sample.docx”,
},
documentType: “word”,
editorConfig: {
callbackUrl: “http://localhost:3001/track”,
},
};

and callback endpoint is
app.post(‘/track’, (req, res) => {
//res.sendFile(path.join(__dirname, ‘documents’, ‘sample.docx’)); // Adjust the path as needed
console.log(“is enter”);
var updateFile = function (response, body, path) {
if (body.status == 2)
{
var file = syncRequest(“GET”, body.url);
fs.writeFileSync(path, file.getBody());
}
response.write(“{"error":0}”);
response.end();
}
var readbody = function (request, response, path) {
var content = “”;
request.on(“data”, function (data) {
content += data;
});
request.on(“end”, function () {
var body = JSON.parse(content);
updateFile(response, body, path);
});
}
if (req.body?.hasOwnProperty(“status”)) {
updateFile(res, req.body, “/documents/”);
} else {
readbody(req, res, “/documents/”)
}

});

Hello @redha

It is not quite clear what means “callback is not trigger when change in Document”, can you elaborate? Do you mean simples changes made to the document or saving the document?

In general, I’d recommend checking out following documentation on callback handler:

I’ve set up an Express app listening on port 3001 with the endpoint /track to log any incoming requests. However, we only receive requests when a file is downloaded. No requests are sent when a file is saved or edited.

The issue is not about handling the callbackUrl as mentioned in the documentation—the problem is that we’re not receiving the requests at all.

Please enable debug level logging for Document Server and check logs for additional information. Document Server logs events such as processes of saving the file, so you will be able to check out whether Document Server sends anything to the callback after all.

To enable debug logging you need to access production.json config in C:\Program Files\ONLYOFFICE\DocumentServer\config\log4js directory, change "level": "WARN" to "level": "DEBUG" and then restart Document Server services in Windows Services to apply the change. Then reproduce the issue and check out logs in C:\Program Files\ONLYOFFICE\DocumentServer\Log.

i do this

and make restart to services after that

I navigated to the following folder path: C:\Program Files\ONLYOFFICE\DocumentServer\Log, but I did not find any errors in the logs. Below is my configuration:

document: {
      fileType: "docx",
      key: "Khirz6x2Pvmd5",
      title: "sample5",
      url: "http://Redha:3001/sample.docx",
    },
    documentType: "word",
    
    editorConfig: {
      forcesave: true,
      autosave: true,
      callbackUrl: "http://Redha:3001/track",
    }

The callbackUrl: "http://Redha:3001/track" is triggered only when the page loads. However, when I edit the document and the autosave occurs, the callback is not triggered.

Below is the implementation of my track endpoint:

app.post('/track', (req, res) => {
  //res.sendFile(path.join(__dirname, 'documents', 'sample.docx'));  // Adjust the path as needed
      console.log("is enter",req.body);
      var updateFile = function (response, body, path) {
        if (body.status == 2)
        {
            var file = syncRequest("GET", body.url);
            fs.writeFileSync(path, file.getBody());
        }
        response.write("{\"error\":0}");
        response.end();
    }
    var readbody = function (request, response, path) {
        var content = "";
        request.on("data", function (data) {
            content += data;
        });
        request.on("end", function () {
            var body = JSON.parse(content);
            updateFile(response, body, path);
        });
    }
    if (req.body?.hasOwnProperty("status")) {
        updateFile(res, req.body, "/documents/");
    } else {
        readbody(req, res, "/documents/")
    }




});

and the output in the server is
image

The message "is enter" appears only when the page containing ONLYOFFICE is loaded. However, when I edit the document, the callback is not triggered, and the message does not appear during the document editing process.

also req.body is undefined

for information i use windows

In debug mode it will be [DEBUG] entry that says which callback has been used. Is it possible to share logs after saving the document?