INWX API error 2002 “Command use error”

In short: Code 2002 “Command use error” means the API command is well-formed but cannot be executed in the current context. With INWX, this is almost always a session problem: the call reaches the DomRobot without a valid, logged-in session.

Common causes

  • Session cookie is not stored or not sent: account.login returns 1000, every following call returns 2002.
  • No write permission for the cookie file: The client cannot store the cookie after login, e.g. because the directory belongs to another user or a cron job runs as a different user. Login succeeds, every following call returns 2002.
  • Login failed but the script keeps going: Login returns 2200 (Authentication error), then only 2002.
  • 2FA enabled but account.unlock with a TAN is missing: Login succeeds, following calls are rejected.
  • Session expired or already ended with account.logout: Long-running jobs fail after a while.
  • Login and calls go to different endpoints (OT&E vs. live): Works in testing but not in production, or the other way round.
  • Command does not fit the object’s current state: Only one specific command fails, others work.

Step-by-step fix

  1. Check the login result. After account.login, code must be 1000. On any other code, stop and log msg instead of carrying on.
  2. Store and send the cookie. Save the cookie from the login response and send it with every following call. Match header names case-insensitively (Set-Cookie and set-cookie are the same).
  3. Check write permissions for the cookie file. Check the path, owner and permissions of the cookie file. The user the client runs as (including under cron or systemd) must be able to create and write the file. If needed, choose a path in a writable directory.
  4. Handle 2FA. If two-factor login is enabled, call account.unlock with the current TAN right after login. The official clients do this when you pass the 2FA secret.
  5. Use one endpoint. Send login and all calls to the same endpoint: live https://api.domrobot.com/… or test https://api.ote.domrobot.com/…. OT&E has its own credentials.
  6. Mind the session lifetime. For long jobs, log in again before the call, or on 2002 log in once more and retry the call.
  7. Check special characters in the password. Your own XML-RPC scripts must escape characters such as <, & or " in the password, or the login itself fails.
  8. Use an official client. The INWX clients (Python, PHP, Node.js and others) manage the cookie and session for you, which rules out most causes.
  9. If only one command keeps failing, check the object’s state (e.g. domain locked, transfer pending) and contact INWX support with the request/response log.
Tags
API
How do I create a CSR? (OpenSSL)