SOLVED cPanel create email account api access issue

basheer ahmed

Registered
Jun 7, 2017
2
1
3
Pakistan
cPanel Access Level
Root Administrator
Hi folks, I've been struggling for almost two days but couldn't figure out the exact issue. I've go through documentation and tried several ways to accomplish the task but failed. I need to create an email through Email module using pop function. The email is being created with no errors when I copy and past the below command in shell.

Code:
uapi --user=username Email add_pop email=user password=12345luggage quota=0 domain=example.com skip_update_db=1
But the same above command does not work when Try to call in with php code. e.x

Code:
$process = new Process($command);
$process->run();
dd($process);//Failed to set uid as normal user
I've also tried the curl way but really that is also returning false and says access denied though I've generated token in my cpanel.

PHP:
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        
$header[0] = "Authorization: whm user:$token";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $url);
$result = curl_exec($curl);