Answer the question
In order to leave comments, you need to log in
How to pass parameters when calling a command via the Plesk REST API?
I want to set up an autoresponder for an existing e-mail address on the server via the Plesk REST API
. I try by calling the command:
function setRequest($url, $headers, $post_fields)
{
$post_fields = json_encode( (array) $post_fields );
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
$response = curl_exec($ch);
curl_close($ch);
return json_decode( $response, true );
}
var_dump( setRequest(
'https://XXX.XXX.XXX.XXX:8443/api/v2/cli/autoresponder/call',
array(
'X-API-Key: c1986243-c4b7-0fc3-d543-67u9ad3a000a',
),
array(
'params'=> array(
'--update',
'mail' => '[email protected]',
),
)
) );
array(3) {
["code"]=>
int(1)
["stdout"]=>
string(0) ""
["stderr"]=>
string(135) "Unknown option '[email protected]': /usr/local/psa/admin/plib/api-cli/autoresponder.php --update >>>[email protected]"
}
Answer the question
In order to leave comments, you need to log in
It turned out to be simple:
var_dump( setRequest(
'https://XXX.XXX.XXX.XXX:8443/api/v2/cli/autoresponder/call',
array(
'X-API-Key: c1986243-c4b7-0fc3-d543-67u9ad3a000a',
),
array(
'params'=> array(
'--update',
'-mail',
'[email protected]',
'-status',
'true',
'-subject',
'Re: this subject text',
'-text',
'This is text email message!',
),
)
) );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question