Jump to content

Using API token in php


browgreg

Recommended Posts

Hello, I have been trying many different ways to complete this and I am totally stuck. I can use the cURL in my terminal fine and it does what I want it to do. I am creating a system where I want the people offering the position to have an automatic system in place.

this code works when I add my information,
curl -H'Authorization: cpanel username:U7HMR63FHY282DQZ4H5BIH16JLYSO01M' 'https://example.com:2083/execute/Email/add_pop?email=newuser&password=12345luggage'

The problem I seem to be having is that it is not connecting to the cPanel?

Is this because I am on a shared hosting plan?
If not then what are the parameters I need to add to the new CPANEL() I have tried username, api token and both I.P and Domain names.
 


 

$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
  
// Create the user@example.com email address.
$new_email = $cpanel->uapi(
    'Email', 'add_pop',
    array(
        'email'           => 'user',
        'password'        => '12345luggage',
        'quota'           => '0',
        'domain'          => 'example.com',
        'skip_update_db'  => '1',
        )
);

What am I doing wrong apart from something obvious, I have managed to get everything working how I want in this site apart from this part.

Thank you in advance,

Greg

Link to comment
Share on other sites

Unless someone here has specific knowledge about the sort of thing you're trying to do, we're not going to be able to tell you what's wrong unless you can describe what you're seeing.

First thing to do is get more information. If you can't tell whether you can connect or not, that sounds like a good place to start. Maybe try some other, simpler cPanel operation to prove that the code is valid? Also see if you can get any logging or error messages that could indicate what's going wrong.

  • Thanks 1
Link to comment
Share on other sites

Thanks I never explained it well at all.,
The second lot of code is what is confusing the issue.

OK, I have built a Document system where people are signed up via the club I am building this website for. The person who runs the admin of the association wants to have certain emails for different areas. That to me is not a problem, as it is a simple process via the cPanel.  What I am basically asking is the terminal or command the only option to run this cURL command or can I replicate it using PHP. 

When I use the code suggested by cPanel it clearly is built for a different type of cPanel. 
When I test the code i get

288977485_ScreenShot2021-04-06at5_55_00pm.png.acf9dc3ebbb8193b86b4015a52f15577.png

What I am asking is what is the best option?

curl -H'Authorization: cpanel example:U7HMR63FHY282DQZ4H5BIH16JLYSO01M' 'https://example.com:2083/execute/Email/add_pop?email=newuser&password=12345luggage' 
Link to comment
Share on other sites

So CPANEL is a dependency package that you've not included in your script. I don't use cPanel so I'm not sure how it's set up, but there should be a require or include directive in the script somewhere - either it'll include the script directly, or it'll include an autoloader file in which case you'll see a use statement naming the CPANEL class.

  • Thanks 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.