Jump to content

WHMCS API Error: "You did not enter a first name" - Node.js and Express


Recommended Posts

I'm facing an issue while trying to interact with the WHMCS API using Node.js and Express. The API is returning the error "You did not enter a first name," and I'm having trouble resolving it. Here's a simplified version of my code:

 const whmcsRequest = async (requestData) => {
  const whmcsApiUrl = process.env.WHMCS_URL;
  const whmcsUserName = process.env.WHMCS_USERNAME;
  const whmcsPassword = process.env.WHMCS_PASSWORD;
  const accessKey = process.env.WHMCS_ACCESS_KEY;
  const action = "AddUser";
  try {
    const response = await axios.post(
      `${whmcsApiUrl}?action=${action}&username=${whmcsUserName}&password=${whmcsPassword}&responsetype=json&accesskey=${accessKey}`,
      requestData
    );

    if (response.data.result === "error") {
      const errorMessage = response.data.message;
      return { error: errorMessage };
    } else {
      return response.data;
    }
  } catch (error) {
    console.error("Error making WHMCS API request:", error.message);
    return { error: "Internal Server Error" };
  }
};

const authController = {
  register: async (req, res) => {
    console.log(req.body.firstname);
    const requestData = {
      firstname: req.body.firstname,
      // others....
    };

    const whmcsResponse = await whmcsRequest(requestData);

    res.json(whmcsResponse);
  },
};

I have ensured that my Express application has express.json() middleware set up, and I'm sending the request with the correct JSON format. However, I'm still getting the mentioned error.

Link to comment
Share on other sites

`${whmcsApiUrl}?action=${action}&username=${whmcsUserName}&password=${whmcsPassword}&responsetype=json&accesskey=${accessKey}`

Your not passing the correct/all variables:

firstname string   Required
lastname string   Required
email string   Required
password2 string The password for the newly created user account Required

 

https://developers.whmcs.com/api-reference/adduser/

Edited by leemahoney3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated