Jump to content

How does one get a "Session" with JSON?


CapSolHost

Recommended Posts

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;

 

Link to comment
Share on other sites

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.

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.

Loading...
×
×
  • Create New...