Skip to main content
Question

I cannot login with BOX CLI using headless

  • September 24, 2026
  • 1 reply
  • 84 views
  • Translate All

Hi,

I’m trying to use BOX CLI version @box/cli/4.10.1 linux-x64 node-v24.21.0
in headless mode.

I can access box using box cli and validating through a local browser

If I try headless I get an error.

These are the steps.

box login --code

? How would you like to authenticate?
[1] Log-in as a Box user (OAuth)
[2] Use a Box Platform App
[q] Quit
? Enter 1, 2, or q: 1




I paste in the URL given into a broswer on another computer and click Grant Access. This redirects to a localhost IP which includes the code and state. Similar to this 

http://localhost:3000/callback?state=12345678901234567890123456789012&code=ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF

I enter the state and the code into the box cli  and get 

Login failed: Failed to exchange auth code for tokens.

Can anyone help?

1 reply

chriskim
  • Box Employee
  • September 29, 2026

Hi Andy,

If Box CLI is running on a remote/headless machine, open the authorization URL printed by box login --code in a browser on your local computer.

After you click Grant Access, Box redirects your browser to http://localhost:3000/callback?.... Here, localhost refers to your local computer. You may see a connection error because the CLI’s callback server is running on the remote machine. That’s expected with this manual flow—the code and state values should still appear in your browser’s address bar.

Copy those values into the waiting CLI on the remote machine, following its prompts: code first, then state. Paste only the values, without code= or state=.

Please complete both prompts within 30 seconds of granting access, since Box authorization codes expire after that time. If an attempt fails, restart box login --code and use a fresh authorization URL.

Translate