Skip to main content

WHM API 1 'Create a temporary user session' doesn't redirect user to app

Comments

10 comments

  • cPRex Jurassic Moderator

    Hey there!  I don't believe you're calling the function correctly for email access.  For the "user" portion you'll want the exact email address instead of the cPanel username.  Can you try that instead?  Here is a test form my personal system:

    root@host: whmapi1 create_user_session user="cptest@hattmonkey.com" service="cpaneld" app="Email_Accounts"

    --- 
    data: 
      cp_security_token: /cpsess0480728513
      expires: '1723478251'
      service: cpaneld
    session: cptest@domain.com:lDB_rRICPefkUIyK:create_user_session,02c4ec2d11d9a7e83d9fa2bb9c931b09
    url: https://host.domain.com:2083/cpsess0480728513/login/?session=cptest%40domain.com%3alDB_rRICPefkUIyK%3acreate_user_session%2c02c4ec
    0
  • Minus

    Hi cPRex, thank you for taking the time to reply and to confirm if things are working on your end.

    I did try to use the email address instead of the username as you suggested and below is what I was presented with, kindly note that the attached screenshot is of Postman.

     

    Also, can you kindly confirm if you open the URL returned in your response, does it take you to the email account page in cPanel?

    0
  • cPRex Jurassic Moderator

    Change "cpaneld" to "webmaild" and that will log you straight into webmail without other steps.  But yes, when using webmaild this URl does take me directly to Roundcube:

    https://host.domain.com:2096/cpsess7510124928/login/?session=cptest%40domain.com%3aqLOQWHtZHPM9JegU%3acreate_user_session%2c0a4ced640fc5f9c7e7e91d263d9f1c1c

    0
  • Minus

    Oh, unfortunately, seems like the screenshot in my last reply created a misunderstanding about what I am trying to achieve here. I apologize for that.

    So I am trying to create a shortcut button that will take the user to view their email accounts on cPanel, not to access Roundcode. Please find the correct screenshot below:

    1. If I use the username for the user:

    If I click on the above link, it takes me to the home page on cPanel and not to the email accounts page.


    2. If I use the email account associated with the username:

    0
  • cPRex Jurassic Moderator

    Got it - thanks for the additional details.  This takes me to the cPanel >> Email Accounts page:

    whmapi1 create_user_session user="hattmonk" service="cpaneld" app="Email_Accounts"

    With the following URL:

    https://host.domain.com:2083/cpsess5685916830/login/?goto_uri=frontend%2fjupiter%2femail_accounts%2findex.html&session=username%3aISgMpFRNrqEA644i%3acreate_user_session%2c2fcd5b7b7fb0eacf926de3c557e7b2c6

    I'm not sure how you'd go about creating that inside a button, but the API function is possible.

    0
  • Minus

    Oh okay. I need help in making this possible with the JSON-API, as in you look at the first screenshot's response, it doesn't include he 'goto_uri=...' which is what is making me go crazy. If it is possible, could you please try to do the above with WHM's JSON API and confirm if the URL return takes the user to the Email Accounts page on cPanel?

    Thank you.

    0
  • cPRex Jurassic Moderator

    Sure thing!  This guy worked for me:

    https://x.x.x.x:2087/cpsess#########/json-api/create_user_session?api.version=1&user=username&service=cpaneld&app=Email_Accounts

    Is that what you're looking for?

    0
  • Minus

    Thank you for your time, cPRex, but unfortunately, that is not what I am looking for. I want to know why the JSON-API endpoint, when passed an "app" name, doesn't include a redirect parameter (goto_uri) in the returned URL to redirect us to the requested app, similar to how it is included in the URL when trying the same request via whmapi1.

    0
  • cPRex Jurassic Moderator

    The short answer is "because it doesn't need to" - when you use the command line API call you're creating a whole new user session, so not only will it need to login to cPanel, it will have to redirect to the correct page.

    The JSON call is already being run from a browser from a session that is already authenticated so it knows it's inside cPanel already and doesn't require the go-to portion.

    0
  • saq rio

    It looks like you're missing the goto_uri parameter in the request body. To redirect directly to the email accounts page, try adding:

    "goto_uri": "/cpsess1234567/frontend/paper_lantern/mail/accounts.html"

    Replace cpsess1234567 with the appropriate session ID. This should redirect the user to the Email Accounts page instead of the cPanel homepage.

    0

Please sign in to leave a comment.