Update RESTful API: able to create/delete mailing list and mail alias account.

This commit is contained in:
Zhang Huangbin 2016-04-12 11:29:47 +08:00
parent f41b4653d9
commit 88c09693ed
4 changed files with 232 additions and 46 deletions

View File

@ -20,7 +20,9 @@ iRedAdmin-Pro RESTful API will return message in JSON format.
didn't offer RESTful API.
* Our samples below requires tool `curl`: <https://curl.haxx.se>.
## Login
## Samples
### Login (`/login`, POST)
```
curl -X POST -c cookie.txt -d "username=<username>&password=<password>" https://<server>/api/login
@ -30,9 +32,9 @@ curl -X POST -c cookie.txt -d "username=<username>&password=<password>" https://
* Replace `<password>` by the real admin password.
* It will create a plain text file `cookie.txt` under current directory.
## Domain
### Domain (`/domain/<domain>`)
### Create a new mail domain
#### Create domain (POST)
```
curl -X POST -i -b cookie.txt -d "var=<value>&var2=value2" https://<server>/api/domain/<domain>
@ -50,7 +52,7 @@ Optional POST data:
* `numberOfUsers`: Max number of mail user accounts
* `numberOfAliases`: Max number of mail alias accounts
### Delete an existing mail domain
#### Delete domain (DELETE)
```
curl -X DELETE -i -b cookie.txt https://<server>/api/domain/<domain>
@ -58,9 +60,9 @@ curl -X DELETE -i -b cookie.txt https://<server>/api/domain/<domain>
* Replace `<domain>` by the (existing) domain name.
## User
### Mail User (`/user/<mail>`)
### Create a new mail user
#### Create mail user (POST)
```
curl -X POST -i -b cookie.txt -d "var=value1&var2=value2&..." https://<server>/api/user/<mail>
@ -78,7 +80,7 @@ Optional POST data:
* `preferredLanguage`: default preferred language for new user. e.g. `en_US` for English, `de_DE` for Deutsch.
* `mailQuota`: mailbox quota for this user (in MB). Defaults to per-domain quota setting or unlimited.
### Delete an existing mail user
#### Delete mail user (DELETE)
```
curl -X DELETE -i -b cookie.txt https://<server>/api/user/<mail>
@ -86,6 +88,50 @@ curl -X DELETE -i -b cookie.txt https://<server>/api/user/<mail>
* Replace `<mail>` by the (existing) email address.
### Mail Alias (`/alias/<mail>`)
#### Create mail alias (POST)
```
curl -X POST -i -b cookie.txt -d "..." https://<server>/api/alias/<mail>
```
* Replace `<mail>` by the email address of (new) mail alias account.
Optional POST data:
* `cn`: display name
#### Delete mail alias (DELETE)
```
curl -X DELETE -i -b cookie.txt https://<server>/api/alias/<mail>
```
* Replace `<mail>` by the email address (existing) mail alias account.
### Mailing List (`/maillist/<mail>`, OpenLDAP backend only)
#### Create mailing list (POST)
```
curl -X POST -i -b cookie.txt -d "..." https://<server>/api/maillist/<mail>
```
* Replace `<mail>` by the email address of (new) mailing list.
Optional POST data:
* `cn`: display name
#### Delete mail alias (DELETE)
```
curl -X DELETE -i -b cookie.txt https://<server>/api/maillist/<mail>
```
* Replace `<mail>` by the email address of (existing) mailing list.
## See Also
* [iRedAdmin-Pro RESTful API (interact with Python)](./iredadmin-pro.restful.api.python.html)

View File

@ -23,7 +23,7 @@ iRedAdmin-Pro RESTful API will return message in JSON format.
## Sample code
### Login
### Login (`/login`, POST)
!!! note
@ -54,9 +54,10 @@ if not data['success']:
cookies = r.cookies
```
### Create new domain
### Domain (`/domain/<domain>`)
#### Create domain (POST)
Create new domain `test.com`.
Create domain `test.com`.
```
requests.post(url + '/domain/test.com',
@ -74,17 +75,17 @@ Optional POST data:
* `numberOfUsers`: Max number of mail user accounts
* `numberOfAliases`: Max number of mail alias accounts
### Delete domain
Delete domain: test.com
#### Delete domain (DELETE)
```
requests.delete(url + '/domain/test.com', cookies=cookies)
```
### Create new user
### Mail User (`/user/<mail>`)
Create new user `zhb@test.com`.
#### Create mail user (POST)
Create mail user `zhb@test.com`.
```
requests.post(url + '/user/zhb@test.com',
@ -105,14 +106,54 @@ Optional POST data:
* `preferredLanguage`: default preferred language for new user. e.g. `en_US` for English, `de_DE` for Deutsch.
* `mailQuota`: mailbox quota for this user (in MB). Defaults to per-domain quota setting or unlimited.
### Delete user
Delete user `zhb@test.com`
#### Delete mail user (DELETE)
```
requests.delete(url + '/user/zhb@test.com', cookies=cookies)
```
### Mail Alias (`/alias/<mail>`)
#### Create mail alias (POST)
Create mail alias account `alias@test.com`.
```
requests.post(url + '/alias/alias@test.com',
cookies=cookies,
data={'cn': 'My Alias'})
```
Optional POST data:
* `cn`: display name
#### Delete mail alias (DELETE)
```
requests.delete(url + '/alias/alias@test.com', cookies=cookies)
```
### Mailing List (`/maillist/<mail>`, OpenLDAP backend only)
#### Create mailing list (POST)
```
requests.post(url + '/maillist/list@test.com',
cookies=cookies,
data={'cn': 'My Mailing List'})
```
Optional POST data:
* `cn`: display name
#### Delete mail alias (DELETE)
```
requests.delete(url + '/maillist/list@test.com', cookies=cookies)
```
## See Also
* [iRedAdmin-Pro RESTful API (interact with `curl`)](./iredadmin-pro.restful.api.curl.html)

View File

@ -14,15 +14,28 @@
<li><a href="#iredadmin-pro-restful-api-interact-with-curl">iRedAdmin-Pro RESTful API (interact with curl)</a><ul>
<li><a href="#summary">Summary</a></li>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#login">Login</a></li>
<li><a href="#domain">Domain</a><ul>
<li><a href="#create-a-new-mail-domain">Create a new mail domain</a></li>
<li><a href="#delete-an-existing-mail-domain">Delete an existing mail domain</a></li>
<li><a href="#samples">Samples</a><ul>
<li><a href="#login-login-post">Login (/login, POST)</a></li>
<li><a href="#domain-domaindomain">Domain (/domain/&lt;domain&gt;)</a><ul>
<li><a href="#create-domain-post">Create domain (POST)</a></li>
<li><a href="#delete-domain-delete">Delete domain (DELETE)</a></li>
</ul>
</li>
<li><a href="#mail-user-usermail">Mail User (/user/&lt;mail&gt;)</a><ul>
<li><a href="#create-mail-user-post">Create mail user (POST)</a></li>
<li><a href="#delete-mail-user-delete">Delete mail user (DELETE)</a></li>
</ul>
</li>
<li><a href="#mail-alias-aliasmail">Mail Alias (/alias/&lt;mail&gt;)</a><ul>
<li><a href="#create-mail-alias-post">Create mail alias (POST)</a></li>
<li><a href="#delete-mail-alias-delete">Delete mail alias (DELETE)</a></li>
</ul>
</li>
<li><a href="#mailing-list-maillistmail-openldap-backend-only">Mailing List (/maillist/&lt;mail&gt;, OpenLDAP backend only)</a><ul>
<li><a href="#create-mailing-list-post">Create mailing list (POST)</a></li>
<li><a href="#delete-mail-alias-delete_1">Delete mail alias (DELETE)</a></li>
</ul>
</li>
<li><a href="#user">User</a><ul>
<li><a href="#create-a-new-mail-user">Create a new mail user</a></li>
<li><a href="#delete-an-existing-mail-user">Delete an existing mail user</a></li>
</ul>
</li>
<li><a href="#see-also">See Also</a></li>
@ -47,7 +60,8 @@
didn't offer RESTful API.</li>
<li>Our samples below requires tool <code>curl</code>: <a href="https://curl.haxx.se">https://curl.haxx.se</a>.</li>
</ul>
<h2 id="login">Login</h2>
<h2 id="samples">Samples</h2>
<h3 id="login-login-post">Login (<code>/login</code>, POST)</h3>
<pre><code>curl -X POST -c cookie.txt -d &quot;username=&lt;username&gt;&amp;password=&lt;password&gt;&quot; https://&lt;server&gt;/api/login
</code></pre>
@ -56,8 +70,8 @@
<li>Replace <code>&lt;password&gt;</code> by the real admin password.</li>
<li>It will create a plain text file <code>cookie.txt</code> under current directory.</li>
</ul>
<h2 id="domain">Domain</h2>
<h3 id="create-a-new-mail-domain">Create a new mail domain</h3>
<h3 id="domain-domaindomain">Domain (<code>/domain/&lt;domain&gt;</code>)</h3>
<h4 id="create-domain-post">Create domain (POST)</h4>
<pre><code>curl -X POST -i -b cookie.txt -d &quot;var=&lt;value&gt;&amp;var2=value2&quot; https://&lt;server&gt;/api/domain/&lt;domain&gt;
</code></pre>
@ -74,15 +88,15 @@
<li><code>numberOfUsers</code>: Max number of mail user accounts</li>
<li><code>numberOfAliases</code>: Max number of mail alias accounts</li>
</ul>
<h3 id="delete-an-existing-mail-domain">Delete an existing mail domain</h3>
<h4 id="delete-domain-delete">Delete domain (DELETE)</h4>
<pre><code>curl -X DELETE -i -b cookie.txt https://&lt;server&gt;/api/domain/&lt;domain&gt;
</code></pre>
<ul>
<li>Replace <code>&lt;domain&gt;</code> by the (existing) domain name.</li>
</ul>
<h2 id="user">User</h2>
<h3 id="create-a-new-mail-user">Create a new mail user</h3>
<h3 id="mail-user-usermail">Mail User (<code>/user/&lt;mail&gt;</code>)</h3>
<h4 id="create-mail-user-post">Create mail user (POST)</h4>
<pre><code>curl -X POST -i -b cookie.txt -d &quot;var=value1&amp;var2=value2&amp;...&quot; https://&lt;server&gt;/api/user/&lt;mail&gt;
</code></pre>
@ -99,13 +113,51 @@
<li><code>preferredLanguage</code>: default preferred language for new user. e.g. <code>en_US</code> for English, <code>de_DE</code> for Deutsch.</li>
<li><code>mailQuota</code>: mailbox quota for this user (in MB). Defaults to per-domain quota setting or unlimited.</li>
</ul>
<h3 id="delete-an-existing-mail-user">Delete an existing mail user</h3>
<h4 id="delete-mail-user-delete">Delete mail user (DELETE)</h4>
<pre><code>curl -X DELETE -i -b cookie.txt https://&lt;server&gt;/api/user/&lt;mail&gt;
</code></pre>
<ul>
<li>Replace <code>&lt;mail&gt;</code> by the (existing) email address.</li>
</ul>
<h3 id="mail-alias-aliasmail">Mail Alias (<code>/alias/&lt;mail&gt;</code>)</h3>
<h4 id="create-mail-alias-post">Create mail alias (POST)</h4>
<pre><code>curl -X POST -i -b cookie.txt -d &quot;...&quot; https://&lt;server&gt;/api/alias/&lt;mail&gt;
</code></pre>
<ul>
<li>Replace <code>&lt;mail&gt;</code> by the email address of (new) mail alias account.</li>
</ul>
<p>Optional POST data:</p>
<ul>
<li><code>cn</code>: display name</li>
</ul>
<h4 id="delete-mail-alias-delete">Delete mail alias (DELETE)</h4>
<pre><code>curl -X DELETE -i -b cookie.txt https://&lt;server&gt;/api/alias/&lt;mail&gt;
</code></pre>
<ul>
<li>Replace <code>&lt;mail&gt;</code> by the email address (existing) mail alias account.</li>
</ul>
<h3 id="mailing-list-maillistmail-openldap-backend-only">Mailing List (<code>/maillist/&lt;mail&gt;</code>, OpenLDAP backend only)</h3>
<h4 id="create-mailing-list-post">Create mailing list (POST)</h4>
<pre><code>curl -X POST -i -b cookie.txt -d &quot;...&quot; https://&lt;server&gt;/api/maillist/&lt;mail&gt;
</code></pre>
<ul>
<li>Replace <code>&lt;mail&gt;</code> by the email address of (new) mailing list.</li>
</ul>
<p>Optional POST data:</p>
<ul>
<li><code>cn</code>: display name</li>
</ul>
<h4 id="delete-mail-alias-delete_1">Delete mail alias (DELETE)</h4>
<pre><code>curl -X DELETE -i -b cookie.txt https://&lt;server&gt;/api/maillist/&lt;mail&gt;
</code></pre>
<ul>
<li>Replace <code>&lt;mail&gt;</code> by the email address of (existing) mailing list.</li>
</ul>
<h2 id="see-also">See Also</h2>
<ul>
<li><a href="./iredadmin-pro.restful.api.python.html">iRedAdmin-Pro RESTful API (interact with Python)</a></li>

View File

@ -15,11 +15,27 @@
<li><a href="#summary">Summary</a></li>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#sample-code">Sample code</a><ul>
<li><a href="#login">Login</a></li>
<li><a href="#create-new-domain">Create new domain</a></li>
<li><a href="#delete-domain">Delete domain</a></li>
<li><a href="#create-new-user">Create new user</a></li>
<li><a href="#delete-user">Delete user</a></li>
<li><a href="#login-login-post">Login (/login, POST)</a></li>
<li><a href="#domain-domaindomain">Domain (/domain/&lt;domain&gt;)</a><ul>
<li><a href="#create-domain-post">Create domain (POST)</a></li>
<li><a href="#delete-domain-delete">Delete domain (DELETE)</a></li>
</ul>
</li>
<li><a href="#mail-user-usermail">Mail User (/user/&lt;mail&gt;)</a><ul>
<li><a href="#create-mail-user-post">Create mail user (POST)</a></li>
<li><a href="#delete-mail-user-delete">Delete mail user (DELETE)</a></li>
</ul>
</li>
<li><a href="#mail-alias-aliasmail">Mail Alias (/alias/&lt;mail&gt;)</a><ul>
<li><a href="#create-mail-alias-post">Create mail alias (POST)</a></li>
<li><a href="#delete-mail-alias-delete">Delete mail alias (DELETE)</a></li>
</ul>
</li>
<li><a href="#mailing-list-maillistmail-openldap-backend-only">Mailing List (/maillist/&lt;mail&gt;, OpenLDAP backend only)</a><ul>
<li><a href="#create-mailing-list-post">Create mailing list (POST)</a></li>
<li><a href="#delete-mail-alias-delete_1">Delete mail alias (DELETE)</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#see-also">See Also</a></li>
@ -46,7 +62,7 @@
please read its <a href="http://docs.python-requests.org/en/master/">official documentation</a>.</li>
</ul>
<h2 id="sample-code">Sample code</h2>
<h3 id="login">Login</h3>
<h3 id="login-login-post">Login (<code>/login</code>, POST)</h3>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>We need the cookies for further operations.</p>
@ -75,8 +91,9 @@ if not data['success']:
cookies = r.cookies
</code></pre>
<h3 id="create-new-domain">Create new domain</h3>
<p>Create new domain <code>test.com</code>.</p>
<h3 id="domain-domaindomain">Domain (<code>/domain/&lt;domain&gt;</code>)</h3>
<h4 id="create-domain-post">Create domain (POST)</h4>
<p>Create domain <code>test.com</code>.</p>
<pre><code>requests.post(url + '/domain/test.com',
cookies=cookies,
data={'defaultQuota': '1024'})
@ -92,13 +109,13 @@ cookies = r.cookies
<li><code>numberOfUsers</code>: Max number of mail user accounts</li>
<li><code>numberOfAliases</code>: Max number of mail alias accounts</li>
</ul>
<h3 id="delete-domain">Delete domain</h3>
<p>Delete domain: test.com</p>
<h4 id="delete-domain-delete">Delete domain (DELETE)</h4>
<pre><code>requests.delete(url + '/domain/test.com', cookies=cookies)
</code></pre>
<h3 id="create-new-user">Create new user</h3>
<p>Create new user <code>zhb@test.com</code>.</p>
<h3 id="mail-user-usermail">Mail User (<code>/user/&lt;mail&gt;</code>)</h3>
<h4 id="create-mail-user-post">Create mail user (POST)</h4>
<p>Create mail user <code>zhb@test.com</code>.</p>
<pre><code>requests.post(url + '/user/zhb@test.com',
cookies=cookies,
data={'cn': 'Zhang Huangbin',
@ -117,11 +134,41 @@ cookies = r.cookies
<li><code>preferredLanguage</code>: default preferred language for new user. e.g. <code>en_US</code> for English, <code>de_DE</code> for Deutsch.</li>
<li><code>mailQuota</code>: mailbox quota for this user (in MB). Defaults to per-domain quota setting or unlimited.</li>
</ul>
<h3 id="delete-user">Delete user</h3>
<p>Delete user <code>zhb@test.com</code></p>
<h4 id="delete-mail-user-delete">Delete mail user (DELETE)</h4>
<pre><code>requests.delete(url + '/user/zhb@test.com', cookies=cookies)
</code></pre>
<h3 id="mail-alias-aliasmail">Mail Alias (<code>/alias/&lt;mail&gt;</code>)</h3>
<h4 id="create-mail-alias-post">Create mail alias (POST)</h4>
<p>Create mail alias account <code>alias@test.com</code>.</p>
<pre><code>requests.post(url + '/alias/alias@test.com',
cookies=cookies,
data={'cn': 'My Alias'})
</code></pre>
<p>Optional POST data:</p>
<ul>
<li><code>cn</code>: display name</li>
</ul>
<h4 id="delete-mail-alias-delete">Delete mail alias (DELETE)</h4>
<pre><code>requests.delete(url + '/alias/alias@test.com', cookies=cookies)
</code></pre>
<h3 id="mailing-list-maillistmail-openldap-backend-only">Mailing List (<code>/maillist/&lt;mail&gt;</code>, OpenLDAP backend only)</h3>
<h4 id="create-mailing-list-post">Create mailing list (POST)</h4>
<pre><code>requests.post(url + '/maillist/list@test.com',
cookies=cookies,
data={'cn': 'My Mailing List'})
</code></pre>
<p>Optional POST data:</p>
<ul>
<li><code>cn</code>: display name</li>
</ul>
<h4 id="delete-mail-alias-delete_1">Delete mail alias (DELETE)</h4>
<pre><code>requests.delete(url + '/maillist/list@test.com', cookies=cookies)
</code></pre>
<h2 id="see-also">See Also</h2>
<ul>
<li><a href="./iredadmin-pro.restful.api.curl.html">iRedAdmin-Pro RESTful API (interact with <code>curl</code>)</a></li>