iredmail-doc/html/iredadmin-pro.restful.api-n...

516 lines
14 KiB
HTML

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>iRedAdmin-Pro: RESTful API</title>
<link rel="stylesheet" type="text/css" href="./css/markdown.css" />
</head>
<body>
<div id="navigation">
<a href="/index.html" target="_blank">
<img alt="iRedMail web site"
src="./images/logo-iredmail.png"
style="vertical-align: middle; height: 30px;"
/>&nbsp;
<span>iRedMail</span>
</a>
&nbsp;&nbsp;//&nbsp;&nbsp;<a href="./index.html">Document Index</a></div><h1 id="iredadmin-pro-restful-api">iRedAdmin-Pro: RESTful API</h1>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If you need an API which has not yet been implemented, don't hesitate to
<a href="../contact.html">contact us</a>.</p>
</div>
<div class="toc">
<ul>
<li><a href="#iredadmin-pro-restful-api">iRedAdmin-Pro: RESTful API</a><ul>
<li><a href="#changelog">ChangeLog</a></li>
<li><a href="#summary">Summary</a></li>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#enable-restful-api">Enable RESTful API</a></li>
<li><a href="#apis">APIs</a><ul>
<li><a href="#domain">Domain</a></li>
<li><a href="#user">User</a></li>
<li><a href="#mailing-list">Mailing List</a></li>
<li><a href="#mail-alias">Mail Alias</a></li>
<li><a href="#throttling">Throttling</a></li>
</ul>
</li>
<li><a href="#sample-code-to-interact-with-iredadmin-pro-restful-api">Sample code to interact with iRedAdmin-Pro RESTful API</a></li>
</ul>
</li>
</ul>
</div>
<h2 id="changelog">ChangeLog</h2>
<ul>
<li>
<p>May XX, 2016:</p>
<ul>
<li>NEW APIs:<ul>
<li><code>/api/user/&lt;mail&gt;/password</code></li>
<li><code>/api/users/&lt;domain&gt;</code></li>
<li><code>/api/users/&lt;domain&gt;/password</code></li>
</ul>
</li>
<li>parameter used to update account profile <code>preferredLanguage</code> has been changed to <code>language</code>.</li>
<li>API used to update user password is now: <code>/api/user/&lt;mail&gt;/password</code> (old is <code>/api/user/&lt;mail&gt;</code>)</li>
</ul>
</li>
<li>
<p>May 3, 2016: initial publish.</p>
</li>
</ul>
<h2 id="summary">Summary</h2>
<p>iRedAdmin-Pro RESTful API will return message in JSON format.</p>
<ul>
<li>If operation succeed, client will receive JSON data: <code>{'success': true}</code>.</li>
<li>If operation failed, client will receive JSON data: <code>{'success': false, 'msg': '&lt;error_reason&gt;'}</code>.</li>
</ul>
<h2 id="requirements">Requirements</h2>
<p>RESTful API is available since iRedAdmin-Pro-SQL-2.4.0 and iRedAdmin-Pro-LDAP-2.6.0
(both released on May 3, 2016). Earlier releases didn't support RESTful API.</p>
<h2 id="enable-restful-api">Enable RESTful API</h2>
<p>RESTful API is disabled by default, to enable it, please add setting below in
iRedAdmin-Pro config file <code>settings.py</code>:</p>
<pre><code>ENABLE_RESTFUL_API = True
</code></pre>
<p>To restrict API access to few IP addresses, please also add settings below in
iRedAdmin-Pro config file:</p>
<pre><code># Enable restriction
RESTRICT_API_ACCESS = True
# List all IP addresses of allowed client for API access.
RESTFUL_API_CLIENTS = ['172.16.244.1', ...]
</code></pre>
<p>Restarting Apache or uwsgi (if you're running Nginx) is required.</p>
<h2 id="apis">APIs</h2>
<p>Notes:</p>
<ul>
<li>replace <code>&lt;domain&gt;</code> in URL by the real domain name.</li>
<li>replace <code>&lt;mail&gt;</code> in URL by the real email address.</li>
</ul>
<h3 id="domain">Domain</h3>
<div class="admonition api">
<p class="admonition-title"><code>/api/domain/&lt;domain&gt;</code> <code>POST</code> <code>Create a new domain</code></p>
</div>
<div class="admonition api">
<p class="admonition-title"><code>/api/domain/&lt;domain&gt;</code> <code>DELETE</code> <code>Delete an existing domain</code></p>
</div>
<div class="admonition api">
<p class="admonition-title"><code>/api/domain/&lt;domain&gt;</code> <code>PUT</code> <code>Update profile of an existing domain</code></p>
<p>Possible <code>PUT</code> parameters used to update account profile:</p>
<table>
<thead>
<tr>
<th>Parameter Name</th>
<th>Summary</th>
<th>Sample Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>cn</code></td>
<td>the short description of this domain name. e.g. company name</td>
<td><code>cn=iRedMail Project</code></td>
</tr>
<tr>
<td><code>quota</code></td>
<td>a integer number for mailbox quota (for whole domain, in MB)</td>
<td><code>quota=20480</code></td>
</tr>
<tr>
<td><code>language</code></td>
<td>default preferred language for new user</td>
<td><code>language=en_US</code></td>
</tr>
<tr>
<td><code>defaultQuota</code></td>
<td>default mailbox quota for new user</td>
<td><code>defaultQuota=1024</code></td>
</tr>
<tr>
<td><code>maxUserQuota</code></td>
<td>Max mailbox quota of a single mail user</td>
<td><code>maxUserQuota=2048</code></td>
</tr>
<tr>
<td><code>numberOfUsers</code></td>
<td>Max number of mail user accounts</td>
<td><code>numberOfUsers=20</code></td>
</tr>
<tr>
<td><code>numberOfAliases</code></td>
<td>Max number of mail alias accounts</td>
<td><code>numberOfAliases=30</code></td>
</tr>
</tbody>
</table>
</div>
<h3 id="user">User</h3>
<div class="admonition api">
<p class="admonition-title"><code>/api/user/&lt;mail&gt;</code> <code>POST</code> <code>Create a new mail user</code></p>
</div>
<div class="admonition api">
<p class="admonition-title"><code>/api/user/&lt;mail&gt;</code> <code>DELETE</code> <code>Delete an existing mail user</code></p>
</div>
<div class="admonition api">
<p class="admonition-title"><code>/api/user/&lt;mail&gt;</code> <code>PUT</code> <code>Update profile of an existing mail user</code></p>
</div>
<div class="admonition api">
<p class="admonition-title"><code>/api/users/&lt;domain&gt;</code> <code>PUT</code> <code>Update profiles of all mail user under domain</code></p>
</div>
<div class="admonition api">
<p class="admonition-title"><code>/api/users/&lt;domain&gt;/password</code> <code>PUT</code> <code>Update passwords of all users under domain</code></p>
<p id="param">Required parameter:</p>
<table>
<thead>
<tr>
<th>Parameter Name</th>
<th>Sample Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>password</code></td>
<td><code>password=Ww0nXVEV8iv4ap@p4b</code></td>
</tr>
</tbody>
</table>
</div>
<table>
<thead>
<tr>
<th>URL</th>
<th>HTTP Method</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
<tr>
<td>/api/user/&lt;mail></td>
<td>POST</td>
<td>Create a new mail user</td>
</tr>
<tr>
<td>/api/user/&lt;mail></td>
<td>DELETE</td>
<td>Delete an existing mail user</td>
</tr>
<tr>
<td>/api/user/&lt;mail></td>
<td>PUT</td>
<td>Update profile of an existing mail user</td>
</tr>
<tr>
<td>/api/users/&lt;domain></td>
<td>PUT</td>
<td>Update profiles for all users under domain <code>&lt;domain&gt;</code></td>
</tr>
<tr>
<td>/api/users/&lt;domain>/password</td>
<td>PUT</td>
<td>Update passwords of all users under domain <code>&lt;domain&gt;</code></td>
</tr>
</tbody>
</table>
<p>Possible <code>PUT</code> parameters used to update account profile (<code>/api/user/&lt;mail&gt;</code>):</p>
<table>
<thead>
<tr>
<th>Parameter Name</th>
<th>Summary</th>
<th>Sample Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>cn</code></td>
<td>display name</td>
<td><code>cn=John Smith</code></td>
</tr>
<tr>
<td><code>accountStatus</code></td>
<td>Account status</td>
<td><code>accountStatus=disabled</code> (or <code>active</code>)</td>
</tr>
<tr>
<td><code>language</code></td>
<td>default preferred language for new user</td>
<td><code>language=en_US</code></td>
</tr>
<tr>
<td><code>transport</code></td>
<td>Transport program</td>
<td><code>transport=dovecot</code></td>
</tr>
</tbody>
</table>
<p>Possible <code>PUT</code> parameters used to update profiles for all users under domain (<code>/api/users/&lt;domain&gt;</code>):</p>
<table>
<thead>
<tr>
<th>Parameter Name</th>
<th>Summary</th>
<th>Sample Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>accountStatus</code></td>
<td>Account status</td>
<td><code>accountStatus=disabled</code> (or <code>active</code>)</td>
</tr>
<tr>
<td><code>language</code></td>
<td>default preferred language for new user</td>
<td><code>language=en_US</code></td>
</tr>
<tr>
<td><code>transport</code></td>
<td>Transport program</td>
<td><code>transport=dovecot</code></td>
</tr>
</tbody>
</table>
<p>Possible <code>PUT</code> parameters used to update passwords of all users under domain (<code>/api/users/&lt;domain&gt;/password</code>):</p>
<table>
<thead>
<tr>
<th>Parameter Name</th>
<th>Summary</th>
<th>Sample Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>password</code></td>
<td>Update passwords of all users under domain</td>
<td><code>password=Ww0nXVEV8iv4ap@p4b</code></td>
</tr>
</tbody>
</table>
<h3 id="mailing-list">Mailing List</h3>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This is applicable to OpenLDAP. For SQL backends, please use mail alias
account as mailing list.</p>
</div>
<table>
<thead>
<tr>
<th>URL</th>
<th>HTTP Method</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
<tr>
<td>/api/maillist/&lt;mail></td>
<td>POST</td>
<td>Create a new mailing list</td>
</tr>
<tr>
<td>/api/maillist/&lt;mail></td>
<td>DELETE</td>
<td>Delete an existing mailing list</td>
</tr>
<tr>
<td>/api/maillist/&lt;mail></td>
<td>PUT</td>
<td>Update profile of an existing mailing list</td>
</tr>
</tbody>
</table>
<p>Possible <code>PUT</code> parameters used to update account profile:</p>
<table>
<thead>
<tr>
<th>Parameter Name</th>
<th>Summary</th>
<th>Sample Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>cn</code></td>
<td>display name</td>
<td><code>cn=My List Name</code></td>
</tr>
<tr>
<td><code>accessPolicy</code></td>
<td>Defines who can send email to this mailing list</td>
<td><code>accessPolicy=public</code></td>
</tr>
</tbody>
</table>
<h3 id="mail-alias">Mail Alias</h3>
<table>
<thead>
<tr>
<th>URL</th>
<th>HTTP Method</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
<tr>
<td>/api/alias/&lt;mail></td>
<td>POST</td>
<td>Create a new mail alias</td>
</tr>
<tr>
<td>/api/alias/&lt;mail></td>
<td>DELETE</td>
<td>Delete an existing mail alias</td>
</tr>
<tr>
<td>/api/alias/&lt;mail></td>
<td>PUT</td>
<td>Update profile of an existing mail alias</td>
</tr>
</tbody>
</table>
<p>Possible <code>PUT</code> parameters used to update account profile:</p>
<table>
<thead>
<tr>
<th>Parameter Name</th>
<th>Summary</th>
<th>Sample Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>cn</code></td>
<td>display name</td>
<td><code>cn=My List Name</code></td>
</tr>
<tr>
<td><code>accessPolicy</code></td>
<td>Defines who can send email to this mail alias account</td>
<td><code>accessPolicy=public</code></td>
</tr>
</tbody>
</table>
<blockquote>
<p>Note: <code>accessPolicy</code> for mail alias account is only available for SQL backends.</p>
</blockquote>
<h3 id="throttling">Throttling</h3>
<table>
<thead>
<tr>
<th>URL</th>
<th>HTTP Method</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
<tr>
<td>/api/throttle/global/inbound</td>
<td>GET</td>
<td>Get global inbound throttle settings</td>
</tr>
<tr>
<td>/api/throttle/global/outbound</td>
<td>GET</td>
<td>Get global outbound throttle settings</td>
</tr>
<tr>
<td>/api/throttle/global/inbound</td>
<td>POST</td>
<td>Set global inbound throttle setting</td>
</tr>
<tr>
<td>/api/throttle/global/outbound</td>
<td>POST</td>
<td>Set global outbound throttle setting</td>
</tr>
<tr>
<td>/api/throttle/&lt;domain>/inbound</td>
<td>GET</td>
<td>Get domain inbound throttle settings</td>
</tr>
<tr>
<td>/api/throttle/&lt;domain>/outbound</td>
<td>GET</td>
<td>Get domain outbound throttle settings</td>
</tr>
<tr>
<td>/api/throttle/&lt;domain>/inbound</td>
<td>POST</td>
<td>Set domain inbound throttle setting</td>
</tr>
<tr>
<td>/api/throttle/&lt;domain>/outbound</td>
<td>POST</td>
<td>Set domain outbound throttle setting</td>
</tr>
<tr>
<td>/api/throttle/&lt;mail>/inbound</td>
<td>GET</td>
<td>Get user inbound throttle settings</td>
</tr>
<tr>
<td>/api/throttle/&lt;mail>/outbound</td>
<td>GET</td>
<td>Get user outbound throttle settings</td>
</tr>
<tr>
<td>/api/throttle/&lt;mail>/inbound</td>
<td>POST</td>
<td>Set user inbound throttle setting</td>
</tr>
<tr>
<td>/api/throttle/&lt;mail>/outbound</td>
<td>POST</td>
<td>Set user outbound throttle setting</td>
</tr>
</tbody>
</table>
<p>Possible <code>POST</code> parameters used to set throttle setting:</p>
<table>
<thead>
<tr>
<th>Parameter Name</th>
<th>Summary</th>
<th>Sample Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>period</code></td>
<td>Period of time (in seconds)</td>
<td><code>period=3600</code> (one hour)</td>
</tr>
<tr>
<td><code>msg_size</code></td>
<td>Max size of single email</td>
<td><code>msg_size=10485760</code> (10 MB)</td>
</tr>
<tr>
<td><code>max_msgs</code></td>
<td>Number of max inbound emails</td>
<td><code>max_msgs=20</code> (up to 20 messages)</td>
</tr>
<tr>
<td><code>max_quota</code></td>
<td>Cumulative size of all inbound emails</td>
<td><code>max_quota=1048576000</code> (1 GB)</td>
</tr>
</tbody>
</table>
<h2 id="sample-code-to-interact-with-iredadmin-pro-restful-api">Sample code to interact with iRedAdmin-Pro RESTful API</h2>
<ul>
<li><a href="./iredadmin-pro.restful.api.curl.html">iRedAdmin-Pro RESTful API (interact with <code>curl</code>)</a></li>
<li><a href="./iredadmin-pro.restful.api.python.html">iRedAdmin-Pro RESTful API (interact with Python)</a></li>
</ul><p style="text-align: center; color: grey;">All documents are available in <a href="https://bitbucket.org/zhb/iredmail-docs/src">BitBucket repository</a>, and published under <a href="http://creativecommons.org/licenses/by-nd/3.0/us/" target="_blank">Creative Commons</a> license. If you found something wrong, please do <a href="http://www.iredmail.org/contact.html">contact us</a> to fix it.<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-3293801-21', 'auto');
ga('send', 'pageview');
</script>
</body></html>