How to get siteId for mail()->create()
Closed this issue · 5 comments
The siteId is a mandatory field for $client->mail()->create()
, yet it seems impossible to get via the api.
The endpoint $client->webspace()->getAll()
returns just the contents of /packet/webspace/get/result/data/gen_info
information about the site, but skips the site id in
/packet/webspace/get/result/id
in the response XML.
So, how do I get the id needed for email account creation (and other site related actions)?
XML response for reference:
<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.6.9.1">
<webspace>
<get>
<result>
<status>ok</status>
<filter-id>1</filter-id>
<id>1</id>
<data>
<gen_info>
<!-- Only (some) contents form here are returned -->
</gen_info>
</data>
</result>
</get>
</webspace>
</packet>
I ran into this issue as well, and as far as I can tell there is no way to do this with the current API. You have to build the logic to fetch the site ID yourself and then hand it over to the method using it.
Below is a crude example from our implementation before proper error handling was added.
This is cut from a concrete implementation of an interface that takes the plesk/api-php-lib as constrcutor property upon creation.
private function get_site_id($domain_name)
{
$array = [
'get' => [
'filter' => [
'name' => $domain_name
],
'dataset' => ''
]
];
$response = $this->XMLConnection->site()->request([$array]);
if ($response->status != 'ok')
{
dd($response);
}
else {
return $response->id;
}
}
Using the request()
method, provided by the different operators in this API, you can construct your own XML packets that will be sent as a request into the Plesk API.
The interactive schema navigator linked in the XML API docs is super helpful when dealing with this, but you will have to refer to the detailed documentation for information about the specific contents and contracts of the different packet structures: http://plesk.github.io/api-schemas/1.6.8.0/agent_output.svg
Thanks @pascualstromsnes
I'll try to add it to my setup, if it works well, I could add a PR to this project. Probably will take time till October though 😅
I had thoughts about PR-ing some stuff to this package as well, as it has a huge potential. I am not sure if Plesk is accepting PRs at all at the moment however.
I proposed change #108 then you get an indexed array of all webspaces, looping through and getting the id is an easy way to find the site-id based on a given criteria (domain name or guid).
It was addressed in the scope of a665af5