Automatic/unattended client installation without graphics toolkit

I’m trying to set up a script that configures the Nextcloud client on a headless Linux virtual machine.

Following the instructions https://docs.nextcloud.com/desktop/latest/advancedusage.html#mass-deployment-and-account-creation, my script has a command like

nextcloud --userid $USERNAME --apppassword $PASSWORD --localdirpath ~/nextcloud --serverurl $URL --background

but it fails with

qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Why is the client trying to connect to the display if I already provided all the authentication information?

Can’t really answer why it does this, and I can’t say for sure if the following will help, but I googled the message and it might help to add the following environment variable to your script:

export QT_QPA_PLATFORM=offscreen

https://stackoverflow.com/a/74719383