XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    xo-cli user.create issues

    Scheduled Pinned Locked Moved REST API
    7 Posts 3 Posters 267 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      samuelolavo
      last edited by

      Good afternoon, I am using the Laravel framework, but I am having a lot of difficulties creating a user via shell_exec.

      $xoCommand = [
                     'xo-cli',
                     'user.create',
                     "email=$username",
                     "password=$randomPassword",
                     "permission=none"
                 ];
                 $this->info("Executing command: " . implode(' ', $xoCommand));
      
                 $process = new Process($xoCommand);
                 $process->run();
      

      When I execute the command, it constantly returns this error in the logs:

      [2024-10-28 13:44:35] local.INFO: Output from user:create command: Executing command: xo-cli user.create email=usertest password=1234 permission=none
      Error creating user in XO: internal/process/esm_loader.js:74
          internalBinding('errors').triggerUncaughtException(
                                    ^
      
      Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'fs' imported from /usr/local/lib/node_modules/xo-cli/index.mjs
          at packageResolve (internal/modules/esm/resolve.js:664:9)
          at moduleResolve (internal/modules/esm/resolve.js:705:18)
          at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:798:11)
          at Loader.resolve (internal/modules/esm/loader.js:100:40)
          at Loader.getModuleJob (internal/modules/esm/loader.js:246:28)
          at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:47:40)
          at link (internal/modules/esm/module_job.js:46:36) {
        code: 'ERR_MODULE_NOT_FOUND'
      }
      

      Can you please help me?

      I can execute other types of commands without any problem, such as:

      $output = shell_exec('xo-cli list-objects type=VM'); for example.
      
      julien-fJ 1 Reply Last reply Reply Quote 0
      • olivierlambertO Online
        olivierlambert Vates 🪐 Co-Founder CEO
        last edited by

        I don't think you should use shel exec to call XO CLI, but call the XO API directly (eg via JSON RPC or REST API). Also, your error is likely related to a very old version of NodeJS. Have you checked the official doc on the requirements?

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          samuelolavo @olivierlambert
          last edited by

          @olivierlambert I have already verified, and I can execute the script directly in the shell without any issues. Is it possible to create a user via the REST API? I couldn't find any documentation on this topic.

          1 Reply Last reply Reply Quote 0
          • olivierlambertO Online
            olivierlambert Vates 🪐 Co-Founder CEO
            last edited by

            Putting @julien-f in the loop

            1 Reply Last reply Reply Quote 0
            • julien-fJ Offline
              julien-f Vates 🪐 Co-Founder XO Team @samuelolavo
              last edited by

              @samuelolavo I have node idea why some xo-cli commands would work but not others.

              Also, fs is a builtin Node package, it should always be available.

              Make sure that you are running Node 20 and that your PHP setup is not messing with the environment.

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                samuelolavo @julien-f
                last edited by samuelolavo

                @julien-f Good afternoon, I am using Node 21, and I believe the PHP configuration is correct.

                However, is it possible to create users via REST API? And also self-service?

                julien-fJ 1 Reply Last reply Reply Quote 0
                • julien-fJ Offline
                  julien-f Vates 🪐 Co-Founder XO Team @samuelolavo
                  last edited by

                  @samuelolavo No, users management and self service are not in the REST API yet.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post