Jump to content

Recommended Posts

Posted

Hi, I'm trying to create a library for NodeJS to interact with the Blesta API over HTTP/S.

For /blesta/components/models/users/login, one needs to provide a session, which is apparently generated by minPHP, however, minPHP/session was deprecated in 4.6, and I don't think that's availabel by the API anyway.

So what do I put there, then? What does a valid "session" look like?

Code for reference:

const params = new url.URLSearchParams({
    session,
    ["vars[username]"]: vars.username,
    ["vars[password]"]: vars.password,
    ["vars[remember_me]"]: vars.rememberMe,
  });
  if (vars.ipAddress) {
    params.append("vars[ip_address]", ipAddress);
  }
  if (vars.otp) {
    params.append("vars[otp]", otp);
  }

  console.log(params.toString());

  const r = await axios({
    method: "post",
    url: aUrl + "users/login.json",
    auth: {
      username: aUser,
      password: aKey,
    },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    data: params.toString(),
  }).catch((e) => {
    return Promise.reject(
      "Server responded with " +
        e.response.status +
        ": " +
        e.response.statusText +
        ". " +
        e.response.data.response
    );
  });
  console.log(r);
  return r.data.response;

 

Posted

What are you trying to do? Determine if a user exists within Blesta based on their login?

 

If you are trying to use the Blesta API there is no need to "login" as the API requires Basic Auth with unique API creds, which is what you have done via aUser and aKey.

 

If you are trying to determine if a user exists within Blesta based on their username and password, use the auth function instead of login. http://source-docs.blesta.com/class-Users.html#_auth

Post to: api/users/auth.json

With form data:

const params = new URLSearchParams({
    "username": vars.username,
    "vars[username]": vars.username,
    "vars[password]": vars.password,
    "type": "any"
});

It will return true if the users exists otherwise false if the user does not.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...