Introduction
Welcome to the Baruwa Enterprise Edition API documentation.
The Baruwa API allows you to manage a Baruwa Server, programmatic way using conventional HTTP requests. The endpoints are intuitive and powerful, allowing you to easily make calls to retrieve information or to execute actions. The Baruwa API is organized around REST and uses OAUTH 2.0 authentication. It is therefore possible to use off-the-shelf HTTP clients.
Most of the functionality that you are familiar with in the Baruwa web interface is also available through the API, allowing you to script the complex actions that your situation requires.
The API documentation will start with a general overview about the design and technology that has been implemented, followed by reference information about specific endpoints.
HTTP Requests
Any tool that is fluent in HTTP
can communicate with the API simply by requesting the
correct URI. Requests MUST
be made using the HTTPS
protocol so that traffic is encrypted.
The API responds to different methods depending on the action required.
METHOD | USAGE |
---|---|
GET | For simple retrieval of information. The information you request will be returned as a JSON object. Paged responses will contain links to the next and last pages. |
Any request using the GET method is read-only and will not affect any of the objects you are querying. |
|
POST | To create a new object, your request should specify the POST method and contain FORM data. |
The POST request should include all of the attributes necessary to create a new object. To create a new object, send a POST request to the target endpoint. |
|
PUT | To update an object, the PUT method is used. |
The PUT method will only update attributes that are different from the current state of the object. | |
DELETE | To remove an object, the DELETE method is used. |
This removes the object, this is not reversible. |
HTTP Responses
Response for a Single Object
{
"name": "example.com"
...
}
Response for an Object Collection
{
"items": [
{
"name": "example.com"
...
},
{
"name": "example.net"
...
}
]
}
When a request is successful, a response body will typically be sent back in the form of a JSON
object.
An exception to this is when a DELETE
request is processed, which will result in a successful HTTP 204
status and an empty response body.
4XX
Error messages will return a JSON object containing the HTTP error code and the description. 5XX
Error messages will be returned as text.
For responses containing multiple items, the JSON
object will contain the items key which will hold
the items and a links key which contains the links that you can request.
A Meta key contains the meta data.
Errors
HTTP Status Code Summary
HTTP/1.1 200 OK - Everything worked as expected.
HTTP/1.1 401 Unauthorized - OAUTH authentication failed.
HTTP/1.1 403 Forbidden - User not allowed to access this scope.
HTTP/1.1 412 Precondition Failed - Parameters were valid but request failed.
HTTP/1.1 404 Not Found - The requested item doesn't exist.
HTTP/1.1 500, 502, 503, 504 Server errors - something went wrong on the server.
Baruwa uses conventional HTTP response codes to indicate success or failure of an API request. In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that resulted from the provided information (e.g. a required parameter was missing, etc.), and codes in the 5xx range indicate an error on the Baruwa backend.
4XX
Error messages will return a JSON object containing the HTTP error code and the description. 5XX
Error messages will be returned as text.
Meta
Sample Meta Object
{
...
"meta": {
"total": 43
}
...
}
In addition to the main resource root, the response may also contain a meta
object. This object contains
information about the response itself.
The meta
object contains a total key that is set to the total number of objects returnable by the request.
This has implications on the links
object and pagination.
Links
Sample Links Object
{
...
"links": {
"pages": {
"last": "https://baruwa.example.com/api/v1/users?page=2",
"next": "https://baruwa.example.com/api/v1/users?page=2"
}
}
...
}
The links
object is returned as part of the response body when pagination is enabled. By default, 25 objects
are returned per page. If the response contains 25 objects or fewer, no links
object will be returned. If the
response contains more than 25 objects, the first 25 will be returned along with the links
object.
The links
object contains a pages
object. The pages
object, in turn, contains keys indicating the relationship
of additional pages. The values of these are the URLs of the associated pages. The keys will be one of the
following:
- first: The URI of the first page of results.
- prev: The URI of the previous sequential page of results.
- next: The URI of the next sequential page of results.
- last: The URI of the last page of results.
Curl Examples
Set and Export the CLIENT_ID and CLIENT_SECRET variables
export CLIENT_ID=28ec8ea4-a9c3-4315-99a9-5e1b170f03ef
export CLIENT_SECRET=iTEueRj9a94U43hl28Pnl6ZtBu3zsRRGdhLC5emF3uR8HjYkhW32ubknjoVa
Throughout this document, some example API requests will be given using the curl command. This will allow us to demonstrate the various endpoints in a simple, textual format.
The names of account-specific references (like Domain IDs, for instance) will be represented by variables. For
instance, a Domain ID may be represented by a variable called $DOMAIN_ID
. You can set the associated variables
in your environment if you wish to use the examples without modification.
The first variables that you should set to get started are your OAuth Client ID and Client Secret. The next section will go over the details of this.
Obtain a Client ID and Client Secret by going to the Apps & API section of the user account you want to use in
the web interface. You can use an existing Client ID and Secret if you have already created an application or
add an application using the "Register new Application" button. Copy the generated Client ID and Client Secret
and use them to set and export the CLIENT_ID
and CLIENT_SECRET
variables in your environment as shown in the
example.
OAuth Authentication
The Baruwa API
uses the OAuth 2.0
protocol to authorize calls. OAuth
is an
industry-standard open standard for authorization used by many companies to
provide secure access to protected resources. For details on authentication,
see How Baruwa Enterprise Edition uses OAuth 2.0
.
In order to interact with the Baruwa
API
, you or your application must authenticate.
The Baruwa API
handles this through OAuth
, OAuth
allows you to delegate access
to your system using read only or write scopes.
Create an Application
Navigate to the Apps & API
section of the user account. Click Register new Application
to
begin the application-creation process.
When you create a new application, Baruwa
generates a set of OAuth
keys for the application
(the keys consist of a client_id
and client_secret
).
The client_id
and client_secret
are displayed to you after the application is created, you
can view existing keys by clicking the application name in the list in the Apps & API section
of the user account.
Get an access token
Example access token request
curl -v -X POST https://baruwa.example.com/api/v1/oauth/token \
-H "Accept: application/json" \
-d "grant_type=password" -d "username=$CLIENT_ID" \
-d "password=$CLIENT_SECRET"
Make a /api/v1/token
call using your application's OAuth keys for username and password values
(the keys are the values of your client_id and client_secret).
In the request body, set grant_type
to password
, username
to client_id
and password
to
client_secret
. When you make the call, Baruwa generates and returns a new access token.
The token returned is a Bearer Token, to run the examples below you need to set your TOKEN
enviroment variable to this token.
Please save this token in a safe place it is only displayed once.
Make an API call
With a valid access token in hand, you're ready to make API requests.
How to Authenticate with OAuth
Authenticate with a Bearer Authorization Header
curl -H "Accept: application/json" -H "Authorization: Bearer $TOKEN"
Send a bearer authorization header with your request. This method of authenticating completes the authorization request in the header portion, away from the actual request.
Revoke an access token
Revoke an access token
curl -v -X POST https://baruwa.example.com/api/v1/oauth/revoke \
-H "Accept: application/json" \
-d "token=$TOKEN" -d "username=$CLIENT_ID" \
-d "password=$CLIENT_SECRET"
Make a /api/v1/revoke
call using your application's OAuth keys for username and password values
(the keys are the values of your client_id and client_secret).
In the request body, set token
to $TOKEN
, When you make the call, Baruwa revokes the token
and returns an empty response.
Scopes
As mentioned earlier, all Baruwa API
end points are protected by Scopes (permissions)
in addition to
OAuth
authorization.
A Scope
is a permission setting that specifies access to Baruwa
data or process.
The following scopes can be assigned to an OAuth
client application:
Name | Action | Mode | Description | Account Type Access |
---|---|---|---|---|
act-read | Read | READ-ONLY | Accounts: Read | Admin & Domain Admin |
act-create | Create | READ-WRITE | Accounts: Create | Admin & Domain Admin |
act-update | Update | READ-WRITE | Accounts: Update | Admin & Domain Admin |
act-delete | Delete | READ-WRITE | Accounts: Delete | Admin & Domain Admin |
dom-read | Read | READ-ONLY | Domains: Read | Admin & Domain Admin |
dom-create | Create | READ-WRITE | Domains: Create | Admin |
dom-update | Update | READ-WRITE | Domains: Update | Admin & Domain Admin |
dom-delete | Delete | READ-WRITE | Domains: Delete | Admin & Domain Admin |
org-read | Read | READ-ONLY | Organizations: Read | Admin |
org-create | Create | READ-WRITE | Organizations: Create | Admin |
org-update | Update | READ-WRITE | Organizations: Update | Admin |
org-delete | Delete | READ-WRITE | Organizations: Delete | Admin |
sta-read | Read | READ-ONLY | Status: Read | Admin & Domain Admin |
Accounts
Account objects are users accounts that are configured on the Baruwa server.
The standard account attributes are:
Attribute | Type | Description |
---|---|---|
username | String | The username for the account |
firstname | String | The first names |
lastname | String | The last names |
password1 | String | This must be a strong password |
password2 | String | This must be a strong password |
String | A valid email address | |
timezone | String | Users timezone, all dates and times will be displayed in this timezone |
account_type | Number | The account type |
domains | Number | The domains to which this user belongs |
active | Boolean | Enable or disable this entry |
send_report | Boolean | If enabled the user will receive reports from the system, these include quarantine as well as summary reports |
spam_checks | Boolean | Enable or disable spam checking of email sent to and from this users email addresses |
low_score | Number | The score at which an email is considered to be suspected spam. |
high_score | Number | The score at which an email is considered to be definitely spam. |
block_macros | Boolean | Enable or disable blocking Attachments with Macros |
List all Accounts
List all Accounts
curl -v -X GET https://baruwa.example.com/api/v1/users \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.get_users()
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_users()
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $res = $api->get_users();
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
u *api.UserList
opts *api.ListOptions
b []byte
err error
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if u, err = c.GetUsers(opts); err != nil {
log.Fatal(err)
}
if len(u.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(u); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if u.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: u.Links.Pages.Next,
}
}
}
Sample response of list all Accounts
{
"items": [{
"username": "fuzzy@example.com",
"send_report": false,
"account_type": 3,
"addresses": [],
"firstname": "Fuzzy",
"organizations": [],
"lastname": "Lumpkins",
"spam_checks": false,
"email": "fuzzy@example.com",
"low_score": 2.0,
"high_score": 12.0,
"created_on": "2014:09:20:15:14:30",
"last_login": "2014:10:03:08:54:28",
"active": true,
"block_macros": true,
"timezone": "Africa/Abidjan",
"local": true,
"id": 4,
"domains": [{
"name": "example.com",
"id": 4
}]
}, {
"username": "rowdyrough",
"send_report": false,
"account_type": 3,
"addresses": [],
"firstname": "Rowdy",
"organizations": [],
"lastname": "Rough",
"spam_checks": false,
"email": "rowdyrough@example.com",
"low_score": 0.0,
"high_score": 0.0,
"created_on": "2014:10:07:06:35:48",
"last_login": "2014:10:11:22:38:11",
"active": true,
"block_macros": true,
"timezone": "Africa/Johannesburg",
"local": true,
"id": 5,
"domains": [{
"name": "example.com",
"id": 4
}]
}],
"meta": {
"total": 2
}
}
To retrieve a list of all of the users in your account, send a GET
request to /api/v1/users
.
For administrator accounts this will list all the users on the system, for Domain administrators
it will contain users within all domains the Domain administrator is administrator for.
The response will be a JSON
object with a key called items. The value of this will be an array of
Account objects, each of which contain the extended account attributes as described above.
Create a new Account
Create an Account
curl -v -X POST https://baruwa.example.com/api/v1/users \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "username=blossom" \
-d "firstname=Blossom" \
-d "lastname=Utonium" \
-d "password1=ng5qhhbiwozcANc3" \
-d "password2=ng5qhhbiwozcANc3" \
-d "email=blossom@example.com" \
-d "timezone=Africa/Johannesburg" \
-d "account_type=3" \
-d "domains=9" \
-d "active=y" \
-d "send_report=y" \
-d "spam_checks=y" \
-d "low_score=0.0" \
-d "high_score=0.0"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
data = {
:username => "blossom",
:firstname => "Blossom",
:lastname => "Utonium",
:password1 => "ng5qhhbiwozcANc3",
:password2 => "ng5qhhbiwozcANc3",
:email => "blossom@example.com",
:timezone => "Africa/Johannesburg",
:account_type => "3",
:domains => "9",
:active => "y",
:send_report => "y",
:spam_checks => "y",
:low_score => "0.0",
:high_score => "0.0"
}
api.create_user(data)
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
data = {
"username": "blossom",
"firstname": "Blossom",
"lastname": "Utonium",
"password1": "ng5qhhbiwozcANc3",
"password2": "ng5qhhbiwozcANc3",
"email": "blossom@example.com",
"timezone": "Africa/Johannesburg",
"account_type": "3",
"domains": "9",
"active": "y",
"send_report": "y",
"spam_checks": "y",
"low_score": "0.0",
"high_score": "0.0"}
api.create_user(data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
password1 => 'ng5qhhbiwozcANc3',
password2 => 'ng5qhhbiwozcANc3',
account_type => 3,
low_score => 0.0,
active => 1,
timezone => 'Africa/Johannesburg',
spam_checks => 1,
high_score => 0.0,
send_report => 1,
domains => 9,
username => 'rowdyrough',
firstname => 'Rowdy',
lastname => 'Rough',
email => 'rowdyrough@example.com',
block_macros => 1,
};
my $res = $api->create_user($data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
u *api.User
f *api.UserForm
b []byte
err error
accountType *int
lowScore, highScore api.LocalFloat64
domains, organizations *[]int
enabled, sendReports, spamChecks, blockMacros *bool
username, firstname, lastname, password1, password2, email, timezone *string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.UserForm{
Username: username,
Firstname: firstname,
Lastname: lastname,
Password1: password1,
Password2: password2,
Email: email,
Timezone: timezone,
AccountType: accountType,
Enabled: enabled,
SendReport: sendReports,
SpamChecks: spamChecks,
LowScore: &lowScore,
HighScore: &highScore,
BlockMacros: blockMacros,
Domains: *domains,
Organizations: *organizations,
}
if u, err = c.CreateUser(f); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(u); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
To create a new Account, send a POST
request to /api/v1/users
.
Set the standard attributes described above.
Retrieve an existing Account
Retrieve an existing Account
curl -v -X GET https://baruwa.example.com/api/v1/users/$USER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
userid = 1
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.get_user(userid)
from BaruwaAPI import BaruwaAPIClient
userid = 5
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_user(userid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $userid = 1;
my $res = $api->get_user($userid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
u *api.User
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if u, err = c.GetUser(id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(u); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output retrieve an existing Account
{
"username": "rowdyrough",
"send_report": false,
"account_type": 3,
"addresses": [],
"firstname": "Rowdy",
"organizations": [],
"lastname": "Rough",
"spam_checks": false,
"email": "rowdyrough@example.com",
"low_score": 0.0,
"high_score": 0.0,
"created_on": "2014:10:07:06:35:48",
"last_login": "2014:10:11:22:38:11",
"active": true,
"block_macros": true,
"timezone": "Africa/Johannesburg",
"local": true,
"id": 5,
"domains": [{
"name": "example.com",
"id": 4
}]
}
To get details about a specific account, send a GET
request to /api/v1/users/$USER_ID
.
The response will be a JSON
object that contains the extended attributes defined for an
account as described above.
Update an Account
Update an Account
curl -v -X PUT https://baruwa.example.com/api/v1/users \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "username=blossom" \
-d "firstname=Blossom" \
-d "lastname=Utonium" \
-d "password1=ng5qhhbiwozcANc3" \
-d "password2=ng5qhhbiwozcANc3" \
-d "email=blossom@example.com" \
-d "timezone=Africa/Johannesburg" \
-d "account_type=3" \
-d "domains=9" \
-d "send_report=y" \
-d "spam_checks=y" \
-d "low_score=5.5" \
-d "high_score=12.2"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
data = {
:id => 1,
:username => "blossom",
:firstname => "Blossom",
:lastname => "Utonium",
:password1 => "ng5qhhbiwozcANc3",
:password2 => "ng5qhhbiwozcANc3",
:email => "blossom@example.com",
:timezone => "Africa/Johannesburg",
:account_type => "3",
:domains => "9",
:active => "y",
:send_report => "y",
:spam_checks => "y",
:low_score => "0.0",
:high_score => "0.0"
}
api.update_user(data)
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
data = {
"username": "blossom",
"firstname": "Blossom",
"lastname": "Utonium",
"password1": "ng5qhhbiwozcANc3",
"password2": "ng5qhhbiwozcANc3",
"email": "blossom@example.com",
"timezone": "Africa/Johannesburg",
"account_type": "3",
"domains": "9",
"active": "y",
"send_report": "y",
"spam_checks": "y",
"low_score": "5.0",
"high_score": "10.0"}
api.update_user(data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $update_data = {
low_score => 5.5,
active => 1,
timezone => 'Africa/Johannesburg',
spam_checks => 1,
high_score => 10.2,
send_report => 1,
domains => 9,
username => 'rowdyrough',
firstname => 'Rowdy',
lastname => 'Rough',
email => 'rowdyrough@example.com',
block_macros => 0,
};
my $res = $api->update_user($update_data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
f *api.UserForm
err error
accountType *int
lowScore, highScore api.LocalFloat64
domains, organizations *[]int
enabled, sendReports, spamChecks, blockMacros *bool
username, firstname, lastname, password1, password2, email, timezone *string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.UserForm{
Username: username,
Firstname: firstname,
Lastname: lastname,
Password1: password1,
Password2: password2,
Email: email,
Timezone: timezone,
AccountType: accountType,
Enabled: enabled,
SendReport: sendReports,
SpamChecks: spamChecks,
LowScore: &lowScore,
HighScore: &highScore,
BlockMacros: blockMacros,
Domains: *domains,
Organizations: *organizations,
}
if err = c.UpdateUser(f); err != nil {
log.Fatal(err)
}
fmt.Printf("The user: %s has been updated\n", *username)
}
To update an Account, send a PUT
request to /api/v1/users/$USER_ID
.
Delete an Account
Delete an existing Account
curl -v -X DELETE https://baruwa.example.com/api/v1/users/$USER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
userid = 10
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.delete_user(userid)
from BaruwaAPI import BaruwaAPIClient
userid = 10
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.delete_user(userid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $update_data = {
low_score => 5.5,
active => 1,
timezone => 'Africa/Johannesburg',
spam_checks => 1,
high_score => 10.2,
send_report => 1,
domains => 9,
username => 'rowdyrough',
firstname => 'Rowdy',
lastname => 'Rough',
email => 'rowdyrough@example.com',
block_macros => 0,
};
my $res = $api->delete_user($update_data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
err error
uid int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if err = c.DeleteUser(uid); err != nil {
log.Fatal(err)
}
fmt.Printf("The user with id: %d has been deleted\n", uid)
}
To delete an Account, send a DELETE
request to /api/v1/users/$USER_ID
.
The Account will be deleted and the response status will be a 204
. This
indicates a successful request with no body returned
Passwords
Domain administrator and normal user account passwords can be changed using the API, administrator accounts can only be changed using the command line.
Change a password
Change an Account password
curl -v -X POST https://baruwa.example.com/api/v1/users/chpw/$USER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "password1=Hp9hzcd1grdSqtrn" \
-d "password2=Hp9hzcd1grdSqtrn"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $update_passwd_data = {
password1 => 'ng5qhhbiwozcANc3',
password2 => 'ng5qhhbiwozcANc3',
};
my $userid = 1;
my $res = $api->set_user_passwd($userid, $update_passwd_data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
f *api.PasswordForm
err error
uid int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.PasswordForm{
Password1: "Hp9hzcd1grdSqtrn",
Password2: "Hp9hzcd1grdSqtrn",
}
if err = c.ChangeUserPassword(uid, f); err != nil {
log.Fatal(err)
}
fmt.Printf("The user with id: %d password has been updated\n", uid)
}
To change an Account password, send a POST
request to /api/v1/users/chpw/$USER_ID
.
The password will be changed and the response status will be a 204
. This
indicates a successful request with no body returned
Alias Addresses
Alias Addresses are added to users accounts on the Baruwa server to enable the user to access email from or to email aliases that belong to them.
Create an Alias Address
Create an Alias Address
curl -v -X POST https://baruwa.example.com/api/v1/aliasaddresses/$USER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=info@example.com" \
-d "enabled=y"
require 'baruwa'
userid = 2
data = {
:enabled => "y",
:address => "info@example.com"
}
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.create_alias(userid, data)
from BaruwaAPI import BaruwaAPIClient
userid = 2
data = {
"enabled": "y",
"address": "info@example.com"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.create_alias(userid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $userid = 1;
my $data = {
address => 'info@example.com',
enabled => 1
};
my $res = $api->create_alias($userid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
a *api.AliasAddress
b []byte
err error
uid int
email string
enabled bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
a = &api.AliasAddress{
Address: email,
Enabled: enabled,
}
if err = c.CreateAliasAddress(uid, a); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(a); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output from Create an Alias Address
{
"enabled": true,
"id": 3,
"address": "info@example.com"
}
To create an Alias Address, send a POST
request to /api/v1/aliasaddresses/$USER_ID
Retrieve an existing Alias Address
Retrieve an existing Alias Address
curl -v -X GET https://baruwa.example.com/api/v1/aliasaddresses/$ADDRESS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
addressid = 3
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.get_aliases(addressid)
from BaruwaAPI import BaruwaAPIClient
addressid = 3
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_aliases(addressid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $addressid = 1;
my $res = $api->get_aliases($addressid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
a *api.AliasAddress
b []byte
err error
aid int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if a, err = c.GetAliasAddress(aid); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(a); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output from Retrieve an existing Alias Address
{
"enabled": true,
"id": 3,
"address": "info@example.com"
}
To retrieve an existing Alias Address, send a GET
request to /api/v1/aliasaddresses/$ADDRESS_ID
Update an Alias Address
Update an Alias Address
curl -v -X PUT https://baruwa.example.com/api/v1/aliasaddresses/$ADDRESS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=info@example.com" \
require 'baruwa'
addressid = 3
data = {
:enabled => "y",
:address => "info@example.com"
}
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.update_alias(addressid, data)
from BaruwaAPI import BaruwaAPIClient
addressid = 3
data = {
"address": "info@example.com"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.update_alias(addressid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $addressid = 3
my $data = {
address => 'info@example.com',
enabled => 1
};
my $res = $api->update_alias($addressid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
a *api.AliasAddress
err error
aid int
email string
enabled bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if a, err = c.GetAliasAddress(aid); err != nil {
log.Fatal(err)
}
a.Address = email
a.Enabled = enabled
if err = c.UpdateAliasAddress(a); err != nil {
log.Fatal(err)
}
fmt.Printf("The alias address: %s has been updated\n", a.Address)
}
Sample output from Update an Alias Address
{
"enabled": false,
"id": 3,
"address": "info@example.com"
}
To update an Alias Address, send a PUT
request to /api/v1/aliasaddresses/$ADDRESS_ID
Delete an Alias Address
Delete an Alias Address
curl -v -X DELETE https://baruwa.example.com/api/v1/aliasaddresses/$ADDRESS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=info@example.com" \
require 'baruwa'
addressid = 3
data = {
:enabled => "y",
:address => "info@example.com"
}
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.delete_alias(addressid, data)
from BaruwaAPI import BaruwaAPIClient
addressid = 3
data = {
"address": "info@example.com"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.delete_alias(addressid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $addressid = 3
my $data = {
address => 'info@example.com',
enabled => 1
};
my $res = $api->delete_alias($addressid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
a *api.AliasAddress
err error
aid int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if a, err = c.GetAliasAddress(aid); err != nil {
log.Fatal(err)
}
if err = c.DeleteAliasAddress(a); err != nil {
log.Fatal(err)
}
fmt.Printf("The alias address: %s has been deleted\n", a.Address)
}
To delete an Alias Address, send a DELETE
request to /api/v1/aliasaddresses/$ADDRESS_ID
The Alias Address will be deleted and the response status will be a 204
. This indicates a
successful request with no body returned
Domains
Domain resources are domain names that you have configured to process email for via the Baruwa server.
The standard domain attributes are:
Attribute | Type | Description |
---|---|---|
name | String | Domain name for which email is processed |
site_url | String | Customize the url that is used in links generated for reports for users in this domain. This url needs to be configured to point to this system otherwise it will create incorrect links in the reports. This must be the full base url for example https://antispam.example.com |
status | Boolean | Enable or disable this entry |
accept_inbound | Boolean | Enable or disable accepting of inbound mail to this domain |
discard_mail | Boolean | Discard all mail sent to this domain |
smtp_callout | Boolean | Enable SMTP callout based recipient verification. The recipients of email sent to this domain will be checked on the delivery server(s) configured for the domain |
ldap_callout | Boolean | Enable LDAP email address verification for this domain. If enabled, the recipients of email sent to this domain will be checked aganist an LDAP directory prior to being accepted, you need to have an authentication server entry of type LDAP for this to work correctly. |
virus_checks | Boolean | Enable or disable virus checks for this domain |
virus_checks_at_smtp | Boolean | Run Virus Checks at SMTP time, if disabled virus checks will be ran after SMTP time allowing you to quarantine virus infected messages |
block_macros | Boolean | Enable or disable blocking Attachments with Macros |
spam_checks | Boolean | Enable or disable spam checks for this domain. |
spam_actions | Number | What to do with messages that score at or above the Probable spam score but below the Definite spam score, these scores can be set below |
highspam_actions | Number | What to do with messages that score at or above the Definite spam score, this score can be set below |
virus_actions | Number | What to do with messages that are virus infected |
low_score | Number | The score at which an email is considered to be suspected spam. |
high_score | Number | The score at which an email is considered to be definitely spam. |
message_size | String | The maximum message size for email sent to and from email addresses under this domain, the format is 2B,2K,2M for bytes,kilobytes,megabytes respectively |
delivery_mode | Number | If the domain has more than one server where clean mail is delivered how should the deliveries be done, load balanced and failover delivery is supported |
language | String | The default language for users under this domain |
timezone | String | The default timezone for users under this domain |
report_every | Number | How often PDF reports should be sent |
organizations | Number | The organizations that own this domain. This is the Organisation ID |
The following options can be set for spam_actions
, highspam_actions
, virus_actions
:
Value | Option | Description |
---|---|---|
1 | Deliver | Deliver the email to the destination |
2 | Quarantine | Quarantine the email |
3 | Delete | Delete the email |
The following options can be set for delivery_mode
:
Value | Option | Description |
---|---|---|
1 | Load balance | Load balance the delivery of messages the configured delivery servers |
2 | Fail over | Deliver to one server until it fails then try the others |
The following options can be set for report_every
:
Value | Option | Description |
---|---|---|
0 | Disabled | Disable the sending of Domain reports |
1 | Daily | Send a Domain report daily |
2 | Weekly | Send a Domain report weekly |
3 | Monthly | Send a Domain report monthly |
Domains contain the following extended attributes
- Delivery Servers
- Authentication Settings
- Alias Domains
- DKIM Keys
- Domain email signatures
The following extended attributes are returned for Delivery Servers
. An array
is returned and contains an object with the following attributes.
Attribute | Type | Description |
---|---|---|
id | Number | Deliver Server ID |
address | String | Server address |
port | Number | Server Port |
The following extended attributes are returned for Authentication Settings
.
An array is returned and contains an object with the following attributes.
Attribute | Type | Description |
---|---|---|
id | Number | Deliver Server ID |
address | String | Server address |
protocol | Number | Authentication Protocol |
The following extended attributes are returned for Alias Domains
.
An array is returned and contains an object with the following attributes.
Attribute | Type | Description |
---|---|---|
id | Number | Domain Alias ID |
name | String | Domain Alias Name |
The following extended attributes are returned for DKIM Keys
. An array is
returned and contains an object with the following attributes.
Attribute | Type | Description |
---|---|---|
id | Number | DKIM Key ID |
The following extended attributes are returned for Domain email signatures
.
An array is returned and contains an object with the following attributes.
Attribute | Type | Description |
---|---|---|
id | Number | Signature ID |
type | Number | Signature Type 1 for text, 2 for html |
List all Domains
List all Domains
curl -v https://baruwa.example.com/api/v1/domains \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $res = $api->get_domains();
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.DomainList
opts *api.ListOptions
b []byte
err error
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if d, err = c.GetDomains(opts); err != nil {
log.Fatal(err)
}
if len(d.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if d.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: d.Links.Pages.Next,
}
}
}
Sample Response
{
"items": [{
"signatures": [{
"type": 1,
"id": 1
}],
"highspam_actions": 2,
"delivery_mode": 1,
"virus_checks": true,
"ldap_callout": false,
"dkimkeys": [],
"timezone": "Africa/Johannesburg",
"spam_actions": 2,
"id": 2,
"deliveryservers": [{
"address": "192.168.1.150",
"id": 2,
"port": 25
}],
"site_url": "https://mail.example.com",
"authservers": [{
"protocol": 2,
"id": 2,
"address": "mail.example.com"
}],
"report_every": 3,
"aliases": [{
"name": "mojo.example.com",
"id": 2
}],
"status": true,
"accept_inbound": true,
"discard_mail": false,
"virus_checks_at_smtp": true,
"low_score": 10.0,
"name": "example.com",
"language": "en",
"spam_checks": false,
"smtp_callout": false,
"message_size": "0",
"high_score": 20.0,
"virus_actions": 2
}, {
"signatures": [],
"highspam_actions": 2,
"delivery_mode": 1,
"virus_checks": true,
"ldap_callout": false,
"dkimkeys": [],
"timezone": "Africa/Johannesburg",
"spam_actions": 2,
"id": 4,
"deliveryservers": [{
"address": "192.168.1.150",
"id": 4,
"port": 25
}],
"site_url": "https://mail.example.net",
"authservers": [],
"report_every": 3,
"aliases": [],
"status": true,
"discard_mail": false,
"virus_checks_at_smtp": false,
"low_score": 0.0,
"name": "example.net",
"language": "en",
"spam_checks": true,
"smtp_callout": true,
"message_size": "0",
"high_score": 0.0,
"virus_actions": 2
}],
"meta": {
"total": 2
}
}
To retrieve a list of all of the domains in your account, send a GET
request to /api/v1/domains
.
For administrator accounts this will list all the domains on the system, for Domain administrators
it will contain all domains the Domain administrator is administrator for.
The response will be a JSON
object with a key called items. The value of this will be an array of
Domain
objects, each of which contain the extended domain attributes as described above.
Create a new Domain
Create a Domain
curl -v -X POST https://baruwa.example.com/api/v1/domains \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "name=example.net" \
-d "site_url=http://baruwa.example.net" \
-d "status=y" \
-d "discard_mail=" \
-d "smtp_callout=" \
-d "ldap_callout=" \
-d "virus_checks=y" \
-d "virus_checks_at_smtp=y" \
-d "spam_checks=y" \
-d "spam_actions=3" \
-d "highspam_actions=3" \
-d "virus_actions=3" \
-d "low_score=0.0" \
-d "high_score=0.0" \
-d "message_size=0" \
-d "delivery_mode=1" \
-d "language=en" \
-d "timezone=Africa/Johannesburg" \
-d "report_every=3" \
-d "organizations=1"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
name => "example.net",
site_url => "http://baruwa.example.net",
status => 1,
accept_inbound => 1,
discard_mail => 0,
smtp_callout => "",
ldap_callout => "",
virus_checks => 1,
virus_checks_at_smtp => 1,
block_macros => 1,
spam_checks => 1,
spam_actions => 3,
highspam_actions => 3,
virus_actions => 3,
low_score => "0.0",
high_score => "0.0",
message_size => 0,
delivery_mode => 1,
language => "en",
timezone => "Africa/Johannesburg",
report_every => 3,
organizations => 1,
};
my $res = $api->create_domain($data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.Domain
b []byte
err error
lowScore, highScore api.LocalFloat64
spamActions, highSpamActions, virusActions, deliveryMode, reportEvery int
organizations []int
name, siteURL, messageSize, language, timeZone string
enabled, acceptInbound, discardMail, smtpCallout, ldapCallout bool
virusChecks, virusChecksAtSMTP, blockMacros, spamChecks bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
d = &api.Domain{
Name: name,
SiteURL: siteURL,
MessageSize: messageSize,
Language: language,
Timezone: timeZone,
Enabled: enabled,
AcceptInbound: acceptInbound,
DiscardMail: discardMail,
SMTPCallout: smtpCallout,
LdapCallout: ldapCallout,
VirusChecks: virusChecks,
VirusChecksAtSMTP: virusChecksAtSMTP,
BlockMacros: blockMacros,
SpamChecks: spamChecks,
SpamActions: spamActions,
HighspamActions: highSpamActions,
VirusActions: virusActions,
DeliveryMode: deliveryMode,
ReportEvery: reportEvery,
Organizations: organizations,
LowScore: lowScore,
HighScore: highScore,
}
if err = c.CreateDomain(d); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample Response
{
"signatures": [],
"highspam_actions": 3,
"delivery_mode": 1,
"virus_checks": true,
"ldap_callout": true,
"dkimkeys": [],
"timezone": "Africa/Johannesburg",
"spam_actions": 3,
"id": 10,
"deliveryservers": [],
"site_url": "http://baruwa.example.net",
"authservers": [],
"report_every": 3,
"aliases": [],
"status": true,
"discard_mail": false,
"virus_checks_at_smtp": true,
"low_score": 0.0,
"name": "example.net",
"language": "en",
"spam_checks": true,
"smtp_callout": true,
"message_size": "0",
"high_score": 0.0,
"virus_actions": 3
}
To create a new Domain
, send a POST
request to /api/v1/domains
.
Set the standard attributes described above.
Retrieve a Domain
Retrieve an existing Domain
curl -v https://baruwa.example.com/api/v1/domains/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $domainid = 1;
my $res = $api->get_domain($domainid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.Domain
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if d, err = c.GetDomain(id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample Response
{
"signatures": [{
"type": 1,
"id": 1
}],
"highspam_actions": 2,
"delivery_mode": 1,
"virus_checks": true,
"ldap_callout": false,
"dkimkeys": [],
"timezone": "Africa/Johannesburg",
"spam_actions": 2,
"id": 1,
"deliveryservers": [{
"address": "192.168.1.150",
"id": 2,
"port": 25
}],
"site_url": "https://mail.example.com",
"authservers": [{
"protocol": 2,
"id": 2,
"address": "mail.example.com"
}],
"report_every": 3,
"aliases": [{
"name": "mojo.example.com",
"id": 2
}],
"status": true,
"discard_mail": false,
"virus_checks_at_smtp": true,
"low_score": 10.0,
"name": "example.com",
"language": "en",
"spam_checks": false,
"smtp_callout": false,
"message_size": "0",
"high_score": 20.0,
"virus_actions": 2
}
To get details about a specific domain, send a GET
request to /api/v1/domains/$DOMAIN_ID
.
The response will be a JSON
object that contains the extended attributes defined for a domain
as described above.
Retrieve a Domain by Name
Retrieve an existing Domain using the Domain name
curl -v https://baruwa.example.com/api/v1/domains/byname/$DOMAIN_NAME \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $domain_name = 'example.net';
my $res = $api->get_domain_by_name($domain_name);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.Domain
b []byte
err error
name string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if d, err = c.GetDomainByName(name); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample Response
{
"signatures": [{
"type": 1,
"id": 1
}],
"highspam_actions": 2,
"delivery_mode": 1,
"virus_checks": true,
"ldap_callout": false,
"dkimkeys": [],
"timezone": "Africa/Johannesburg",
"spam_actions": 2,
"id": 1,
"deliveryservers": [{
"address": "192.168.1.150",
"id": 2,
"port": 25
}],
"site_url": "https://mail.example.com",
"authservers": [{
"protocol": 2,
"id": 2,
"address": "mail.example.com"
}],
"report_every": 3,
"aliases": [{
"name": "mojo.example.com",
"id": 2
}],
"status": true,
"discard_mail": false,
"virus_checks_at_smtp": true,
"low_score": 10.0,
"name": "example.com",
"language": "en",
"spam_checks": false,
"smtp_callout": false,
"message_size": "0",
"high_score": 20.0,
"virus_actions": 2
}
To get details about a specific domain, send a GET
request to /api/v1/domains/byname/$DOMAIN_NAME
.
The response will be a JSON
object that contains the extended attributes defined for a domain
as described above.
Update a Domain
Update a Domain
curl -v -X PUT https://baruwa.example.com/api/v1/domains/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "name=example.com" \
-d "site_url=http://baruwa.example.net" \
-d "status=y" \
-d "discard_mail=y" \
-d "smtp_callout=" \
-d "ldap_callout=" \
-d "virus_checks=y" \
-d "virus_checks_at_smtp=y" \
-d "spam_checks=y" \
-d "spam_actions=3" \
-d "highspam_actions=3" \
-d "virus_actions=3" \
-d "low_score=0.0" \
-d "high_score=0.0" \
-d "message_size=0" \
-d "delivery_mode=1" \
-d "language=en" \
-d "timezone=Africa/Johannesburg" \
-d "report_every=3" \
-d "organizations=1"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
name => "example.net",
site_url => "http://baruwa.example.net",
status => 1,
accept_inbound => 1,
discard_mail => 0,
smtp_callout => "",
ldap_callout => "",
virus_checks => 1,
virus_checks_at_smtp => 1,
block_macros => 1,
spam_checks => 1,
spam_actions => 3,
highspam_actions => 3,
virus_actions => 3,
low_score => "0.0",
high_score => "0.0",
message_size => 0,
delivery_mode => 1,
language => "en",
timezone => "Africa/Johannesburg",
report_every => 3,
organizations => 1,
};
my $domainid = 1;
my $res = $api->update_domain($domainid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
d *api.Domain
err error
lowScore, highScore api.LocalFloat64
id, spamActions, highSpamActions, virusActions, deliveryMode, reportEvery int
organizations []int
name, siteURL, messageSize, language, timeZone string
enabled, acceptInbound, discardMail, smtpCallout, ldapCallout bool
virusChecks, virusChecksAtSMTP, blockMacros, spamChecks bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
d = &api.Domain{
ID: id,
Name: name,
SiteURL: siteURL,
MessageSize: messageSize,
Language: language,
Timezone: timeZone,
Enabled: enabled,
AcceptInbound: acceptInbound,
DiscardMail: discardMail,
SMTPCallout: smtpCallout,
LdapCallout: ldapCallout,
VirusChecks: virusChecks,
VirusChecksAtSMTP: virusChecksAtSMTP,
BlockMacros: blockMacros,
SpamChecks: spamChecks,
SpamActions: spamActions,
HighspamActions: highSpamActions,
VirusActions: virusActions,
DeliveryMode: deliveryMode,
ReportEvery: reportEvery,
Organizations: organizations,
LowScore: lowScore,
HighScore: highScore,
}
if err = c.UpdateDomain(d); err != nil {
log.Fatal(err)
}
fmt.Printf("The domain: %s has been updated\n", d.Name)
}
Sample response to update Domain
{
"signatures": [],
"highspam_actions": 3,
"delivery_mode": 1,
"virus_checks": true,
"ldap_callout": true,
"dkimkeys": [],
"timezone": "Africa/Johannesburg",
"spam_actions": 3,
"id": 10,
"deliveryservers": [],
"site_url": "http://baruwa.example.net",
"authservers": [],
"report_every": 3,
"aliases": [],
"status": true,
"discard_mail": true,
"virus_checks_at_smtp": true,
"low_score": 0.0,
"name": "example.com",
"language": "en",
"spam_checks": true,
"smtp_callout": true,
"message_size": "0",
"high_score": 0.0,
"virus_actions": 3
}
To update a Domain
, send a PUT
request to /api/v1/domains/$DOMAIN_ID
.
Delete a Domain
Delete an existing Domain
curl -v -X DELETE https://baruwa.example.com/api/v1/domains/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $domainid = 1;
my $res = $api->delete_domain($domainid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if err = c.DeleteDomain(id); err != nil {
log.Fatal(err)
}
fmt.Printf("The domain: %d has been deleted\n", id)
}
To delete a Domain, send a DELETE
request to /api/v1/domains/$DOMAIN_ID
.
The Domain will be deleted and the response status will be a 204
. This
indicates a successful request with no body returned
Domain Aliases
Some organisations have email addressed to the same account using different domain names, Alias domains allow users access to all their messages regardless of the domain name under a single login.
By adding an alias to a domain name, Baruwa
will accept and process email for that domain
alias as well. This simplifies configuration in cases where an organisation owns multiple
domains, for example example.com
, example.net
and example.org
. You can add example.com
as a domain and then add the others as domain aliases of example.com
Listing Domain Aliases
Listing all Domain Aliases under a Domain
curl -v -X GET https://baruwa.example.com/api/v1/domainaliases/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
domainid = 1
aliasid = 1
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.get_domainalias(domainid, aliasid)
from BaruwaAPI import BaruwaAPIClient
domainid = 1
aliasid = 1
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_domainalias(domainid, aliasid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $domainid = 1;
my $res = $api->get_domainaliases($domainid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.DomainAliasList
opts *api.ListOptions
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if d, err = c.GetDomainAliases(id, opts); err != nil {
log.Fatal(err)
}
if len(d.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if d.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: d.Links.Pages.Next,
}
}
}
Sample output from Listing all Domain Aliases under a Domain
{
"items": [{
"status": true,
"domain": {
"name": "example.com",
"id": 2
},
"id": 2,
"name": "example.net"
}],
"meta": {
"total": 1
}
}
To retrieve a list of Domain Aliases
assigned to a Domain
, send a GET
request to
/api/v1/domainaliases/$DOMAIN_ID
.
Create a Domain Alias
Create a new Domain Alias
curl -v -X POST https://baruwa.example.com/api/v1/domainaliases/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "name=example.net" \
-d "status=y" \
-d "domain=2"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.create_domainalias(domainid, data)
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.create_domainalias(domainid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
name => "example.net",
status => 1,
domain => 2,
accept_inbound => 1,
};
my $domainid = 1;
my $res = $api->create_domainalias($domainid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.DomainAlias
f *api.DomainAliasForm
b []byte
err error
did int
name string
enabled, acceptInbound bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.DomainAliasForm{
Name: name,
Enabled: enabled,
AcceptInbound: acceptInbound,
Domain: did,
}
if d, err = c.CreateDomainAlias(did, f); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output from Create a new Domain Alias
{
"status": true,
"domain": {
"name": "example.com",
"id": 2
},
"id": 4,
"name": "example.net"
}
To create a Domain Aliases
, send a POST
request to /api/v1/domainaliases/$DOMAIN_ID
.
Retrieve Domain Alias
Retrieve an existing Domain Alias
curl -v -X GET https://baruwa.example.com/api/v1/domainaliases/$DOMAIN_ID/$ALIAS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $aliasid = 10;
my $domainid = 1;
my $res = $api->get_domainalias($domainid, $aliasid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.DomainAlias
b []byte
err error
id, did int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if d, err = c.GetDomainAlias(did, id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output from Retrieve an existing Domain Alias
{
"status": true,
"domain": {
"name": "example.com",
"id": 2
},
"id": 4,
"name": "example.net"
}
To retrieve an existing Domain Alias
, send a GET
request to /api/v1/domainaliases/$DOMAIN_ID/$ALIAS_ID
.
Update a Domain Alias
Update a Domain Alias
curl -v -X PUT https://baruwa.example.com/api/v1/domainaliases/$DOMAIN_ID/$ALIAS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "name=example.net"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
name => "example.net",
status => 1,
domain => 2,
accept_inbound => 1,
};
my $aliasid = 10;
my $domainid = 1;
my $res = $api->update_domainalias($domainid, $aliasid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
d *api.DomainAlias
f *api.DomainAliasForm
err error
id, did int
name string
enabled, acceptInbound bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.DomainAliasForm{
ID: id,
Domain: did,
Name: name,
AcceptInbound: acceptInbound,
Enabled: enabled,
}
if err = c.UpdateDomainAlias(did, f); err != nil {
log.Fatal(err)
}
fmt.Printf("The domain alias: %s has been updated\n", d.Name)
}
Sample output from Update a Domain Alias
{
"status": false,
"domain": {
"name": "example.com",
"id": 2
},
"id": 4,
"name": "example.net"
}
To update a Domain Alias
, send a PUT
request to /api/v1/domainaliases/$DOMAIN_ID/$ALIAS_ID
.
Delete a Domain Alias
Delete a Domain Alias
curl -v -X DELETE https://baruwa.example.com/api/v1/domainaliases/$DOMAIN_ID/$ALIAS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "name=example.net"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
name => "example.net",
status => 1,
domain => 2,
accept_inbound => 1,
};
my $aliasid = 10;
my $domainid = 1;
my $res = $api->delete_domainalias($domainid, $aliasid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
d *api.DomainAlias
f *api.DomainAliasForm
err error
id, did int
name string
enabled, acceptInbound bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.DomainAliasForm{
ID: id,
Domain: did,
Name: name,
AcceptInbound: acceptInbound,
Enabled: enabled,
}
if err = c.DeleteDomainAlias(did, f); err != nil {
log.Fatal(err)
}
fmt.Printf("The domain alias: %s has been deleted\n", d.Name)
}
To delete a Domain Alias
, send a DELETE
request to /api/v1/domainaliases/$DOMAIN_ID/$ALIAS_ID
.
The Domain Alias will be deleted and the response status will be a 204
. This indicates a successful
request with no body returned
Delivery servers
Delivery servers
are the actual mail servers hosting the email accounts where messages processed by
Baruwa
need to be delivered.
Multiple servers per domain are supported and they can be configured to either load balance or fail over.
In load balance mode mail is sent to the group of servers in a round robin manner while in fail over mail is sent to the first in the list and only to the others if the first is not available.
Listing Delivery servers
Listing all Delivery servers for a Domain
curl -v -X GET https://baruwa.example.com/api/v1/deliveryservers/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
domainid = 9
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.get_deliveryservers(domainid)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_deliveryservers(domainid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $domainid = 1;
my $res = $api->get_deliveryservers($domainid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.DomainDeliveryServerList
opts *api.ListOptions
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if d, err = c.GetDomainDeliveryServers(id, opts); err != nil {
log.Fatal(err)
}
if len(d.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if d.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: d.Links.Pages.Next,
}
}
}
Sample output for Listing all Delivery servers for a Domain
{
"items": [{
"domain": {
"name": "example.com",
"id": 2
},
"protocol": 1,
"enabled": true,
"verification_only": false,
"id": 2,
"address": "192.168.1.150",
"port": 25
}],
"meta": {
"total": 1
}
}
To retrieve a list of Delivery servers
configured for a Domain
, send a GET
request to
/api/v1/deliveryservers/$DOMAIN_ID
.
Create a Delivery server
Create a new Delivery server
curl -v -X POST https://baruwa.example.com/api/v1/deliveryservers/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=1" \
-d "port=25" \
-d "require_tls=n" \
-d "verification_only=n" \
-d "enabled=y"
require 'baruwa'
domainid = 9
data = {
:address => "192.168.1.152",
:protocol => "1",
:port => "25",
:require_tls => "n",
:enabled => "y"
}
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.create_deliveryserver(domainid, data)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
data = {
"address": "192.168.1.152",
"protocol": "1",
"port": "25",
"require_tls": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.create_deliveryserver(domainid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $domainid = 1;
my $data = {
address => "192.168.1.151",
protocol => 1,
port => 25,
enabled => 1,
require_tls => 1,
verification_only => 1,
};
my $res = $api->create_deliveryserver($domainid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.DomainDeliveryServer
f *api.DomainDeliveryServerForm
id, protocol, port int
address string
enabled, requireTLS, verificationOnly bool
b []byte
err error
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.DomainDeliveryServerForm{
Address: address,
Enabled: enabled,
RequireTLS: requireTLS,
VerificationOnly: verificationOnly,
Protocol: protocol,
Port: port,
Domain: id,
}
if s, err = c.CreateDomainDeliveryServer(id, f); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Create a new Delivery server
{
"domain": {
"name": "example.com",
"id": 2
},
"protocol": 1,
"enabled": true,
"require_tls": false,
"verification_only": false,
"id": 9,
"address": "192.168.1.151",
"port": 25
}
To create a new Delivery server
, send a POST
request to /api/v1/deliveryservers/$DOMAIN_ID
.
Retrieve a Delivery server
Retrieve an existing Delivery server
curl -v -X GET https://baruwa.example.com/api/v1/deliveryservers/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
domainid = 9
serverid = 4
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.get_deliveryserver(domainid, serverid)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_deliveryserver(domainid, serverid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $domainid = 1;
my $res = $api->get_deliveryserver($domainid, $serverid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.DomainDeliveryServer
id, did int
b []byte
err error
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetDomainDeliveryServer(did, id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Retrieve an existing Delivery server
{
"domain": {
"name": "example.com",
"id": 2
},
"protocol": 1,
"enabled": true,
"require_tls": false,
"verification_only": false,
"id": 9,
"address": "192.168.1.151",
"port": 25
}
To retrieve an existing Delivery server
, send a GET
request to /api/v1/deliveryservers/$DOMAIN_ID/$SERVER_ID
.
Update a Delivery server
Update a Delivery server
curl -v -X PUT https://baruwa.example.com/api/v1/deliveryservers/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=1" \
-d "port=25"
require 'baruwa'
domainid = 9
serverid = 4
data = {
:address => "192.168.1.152",
:protocol => "1",
:port => "25",
:require_tls => "n",
:enabled => "y"
}
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.update_deliveryserver(domainid, serverid, data)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
data = {
"address": "192.168.1.153",
"protocol": "1",
"port": "25",
"require_tls": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.update_deliveryserver(domainid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
protocol => 1,
port => 25,
enabled => 1,
require_tls => 1,
verification_only => 1,
};
my $serverid = 12;
my $domainid = 1;
my $res = $api->update_deliveryserver($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.DomainDeliveryServer
f *api.DomainDeliveryServerForm
id, did, protocol, port int
address string
enabled, requireTLS, verificationOnly bool
err error
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.DomainDeliveryServerForm{
Address: address,
Enabled: enabled,
RequireTLS: requireTLS,
VerificationOnly: verificationOnly,
Protocol: protocol,
Port: port,
Domain: did,
}
if err = c.UpdateDomainDeliveryServer(did, f); err != nil {
log.Fatal(err)
}
fmt.Printf("The domain delivery server: %s has been updated\n", s.Address)
}
Sample output from Update a Delivery server
{
"domain": {
"name": "example.com",
"id": 2
},
"protocol": 1,
"enabled": false,
"require_tls": false,
"verification_only": false,
"id": 9,
"address": "192.168.1.151",
"port": 25
}
To update a Delivery server
, send a PUT
request to /api/v1/deliveryservers/$DOMAIN_ID/$SERVER_ID
.
Delete a Delivery server
Delete a Delivery server
curl -v -X DELETE https://baruwa.example.com/api/v1/deliveryservers/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151"
require 'baruwa'
domainid = 9
serverid = 4
data = {
:address => "192.168.1.152",
:protocol => "1",
:port => "25",
:require_tls => "n",
:enabled => "y"
}
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.delete_deliveryserver(domainid, serverid, data)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
data = {
"address": "192.168.1.153",
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.delete_deliveryserver(domainid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $domainid = 1;
my $res = $api->delete_deliveryserver($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.DomainDeliveryServer
f *api.DomainDeliveryServerForm
id, did, protocol, port int
address string
enabled, requireTLS, verificationOnly bool
err error
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.DomainDeliveryServerForm{
Address: address,
Enabled: enabled,
RequireTLS: requireTLS,
VerificationOnly: verificationOnly,
Protocol: protocol,
Port: port,
Domain: did,
ID: id,
}
if err = c.DeleteDomainDeliveryServer(did, f); err != nil {
log.Fatal(err)
}
fmt.Printf("The domain delivery server: %s has been deleted\n", s.Address)
}
To delete a Delivery server
, send a DELETE
request to /api/v1/deliveryservers/$DOMAIN_ID/$SERVER_ID
.
The Delivery server will be deleted and the response status will be a 204
. This indicates a successful
request with no body returned
User Delivery servers
User Delivery servers
are used to support split delivery of mail
for users on a per user basis.
Multiple servers per domain are supported. The User Delivery servers
are added to the domain to make them available for assignment to users
within the domain.
Listing User Delivery servers
Listing all User Delivery servers for a Domain
curl -v -X GET https://baruwa.example.com/api/v1/userdeliveryservers/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_deliveryservers(domainid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $domainid = 1;
my $res = $api->get_user_deliveryservers($domainid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.UserDeliveryServerList
opts *api.ListOptions
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if d, err = c.GetUserDeliveryServers(id, opts); err != nil {
log.Fatal(err)
}
if len(d.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if d.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: d.Links.Pages.Next,
}
}
}
Sample output for Listing all User Delivery servers for a Domain
{
"items": [{
"domain": {
"name": "example.com",
"id": 2
},
"protocol": 1,
"enabled": true,
"id": 2,
"address": "192.168.1.150",
"port": 25,
"require_tls": false,
"verification_only": false
}],
"meta": {
"total": 1
}
}
To retrieve a list of User Delivery servers
configured for a Domain
, send a GET
request to
/api/v1/userdeliveryservers/$DOMAIN_ID
.
Create a User Delivery server
Create a new User Delivery server
curl -v -X POST https://baruwa.example.com/api/v1/userdeliveryservers/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=1" \
-d "port=25" \
-d "require_tls=n" \
-d "verification_only=n" \
-d "enabled=y"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
data = {
"address": "192.168.1.152",
"protocol": "1",
"port": "25",
"require_tls": "n",
"verification_only": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.create_deliveryserver(domainid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
protocol => 1,
port => 25,
enabled => 1,
require_tls => 1,
verification_only => 1,
};
my $domainid = 1;
my $res = $api->create_user_deliveryserver($domainid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.UserDeliveryServer
f *api.UserDeliveryServerForm
b []byte
err error
id, protocol, port int
address string
enabled, requireTLS, verificationOnly bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.UserDeliveryServerForm{
Address: address,
Enabled: enabled,
RequireTLS: requireTLS,
VerificationOnly: verificationOnly,
Protocol: protocol,
Port: port,
Domain: id,
}
if s, err = c.CreateUserDeliveryServer(id, f); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Create a new User Delivery server
{
"domain": {
"name": "example.com",
"id": 2
},
"protocol": 1,
"enabled": true,
"require_tls": false,
"verification_only": false,
"id": 9,
"address": "192.168.1.151",
"port": 25
}
To create a new Delivery server
, send a POST
request to /api/v1/userdeliveryservers/$DOMAIN_ID
.
Retrieve a User Delivery server
Retrieve an existing User Delivery server
curl -v -X GET https://baruwa.example.com/api/v1/userdeliveryservers/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_deliveryserver(domainid, serverid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $domainid = 1;
my $res = $api->get_user_deliveryserver($domainid, $serverid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.UserDeliveryServer
b []byte
err error
id, did int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetUserDeliveryServer(did, id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Retrieve an existing User Delivery server
{
"domain": {
"name": "example.com",
"id": 2
},
"protocol": 1,
"enabled": true,
"require_tls": false,
"verification_only": false,
"id": 9,
"address": "192.168.1.151",
"port": 25
}
To retrieve an existing User Delivery server
, send a GET
request to /api/v1/userdeliveryservers/$DOMAIN_ID/$SERVER_ID
.
Update a User Delivery server
Update a User Delivery server
curl -v -X PUT https://baruwa.example.com/api/v1/userdeliveryservers/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=1" \
-d "port=25"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
data = {
"address": "192.168.1.153",
"protocol": "1",
"port": "25",
"require_tls": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.update_deliveryserver(domainid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
protocol => 1,
port => 25,
enabled => 1,
require_tls => 1,
verification_only => 1,
};
my $serverid = 12;
my $domainid = 1;
my $res = $api->update_user_deliveryserver($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
f *api.UserDeliveryServerForm
err error
id, did, protocol, port int
address string
enabled, requireTLS, verificationOnly bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.UserDeliveryServerForm{
ID: id,
Domain: did,
Address: address,
Enabled: enabled,
RequireTLS: requireTLS,
VerificationOnly: verificationOnly,
Protocol: protocol,
Port: port,
}
if err = c.UpdateUserDeliveryServer(did, f); err != nil {
log.Fatal(err)
}
fmt.Printf("The user delivery server: %s has been updated\n", f.Address)
}
Sample output from Update a User Delivery server
{
"domain": {
"name": "example.com",
"id": 2
},
"protocol": 1,
"enabled": false,
"require_tls": false,
"id": 9,
"address": "192.168.1.151",
"port": 25
}
To update a User Delivery server
, send a PUT
request to /api/v1/userdeliveryservers/$DOMAIN_ID/$SERVER_ID
.
Delete a User Delivery server
Delete a User Delivery server
curl -v -X DELETE https://baruwa.example.com/api/v1/userdeliveryservers/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
data = {
"address": "192.168.1.153",
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.delete_deliveryserver(domainid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
protocol => 1,
port => 25,
enabled => 1,
require_tls => 1,
verification_only => 1,
};
my $serverid = 12;
my $domainid = 1;
my $res = $api->delete_user_deliveryserver($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
f *api.UserDeliveryServerForm
err error
id, did, protocol, port int
address string
enabled, requireTLS, verificationOnly bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.UserDeliveryServerForm{
ID: id,
Domain: did,
Address: address,
Enabled: enabled,
RequireTLS: requireTLS,
VerificationOnly: verificationOnly,
Protocol: protocol,
Port: port,
}
if err = c.DeleteUserDeliveryServer(did, f); err != nil {
log.Fatal(err)
}
fmt.Printf("The user delivery server: %s has been deleted\n", f.Address)
}
To delete a User Delivery server
, send a DELETE
request to /api/v1/userdeliveryservers/$DOMAIN_ID/$SERVER_ID
.
The User Delivery server will be deleted and the response status will be a 204
. This indicates a successful
request with no body returned
Authentication Settings
Authentication settings allow users within a domain be be authenticated to an external authentication system.
This can be used for centralised user management and to allow users to use existing authentication credentials
instead of creating duplicate accounts on the Baruwa
system.
The supported external authentication mechanisms include:
- AD/LDAP
- SMTP
- POP3
- IMAP
- RADIUS
The AD/LDAP
mechanism allows for the user details in the directory to be automatically updated to the Baruwa
account created for them. These details include:
- First name
- Last name
- Primary Email Address
- Alias Email Addresses
Listing Authentication Settings
Listing all Authentication Settings for a Domain
curl -v -X GET https://baruwa.example.com/api/v1/authservers/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
domainid = 9
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.get_authservers(domainid)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_authservers(domainid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $domainid = 1;
my $res = $api->get_authservers($domainid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.AuthServerList
opts *api.ListOptions
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if d, err = c.GetAuthServers(id, opts); err != nil {
log.Fatal(err)
}
if len(d.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if d.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: d.Links.Pages.Next,
}
}
}
Sample output for Listing all Authentication Settings for a Domain
{
"items": [{
"protocol": 2,
"enabled": true,
"user_map_template": "example_%(user)s",
"split_address": true,
"address": "192.168.1.150",
"id": 2
}],
"meta": {
"total": 1
}
}
To retrieve a list of Authentication Settings
configured for a Domain
, send a GET
request to
/api/v1/authservers/$DOMAIN_ID
.
Create Authentication Settings
Create Authentication Settings for a Domain
curl -v -X POST https://baruwa.example.com/api/v1/authservers/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=2" \
-d "port=993" \
-d "enabled=y" \
-d "split_address=y" \
-d "user_map_template=example_%(user)s"
require 'baruwa'
domainid = 9
data = {
:address => "192.168.1.151",
:protocol => "2",
:port => "993",
:enabled => "y",
:split_address => "y",
:user_map_template => "example_%(user)s"
}
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.create_authserver(domainid, data)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
data = {
"address": "192.168.1.151",
"protocol": "2",
"port": "993",
"enabled": "y",
"split_address": "y",
"user_map_template": "example_%(user)s"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.create_authserver(domainid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
protocol => 2,
port => 993,
enabled => 1,
split_address => 1,
user_map_template => "example_%(user)s"
};
my $domainid = 1;
$res = $api->create_authserver($domainid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.AuthServer
b []byte
err error
did, protocol, port int
address, usm string
enabled, splitAddress bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.AuthServer{
Address: address,
Port: port,
UserMapTemplate: usm,
Protocol: protocol,
Enabled: enabled,
SplitAddress: splitAddress,
}
if err = c.CreateAuthServer(did, s); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Create Authentication Settings for a Domain
{
"protocol": 2,
"enabled": true,
"user_map_template": "example_%(user)s",
"split_address": true,
"address": "192.168.1.151",
"id": 5
}
To create Authentication Settings
, send a POST
request to /api/v1/authservers/$DOMAIN_ID
.
Retrieve Authentication Settings
Retrieve existing Authentication Settings
curl -v -X GET https://baruwa.example.com/api/v1/authservers/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
domainid = 9
serverid = 4
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.get_authserver(domainid, serverid)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_authserver(domainid, serverid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $domainid = 1;
my $res = $api->get_authserver($domainid, $serverid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.AuthServer
b []byte
err error
did, id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetAuthServer(did, id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Retrieve existing Authentication Settings
{
"protocol": 2,
"enabled": true,
"user_map_template": "example_%(user)s",
"split_address": true,
"address": "192.168.1.151",
"id": 5
}
To retrieve existing Authentication Settings
, send a GET
request to /api/v1/authservers/$DOMAIN_ID/$SERVER_ID
.
Update Authentication Settings
Update Authentication Settings
curl -v -X PUT https://baruwa.example.com/api/v1/authservers/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=2" \
-d "port=993" \
-d "enabled=y" \
-d "split_address=y" \
-d "user_map_template="
require 'baruwa'
domainid = 9
serverid = 3
data = {
:address => "192.168.1.151",
:protocol => "2",
:port => "993",
:enabled => "y",
:split_address => "y",
:user_map_template => "example_%(user)s"
}
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.update_authserver(domainid, serverid, data)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 3
data = {
"address": "192.168.1.151",
"protocol": "2",
"port": "995",
"enabled": "y",
"split_address": "y",
"user_map_template": "example_%(user)s"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.update_authserver(domainid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
protocol => 2,
port => 993,
enabled => 1,
split_address => 1,
user_map_template => "example_%(user)s"
};
my $serverid = 12;
my $domainid = 1;
my $res = $api->update_authserver($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.AuthServer
err error
did, protocol, port int
address, usm string
enabled, splitAddress bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.AuthServer{
Address: address,
Port: port,
UserMapTemplate: usm,
Protocol: protocol,
Enabled: enabled,
SplitAddress: splitAddress,
}
if err = c.UpdateAuthServer(did, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The authentication setting: %s has been updated\n", s.Address)
}
Sample output from Update Authentication Settings
{
"protocol": 2,
"enabled": true,
"user_map_template": "",
"split_address": true,
"address": "192.168.1.151",
"id": 5
}
To update Authentication Settings
, send a PUT
request to /api/v1/authservers/$DOMAIN_ID/$SERVER_ID
.
Delete Authentication Settings
Delete Authentication Settings
curl -v -X DELETE https://baruwa.example.com/api/v1/authservers/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=2" \
-d "port=993" \
-d "enabled=y" \
-d "split_address=y" \
-d "user_map_template="
require 'baruwa'
domainid = 9
serverid = 3
data = {
:address => "192.168.1.151",
:protocol => "2",
:port => "993",
:enabled => "y",
:split_address => "y",
:user_map_template => "example_%(user)s"
}
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
api.delete_authserver(domainid, serverid, data)
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 3
data = {
"address": "192.168.1.151",
"protocol": "2",
"port": "995",
"enabled": "y",
"split_address": "y",
"user_map_template": "example_%(user)s"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.delete_authserver(domainid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $domainid = 1;
my $data = {
address => "192.168.1.151",
protocol => 2,
port => 993,
enabled => 1,
split_address => 1,
user_map_template => "example_%(user)s"
};
my $res = $api->delete_authserver($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.AuthServer
err error
did, protocol, port int
address, usm string
enabled, splitAddress bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.AuthServer{
Address: address,
Port: port,
UserMapTemplate: usm,
Protocol: protocol,
Enabled: enabled,
SplitAddress: splitAddress,
}
if err = c.DeleteAuthServer(did, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The authentication setting: %s has been deleted\n", s.Address)
}
To delete a Authentication Settings
, send a DELETE
request to /api/v1/authservers/$DOMAIN_ID/$SERVER_ID
.
The Delivery server will be deleted and the response status will be a 204
. This indicates a successful
request with no body returned
Domain Smarthosts
Domain SmartHosts
are used to route outbound email via a Domain SmartHost
as
opposed to routing it via the DNS based lookup of the MX record.
Multiple Domain SmartHosts
per domain are supported.
Listing Domain Smarthosts
Listing all Domain Smarthosts for a Domain
curl -v -X GET https://baruwa.example.com/api/v1/domains/smarthosts/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_smarthosts(domainid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $domainid = 1;
my $res = $api->get_domain_smarthosts($domainid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
d *api.DomainSmartHostList
opts *api.ListOptions
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if d, err = c.GetDomainSmartHosts(id, opts); err != nil {
log.Fatal(err)
}
if len(d.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(d); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if d.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: d.Links.Pages.Next,
}
}
}
Sample output for Listing all Smarthosts for a Domain
{
"items": [{
"enabled": true,
"require_tls": false,
"id": 2,
"address": "192.168.1.150",
"username": "andrew",
"description": "outbound-archiver",
"port": 25
}],
"meta": {
"total": 1
}
}
To retrieve a list of Smarthosts
configured for a Domain
, send a GET
request to
/api/v1/domains/smarthosts/$DOMAIN_ID
.
Create a Domain Smarthost
Create a new Domain Smarthost
curl -v -X POST https://baruwa.example.com/api/v1/domains/smarthosts/$DOMAIN_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "username=andrew" \
-d "password=p4ssw0rd" \
-d "description=outbound-archiver" \
-d "port=25" \
-d "require_tls=y" \
-d "enabled=y"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
data = {
"address": "192.168.1.152",
"username": "andrew",
"password": "p4ssw0rd",
"description": "outbound-archiver",
"port": "25",
"require_tls": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.create_smarthost(domainid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
username => "andrew",
password => "p4ssw0rd",
port => 25,
require_tls => 1,
enabled => 1,
description => "outbound-archiver",
};
my $domainid = 1;
my $res = $api->create_domain_smarthost($domainid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.DomainSmartHost
b []byte
err error
did, port int
enabled, requireTLS bool
address, username, password, description string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.DomainSmartHost{
Address: address,
Username: username,
Password: password,
Description: description,
Enabled: enabled,
RequireTLS: requireTLS,
Port: port,
}
if err = c.CreateDomainSmartHost(did, s); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Create a new Domain Smarthost
{
"enabled": true,
"require_tls": false,
"id": 2,
"address": "192.168.1.150",
"username": "andrew",
"description": "outbound-archiver",
"port": 25
}
To create a new Smarthost
, send a POST
request to /api/v1/domains/smarthosts/$DOMAIN_ID
.
Retrieve a Domain Smarthost
Retrieve an existing Domain Smarthost
curl -v -X GET https://baruwa.example.com/api/v1/domains/smarthosts/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_smarthost(domainid, serverid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $domainid = 1;
my $res = $api->get_domain_smarthost($domainid, $serverid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.DomainSmartHost
b []byte
err error
id, did int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetDomainSmartHost(did, id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Retrieve an existing Domain Smarthost
{
"enabled": true,
"require_tls": false,
"id": 2,
"address": "192.168.1.150",
"username": "andrew",
"description": "outbound-archiver",
"port": 25
}
To retrieve an existing Domain Smarthost
, send a GET
request to /api/v1/domains/smarthosts/$DOMAIN_ID/$SERVER_ID
.
Update a Domain Smarthost
Update a Domain Smarthost
curl -v -X PUT https://baruwa.example.com/api/v1/domains/smarthosts/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=1" \
-d "port=25"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
data = {
"address": "192.168.1.152",
"username": "andrew",
"description": "outbound-archiver",
"port": "25",
"require_tls": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.update_smarthost(domainid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
username => "andrew",
password => "p4ssw0rd",
port => 25,
require_tls => 1,
enabled => 1,
description => "outbound-archiver",
};
my $serverid = 12;
my $domainid = 1;
my $res = $api->update_domain_smarthost($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.DomainSmartHost
err error
did, port int
enabled, requireTLS bool
address, username, password, description string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.DomainSmartHost{
Address: address,
Username: username,
Password: password,
Description: description,
Enabled: enabled,
RequireTLS: requireTLS,
Port: port,
}
if err = c.UpdateDomainSmartHost(did, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The domain smarthost: %s has been updated\n", s.Address)
}
Sample output from Update a Domain Smarthost
{
"enabled": true,
"require_tls": false,
"id": 2,
"address": "192.168.1.150",
"username": "andrew",
"description": "outbound-archiver",
"port": 25
}
To update a Domain Smarthost
, send a PUT
request to /api/v1/domains/smarthosts/$DOMAIN_ID/$SERVER_ID
.
Delete a Domain Smarthost
Delete a Domain Smarthost
curl -v -X DELETE https://baruwa.example.com/api/v1/domains/smarthosts/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
domainid = 9
serverid = 4
data = {
"address": "192.168.1.153",
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.delete_smarthost(domainid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
username => "andrew",
password => "p4ssw0rd",
port => 25,
require_tls => 1,
enabled => 1,
description => "outbound-archiver",
};
my $serverid = 12;
my $domainid = 1;
my $res = $api->delete_domain_smarthost($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.DomainSmartHost
err error
did, port int
enabled, requireTLS bool
address, username, password, description string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.DomainSmartHost{
Address: address,
Username: username,
Password: password,
Description: description,
Enabled: enabled,
RequireTLS: requireTLS,
Port: port,
}
if err = c.DeleteDomainSmartHost(did, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The domain smarthost: %s has been deleted\n", s.Address)
}
To delete a Domain Smarthost
, send a DELETE
request to /api/v1/domains/smarthosts/$DOMAIN_ID/$SERVER_ID
.
The Domain Smarthost will be deleted and the response status will be a 204
.
This indicates a successful request with no body returned
AD/LDAP Settings
AD/LDAP
authentication requires the following additional setting.
- Base DN - The LDAP Directory Base DN
- Username attribute - The username attribute, defaults to uid
- Email attribute - The email attribute, defaults to mail
- Bind DN - The BIND DN if Directory does not allow anonymous binds
- Bind password - The BIND password
- Use TLS - Use a TLS connection
- Search for UserDN - Find the UserDN then Bind to that
- Auth Search Filter - Filter used to find the UserDN, LDAP Search Filter Variables are supported
- Auth Search Scope - Search Scope, defaults to subtree
- Email Search Filter - Filter used to find email addresses, LDAP Search Filter Variables are supported
- Email Search Scope - Search Scope, defaults to subtree
Create AD/LDAP Settings
Create AD/LDAP Settings
curl -v -X POST https://baruwa.example.com/api/v1/ldapsettings/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "basedn=ou=Users,dc=example,dc=com" \
-d "nameattribute=uid" \
-d "emailattribute=mail" \
-d "binddn=uid=readonly-admin,ou=Users,dc=example,dc=com" \
-d "bindpw=P4ssW0rd" \
-d "usetls=y" \
-d "search_scope=subtree" \
-d "emailsearch_scope=subtree"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
basedn => "ou=Users,dc=example,dc=com",
nameattribute => "uid",
emailattribute => "mail",
binddn => "uid=readonly-admin,ou=Users,dc=example,dc=com",
bindpw => "P4ssW0rd",
usetls => 1,
usesearch => 0,
searchfilter => "",
search_scope => "subtree",
emailsearchfilter => "",
emailsearch_scope => "subtree"
};
my $serverid = 12;
my $domainid = 1;
my $res = $api->create_ldapsettings($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.LDAPSettings
b []byte
err error
did, sid int
useTLS, useSearch bool
basedn, nameattribute, emailattribute, binddn, bindpw string
searchfilter, searchScope, emailSearchFilter, emailSearchScope string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.LDAPSettings{
Basedn: basedn,
NameAttribute: nameattribute,
EmailAttribute: emailattribute,
BindDN: binddn,
BindPw: bindpw,
SearchFilter: searchfilter,
SearchScope: searchScope,
EmailSearchFilter: emailSearchFilter,
EmailSearchScope: emailSearchScope,
UseTLS: useTLS,
UseSearch: useSearch,
}
if err = c.CreateLDAPSettings(did, sid, s); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Create LDAP Settings
{
"binddn": "uid=readonly-admin,ou=Users,dc=example,dc=com",
"emailsearchfilter": "",
"emailsearch_scope": "subtree",
"searchfilter": "",
"search_scope": "subtree",
"authserver": {
"id": 6
},
"basedn": "ou=Users,dc=example,dc=com",
"usetls": true,
"usesearch": false,
"emailattribute": "mail",
"id": 2,
"nameattribute": "uid"
}
To create AD/LDAP Settings
, send a POST
request to /api/v1/ldapsettings/$DOMAIN_ID/$SERVER_ID
.
Retrieve AD/LDAP Settings
Retrieve existing AD/LDAP Settings
curl -v -X GET https://baruwa.example.com/api/v1/ldapsettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $domainid = 1;
my $settingsid = 20;
my $res = $api->get_ldapsettings($domainid, $serverid, $settingsid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.LDAPSettings
b []byte
err error
did, sid, lid int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetLDAPSettings(did, sid, lid); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Retrieve existing AD/LDAP Settings
{
"binddn": "uid=readonly-admin,ou=Users,dc=example,dc=com",
"emailsearchfilter": "",
"emailsearch_scope": "subtree",
"searchfilter": "",
"search_scope": "subtree",
"authserver": {
"id": 6
},
"basedn": "ou=Users,dc=example,dc=com",
"usetls": true,
"usesearch": false,
"emailattribute": "mail",
"id": 2,
"nameattribute": "uid"
}
To retrieve AD/LDAP Settings
, send a GET
request to /api/v1/ldapsettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID
.
Update AD/LDAP Settings
Update AD/LDAP Settings
curl -v -X PUT https://baruwa.example.com/api/v1/ldapsettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "basedn=ou=Users,dc=example,dc=com" \
-d "nameattribute=uid" \
-d "emailattribute=mail" \
-d "binddn=uid=readonly-admin,ou=Users,dc=example,dc=com" \
-d "bindpw=P4ssW0rd###" \
-d "search_scope=subtree" \
-d "emailsearch_scope=subtree"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $domainid = 1;
my $settingsid = 20;
my $res = $api->update_ldapsettings($domainid, $serverid, $settingsid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.LDAPSettings
err error
did, sid, lid int
useTLS, useSearch bool
basedn, nameattribute, emailattribute, binddn, bindpw string
searchfilter, searchScope, emailSearchFilter, emailSearchScope string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.LDAPSettings{
ID: lid,
Basedn: basedn,
NameAttribute: nameattribute,
EmailAttribute: emailattribute,
BindDN: binddn,
BindPw: bindpw,
SearchFilter: searchfilter,
SearchScope: searchScope,
EmailSearchFilter: emailSearchFilter,
EmailSearchScope: emailSearchScope,
UseTLS: useTLS,
UseSearch: useSearch,
}
if err = c.UpdateLDAPSettings(did, sid, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The ldap settings: %d have been updated\n", s.ID)
}
Sample output for Update LDAP Settings
{
"binddn": "uid=readonly-admin,ou=Users,dc=example,dc=com",
"emailsearchfilter": "",
"emailsearch_scope": "subtree",
"searchfilter": "",
"search_scope": "subtree",
"authserver": {
"id": 6
},
"basedn": "ou=Users,dc=example,dc=com",
"usetls": false,
"usesearch": false,
"emailattribute": "mail",
"id": 2,
"nameattribute": "uid"
}
To update AD/LDAP Settings
, send a PUT
request to /api/v1/ldapsettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID
.
Delete AD/LDAP Settings
Delete AD/LDAP Settings
curl -v -X DELETE https://baruwa.example.com/api/ldapsettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "basedn=ou=Users,dc=example,dc=com" \
-d "nameattribute=uid" \
-d "emailattribute=mail" \
-d "binddn=uid=readonly-admin,ou=Users,dc=example,dc=com" \
-d "bindpw=P4ssW0rd###" \
-d "search_scope=subtree" \
-d "emailsearch_scope=subtree"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
basedn => "ou=Users,dc=example,dc=com",
nameattribute => "uid",
emailattribute => "mail",
binddn => "uid=readonly-admin,ou=Users,dc=example,dc=com",
bindpw => "P4ssW0rd",
usetls => 1,
usesearch => 0,
searchfilter => "",
search_scope => "subtree",
emailsearchfilter => "",
emailsearch_scope => "subtree"
};
my $serverid = 12;
my $domainid = 1;
my $settingsid = 20;
my $res = $api->delete_ldapsettings($domainid, $serverid, $settingsid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.LDAPSettings
err error
did, sid, lid int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetLDAPSettings(did, sid, lid); err != nil {
log.Fatal(err)
}
if err = c.DeleteLDAPSettings(did, sid, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The ldap settings: %d have been deleted\n", s.ID)
}
To delete AD/LDAP Settings
, send a DELETE
request to /api/v1/ldapsettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID
.
The AD/LDAP Settings will be deleted and the response status will be a 204
. This indicates a successful
request with no body returned
RADIUS Settings
The RADIUS
protocol requires a shared secret between the client and the server, the additional settings allows
you to configure this.
Create RADIUS Settings
Create RADIUS Settings
curl -v -X POST https://baruwa.example.com/api/v1/radiussettings/$DOMAIN_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "secret=P4ssW0rd#" \
-d "timeout=30"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
secret => "P4ssW0rd#",
timeout => 30
};
my $serverid = 12;
my $domainid = 1;
my $res = $api->create_radiussettings($domainid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.RadiusSettings
b []byte
err error
secret string
did, sid, timeout int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.RadiusSettings{
Secret: secret,
Timeout: timeout,
}
if err = c.CreateRadiusSettings(did, sid, s); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Create RADIUS Settings
{
"authserver": {
"id": 7
},
"id": 1,
"timeout": 30
}
To create RADIUS Settings
, send a POST
request to /api/v1/radiussettings/$DOMAIN_ID/$SERVER_ID
.
Retrieve RADIUS Settings
Retrieve existing RADIUS Settings
curl -v -X GET https://baruwa.example.com/api/v1/radiussettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $domainid = 1;
my $settingsid = 20;
my $res = $api->get_radiussettings($domainid, $serverid, $settingsid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.RadiusSettings
b []byte
err error
did, sid, rid int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetRadiusSettings(did, sid, rid); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Retrieve existing RADIUS Settings
{
"authserver": {
"id": 7
},
"id": 1,
"timeout": 30
}
To retrieve RADIUS Settings
, send a GET
request to /api/v1/radiussettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID
.
Update RADIUS Settings
Update RADIUS Settings
curl -v -X PUT https://baruwa.example.com/api/v1/radiussettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "secret=P4ssW0rd#" \
-d "timeout=60"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
secret => "P4ssW0rd#",
timeout => 30
};
my $serverid = 12;
my $domainid = 1;
my $settingsid = 20;
my $res = $api->update_radiussettings($domainid, $serverid, $settingsid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.RadiusSettings
err error
secret string
did, sid, rid, timeout int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.RadiusSettings{
ID: rid,
Secret: secret,
Timeout: timeout,
}
if err = c.UpdateRadiusSettings(did, sid, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The radius settings: %d have been updated\n", s.ID)
}
Sample output for Update RADIUS Settings
{
"authserver": {
"id": 7
},
"id": 1,
"timeout": 60
}
To update RADIUS Settings
, send a PUT
request to /api/v1/radiussettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID
.
Delete RADIUS Settings
Delete RADIUS Settings
curl -v -X DELETE https://baruwa.example.com/api/v1/radiussettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "secret=P4ssW0rd#" \
-d "timeout=60"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
secret => "P4ssW0rd#",
timeout => 30
};
my $serverid = 12;
my $domainid = 1;
my $settingsid = 20;
my $res = $api->delete_radiussettings($domainid, $serverid, $settingsid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.RadiusSettings
err error
did, sid, rid int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetRadiusSettings(did, sid, rid); err != nil {
log.Fatal(err)
}
if err = c.DeleteRadiusSettings(did, sid, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The radius settings: %d have been deleted\n", s.ID)
}
To delete RADIUS Settings
, send a DELETE
request to /api/v1/radiussettings/$DOMAIN_ID/$SERVER_ID/$SETTINGS_ID
.
The RADIUS Settings will be deleted and the response status will be a 204
. This indicates a successful
request with no body returned
Organizations
Organizations enable easy management of large number of domains, Administrators are assigned to Organizations and can manage all the domains with in the organization.
You can create smaller organizations out of bigger organizations and add specific domains from a bigger organization to allow delegation of domain management.
The standard organization attributes are:
Attribute | Type | Description |
---|---|---|
name | String | The name of the organization, organizations are used to group domains and assign administrators to manage them |
domains | Number | The domains to add to this organization |
admins | Number | The selected admins will manage all the domains under this organization |
Listing all Organizations
List all Organizations
curl -v https://baruwa.example.com/api/v1/organizations \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $res = $api->get_organizations();
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
o *api.OrganizationList
opts *api.ListOptions
b []byte
err error
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if o, err = c.GetOrganizations(opts); err != nil {
log.Fatal(err)
}
if len(o.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(o); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if o.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: o.Links.Pages.Next,
}
}
}
Sample response list all organizations
{
"items": [{
"domains": [{
"name": "example.com",
"id": 2
}, {
"name": "example.net",
"id": 4
}],
"name": "TDS",
"id": 1
}, {
"domains": [{
"name": "example.systems",
"id": 9
}],
"name": "New Technology",
"id": 2
}, {
"domains": [],
"name": "My Org",
"id": 3
}],
"meta": {
"total": 3
}
}
To retrieve a list of all of the organizations on the server, send a GET
request to
/api/v1/organizations
.
The response will be a JSON
object with a key called items. The value of this will be an array of
Organization objects, each of which contain the standard organization attributes as described above.
Create an Organization
Create an Organization
curl -v -X POST https://baruwa.example.com/api/v1/organizations \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "name=My Org" \
-d "domains=2" \
-d "domains=4" \
-d "admins=3"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
name => "My Org",
domains => [2, 4, 3],
admins => [3]
};
my $res = $api->create_organization($data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
f *api.OrganizationForm
o *api.Organization
b []byte
err error
name string
domains, admins []int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.OrganizationForm{
Name: name,
Domains: domains,
Admins: admins,
}
if o, err = c.CreateOrganization(f); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(o); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample response create an organization
{
"domains": [{
"name": "example.com",
"id": 2
}, {
"name": "example.net",
"id": 4
}],
"name": "My Org",
"id": 4
}
To create a new Organization, send a POST
request to /api/v1/organizations
.
Set the standard attributes described above.
Retrieve an existing Organization
Retrieve an existing Organization
curl -v https://baruwa.example.com/api/v1/organizations/$ORG_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $orgid = 23;
my $res = $api->get_organization($orgid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
o *api.Organization
b []byte
id int
err error
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if o, err = c.GetOrganization(id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(o); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample response retrieve an existing Organization
{
"domains": [{
"name": "example.com",
"id": 2
}, {
"name": "example.net",
"id": 4
}],
"name": "My Org",
"id": 3
}
To get details about an existing Organization, send a GET
request to /api/v1/organizations/$ORG_ID
.
The response will be a JSON
object that contains the standard attributes defined for an organization
as described above.
Update an Organization
Update an Organization
curl -v -X PUT https://baruwa.example.com/api/v1/organizations/$ORG_ID -H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "name=My Org [Updated]" \
-d "domains=2" \
-d "domains=4" \
-d "admins=6"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $orgid = 23;
my $data = {
name => "My Org",
domains => [2, 4, 3],
admins => [3]
};
my $res = $api->update_organization($orgid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
f *api.OrganizationForm
o *api.Organization
b []byte
err error
name string
domains, admins []int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
f = &api.OrganizationForm{
Name: name,
Domains: domains,
Admins: admins,
}
if err = c.UpdateOrganization(f, o); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(o); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample response update an Organization
{
"domains": [{
"name": "example.com",
"id": 2
}, {
"name": "example.net",
"id": 4
}],
"name": "My Org [Updated]",
"id": 3
}
To update an Organization, send a PUT
request to /api/v1/organizations/$ORG_ID
.
Delete an Organization
Delete an Organization
curl -v -X DELETE https://baruwa.example.com/api/v1/organizations/$ORG_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $orgid = 23;
my $res = $api->delete_organization($orgid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if err = c.DeleteOrganization(id); err != nil {
log.Fatal(err)
}
fmt.Printf("The organization: %d has been deleted\n", id)
}
To delete an Organization, send a DELETE
request to /api/v1/organizations/$ORG_ID
.
The Organization will be deleted and the response status will be a 204
. This
indicates a successful request with no body returned
Relays
Relaying of outbound mail is authenticated on a per organization basis, to enable
an organization to send outbound mail through Baruwa
you need to add relay settings.
Two kinds of outbound relaying are supported.
- IP address
- SMTP AUTH
Create Relay settings
Create Relay settings
curl -v -X POST https://baruwa.example.com/api/v1/relays/$ORG_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.20" \
-d "enabled=y" \
-d "require_tls=n" \
-d "username=outboundsmtp" \
-d "password1=Str0ngP4ss##" \
-d "password2=Str0ngP4ss##" \
-d "description=Backup-outbound-smtp" \
-d "low_score=10.0" \
-d "high_score=15.0" \
-d "spam_actions=2" \
-d "highspam_actions=3"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $orgid = 23;
my $data = {
address => "192.168.1.20",
username => "outboundsmtp",
enabled => 1,
require_tls => 1,
password1 => "Str0ngP4ss##",
password2 => "Str0ngP4ss##",
description => "Backup-outbound-smtp",
low_score => 10.0,
high_score => 15.0,
spam_actions => 2,
highspam_actions => 3,
block_macros => 1,
ratelimit => 250,
};
my $res = $api->create_relay($orgid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
r *api.RelaySetting
err error
b []byte
lowScore, highScore api.LocalFloat64
id, spamActions, highSpamActions, rateLimit int
enabled, requireTLS, blockMacros bool
address, username, password1, password2, description string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
r = &api.RelaySetting{
Address: address,
Username: username,
Password1: password1,
Password2: password2,
Description: description,
Enabled: enabled,
RequireTLS: requireTLS,
BlockMacros: blockMacros,
SpamActions: spamActions,
HighSpamActions: highSpamActions,
RateLimit: rateLimit,
LowScore: lowScore,
HighScore: highScore,
}
if err = c.CreateRelaySetting(id, r); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(r); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output Create Relay settings
{
"username": "outboundsmtp",
"description": "Backup-outbound-smtp",
"enabled": true,
"require_tls": false,
"spam_actions": 2,
"low_score": 10.0,
"high_score": 15.0,
"address": "192.168.1.20",
"id": 3,
"highspam_actions": 3
}
To create Relay settings
, send a POST
request to /api/v1/relays/$ORG_ID
.
Retrieve Relay settings
Retrieve Relay settings
curl -v -X GET https://baruwa.example.com/api/v1/relays/$RELAY_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $relayid = 5;
my $res = $api->get_relay($relayid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
r *api.RelaySetting
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if r, err = c.GetRelaySetting(id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(r); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Retrieve Relay settings
{
"username": "outboundsmtp",
"description": "Backup-outbound-smtp",
"enabled": true,
"require_tls": false,
"spam_actions": 2,
"low_score": 10.0,
"high_score": 15.0,
"address": "192.168.1.20",
"id": 3,
"highspam_actions": 3
}
To retrieve Relay settings
, send a GET
request to /api/v1/relays/$RELAY_ID
.
Update Relay settings
Update Relay settings
curl -v -X PUT https://baruwa.example.com/api/v1/relays/$RELAY_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.20" \
-d "enabled=y" \
-d "require_tls=n" \
-d "username=outboundsmtp" \
-d "description=Backup-outbound-smtp" \
-d "low_score=12.0" \
-d "high_score=20.0" \
-d "spam_actions=2" \
-d "highspam_actions=3"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.20",
username => "outboundsmtp",
enabled => 1,
require_tls => 1,
password1 => "Str0ngP4ss##",
password2 => "Str0ngP4ss##",
description => "Backup-outbound-smtp",
low_score => 10.0,
high_score => 15.0,
spam_actions => 2,
highspam_actions => 3,
block_macros => 1,
ratelimit => 250,
};
my $relayid = 5;
my $res = $api->update_relay($relayid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
r *api.RelaySetting
err error
lowScore, highScore api.LocalFloat64
id, spamActions, highSpamActions, rateLimit int
enabled, requireTLS, blockMacros bool
address, username, password1, password2, description string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
r = &api.RelaySetting{
ID: id,
Address: address,
Username: username,
Password1: password1,
Password2: password2,
Description: description,
Enabled: enabled,
RequireTLS: requireTLS,
BlockMacros: blockMacros,
SpamActions: spamActions,
HighSpamActions: highSpamActions,
RateLimit: rateLimit,
LowScore: lowScore,
HighScore: highScore,
}
if err = c.UpdateRelaySetting(r); err != nil {
log.Fatal(err)
}
fmt.Printf("The relay setting: %s[%s] has been updated\n", r.Address, r.Username)
}
Sample output for Update Relay settings
{
"username": "outboundsmtp",
"description": "Backup-outbound-smtp",
"enabled": true,
"require_tls": false,
"spam_actions": 2,
"low_score": 12.0,
"high_score": 20.0,
"address": "192.168.1.20",
"id": 3,
"highspam_actions": 3
}
To update Relay settings
, send a PUT
request to /api/v1/relays/$RELAY_ID
.
Delete Relay settings
Delete Relay settings
curl -v -X DELETE https://baruwa.example.com/api/v1/relays/$RELAY_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.20"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.20",
username => "outboundsmtp",
enabled => 1,
require_tls => 1,
password1 => "Str0ngP4ss##",
password2 => "Str0ngP4ss##",
description => "Backup-outbound-smtp",
low_score => 10.0,
high_score => 15.0,
spam_actions => 2,
highspam_actions => 3,
block_macros => 1,
ratelimit => 250,
};
my $relayid = 5;
my $res = $api->delete_relay($relayid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
r *api.RelaySetting
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if r, err = c.GetRelaySetting(id); err != nil {
log.Fatal(err)
}
if err = c.DeleteRelaySetting(r); err != nil {
log.Fatal(err)
}
fmt.Printf("The relay setting: %s[%s] has been deleted\n", r.Address, r.Username)
}
To delete Relay settings
, send a DELETE
request to /api/v1/relays/$RELAY_ID
.
The Relay settings
will be deleted and the response status will be a 204
. This
indicates a successful request with no body returned
Fallback servers
Fallback servers
are used when no delivery server has been configured for a domain. They can
be setup in cases where an organization has several domains whose mail is hosted on the same
server so it would be repetitive to setup the same delivery server for each domain.
An Organization can have multiple Fallback servers
.
Listing Fallback servers
Listing all Fallback servers for an Organization
curl -v -X GET https://baruwa.example.com/api/v1/failbackservers/$ORG_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
orgid = 9
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_failbackservers(orgid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $orgid = 1;
my $res = $api->get_fallbackservers($orgid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
o *api.FallBackServerList
opts *api.ListOptions
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if o, err = c.GetFallBackServers(id, opts); err != nil {
log.Fatal(err)
}
if len(o.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(o); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if o.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: o.Links.Pages.Next,
}
}
}
Sample output for Listing all Fallback servers for an Organization
{
"items": [{
"organization": {
"name": "Baruwa",
"id": 2
},
"protocol": 1,
"enabled": true,
"verification_only": false,
"id": 2,
"address": "192.168.1.150",
"port": 25
}],
"meta": {
"total": 1
}
}
To retrieve a list of Fallback servers
configured for an Organization
, send a GET
request to
/api/v1/failbackservers/list/$ORG_ID
.
Create a Fallback server
Create a new Fallback server
curl -v -X POST https://baruwa.example.com/api/v1/failbackservers/$ORG_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=1" \
-d "port=25" \
-d "require_tls=n" \
-d "enabled=y"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
orgid = 9
data = {
"address": "192.168.1.152",
"protocol": "1",
"port": "25",
"require_tls": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.create_fallbackserver(orgid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
protocol => 1,
port => 25,
enabled => 1,
require_tls => 1,
verification_only => 1,
};
my $orgid = 1;
my $res = $api->create_fallbackserver($orgid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.FallBackServer
b []byte
err error
oid, protocol, port int
address string
enabled, requireTLS, verificationOnly bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.FallBackServer{
Address: address,
Enabled: enabled,
RequireTLS: requireTLS,
VerificationOnly: verificationOnly,
Protocol: protocol,
Port: port,
}
if err = c.CreateFallBackServer(oid, s); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Create a new Fallback server
{
"organization": {
"name": "Baruwa",
"id": 2
},
"protocol": 1,
"enabled": true,
"require_tls": false,
"verification_only": false,
"id": 9,
"address": "192.168.1.151",
"port": 25
}
To create a new Fallback server
, send a POST
request to /api/v1/failbackservers/$ORG_ID
.
Retrieve a Fallback server
Retrieve an existing Fallback server
curl -v -X GET https://baruwa.example.com/api/v1/failbackservers/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
orgid = 9
serverid = 4
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_fallbackserver(serverid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $res = $api->get_fallbackserver($serverid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.FallBackServer
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetFallBackServer(id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Retrieve an existing Fallback server
{
"organization": {
"name": "Baruwa",
"id": 2
},
"protocol": 1,
"enabled": true,
"require_tls": false,
"verification_only": false,
"id": 9,
"address": "192.168.1.151",
"port": 25
}
To retrieve an existing Fallback server
, send a GET
request to /api/v1/failbackservers/$SERVER_ID
.
Update a Fallback server
Update a Fallback server
curl -v -X PUT https://baruwa.example.com/api/v1/failbackservers/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=1" \
-d "port=25"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
orgid = 9
serverid = 4
data = {
"address": "192.168.1.153",
"protocol": "1",
"port": "25",
"require_tls": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.update_fallbackserver(serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
protocol => 1,
port => 25,
enabled => 1,
require_tls => 1,
verification_only => 1,
};
my $serverid = 12;
my $res = $api->update_fallbackserver($serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.FallBackServer
err error
id, protocol, port int
address string
enabled, requireTLS, verificationOnly bool
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.FallBackServer{
Address: address,
Enabled: enabled,
RequireTLS: requireTLS,
VerificationOnly: verificationOnly,
Protocol: protocol,
Port: port,
ID: id,
}
if err = c.UpdateFallBackServer(s); err != nil {
log.Fatal(err)
}
fmt.Printf("The fallback server: %s has been updated\n", s.Address)
}
Sample output from Update a Fallback server
{
"organization": {
"name": "Baruwa",
"id": 2
},
"protocol": 1,
"enabled": false,
"require_tls": false,
"id": 9,
"address": "192.168.1.151",
"port": 25
}
To update a Fallback server
, send a PUT
request to /api/v1/failbackservers/$SERVER_ID
.
Delete a Fallback server
Delete a Fallback server
curl -v -X DELETE https://baruwa.example.com/api/v1/failbackservers/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
serverid = 4
data = {
"address": "192.168.1.153",
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.delete_fallbackserver(serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
protocol => 1,
port => 25,
enabled => 1,
require_tls => 1,
verification_only => 1,
};
my $serverid = 12;
my $res = $api->delete_fallbackserver($serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.FallBackServer
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetFallBackServer(id); err != nil {
log.Fatal(err)
}
if err = c.DeleteFallBackServer(s); err != nil {
log.Fatal(err)
}
fmt.Printf("The fallback server: %s has been deleted\n", s.Address)
}
To delete a Fallback server
, send a DELETE
request to /api/v1/failbackservers/$SERVER_ID
.
The Fallback server will be deleted and the response status will be a 204
. This indicates a successful
request with no body returned
Organization Smarthosts
Organization SmartHosts
are used to route outbound email via a Organization SmartHost
as
opposed to routing it via the DNS based lookup of the MX record.
Multiple Organization SmartHosts
per Organization are supported.
Listing Organization Smarthosts
Listing all Organization Smarthosts for a Organization
curl -v -X GET https://baruwa.example.com/api/v1/organizations/smarthosts/$ORG_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
orgid = 9
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_org_smarthosts(orgid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $orgid = 1;
my $res = $api->get_org_smarthosts($orgid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
o *api.OrgSmartHostList
opts *api.ListOptions
b []byte
err error
id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
for {
if o, err = c.GetOrgSmartHosts(id, opts); err != nil {
log.Fatal(err)
}
if len(o.Items) == 0 {
fmt.Println()
break
}
if b, err = prettyjson.Marshal(o); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
if o.Links.Pages.Next == "" {
break
}
opts = &api.ListOptions{
Page: o.Links.Pages.Next,
}
}
}
Sample output for Listing all Smarthosts for an Organization
{
"items": [{
"enabled": true,
"require_tls": false,
"id": 2,
"address": "192.168.1.150",
"username": "andrew",
"description": "outbound-archiver",
"port": 25
}],
"meta": {
"total": 1
}
}
To retrieve a list of Organization Smarthosts
configured for a Organization
,
send a GET
request to /api/v1/organizations/smarthosts/$ORG_ID
.
Create an Organization Smarthost
Create a new Organization Smarthost
curl -v -X POST https://baruwa.example.com/api/v1/organizations/smarthosts/$ORG_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "username=andrew" \
-d "password=p4ssw0rd" \
-d "description=outbound-archiver" \
-d "port=25" \
-d "require_tls=y" \
-d "enabled=y"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
orgid = 9
data = {
"address": "192.168.1.152",
"username": "andrew",
"password": "p4ssw0rd",
"description": "outbound-archiver",
"port": "25",
"require_tls": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.create_org_smarthost(orgid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
username => "andrew",
password => "p4ssw0rd",
port => 25,
require_tls => 1,
enabled => 1,
description => "outbound-archiver",
};
my $orgid = 1;
my $res = $api->create_org_smarthost($orgid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.OrgSmartHost
b []byte
err error
oid, port int
enabled, requireTLS bool
address, username, password, description string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.OrgSmartHost{
Address: address,
Username: username,
Password: password,
Description: description,
Enabled: enabled,
RequireTLS: requireTLS,
Port: port,
}
if err = c.CreateOrgSmartHost(oid, s); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Create a new Organization Smarthost
{
"enabled": true,
"require_tls": false,
"id": 2,
"address": "192.168.1.150",
"username": "andrew",
"description": "outbound-archiver",
"port": 25
}
To create a new Organization Smarthost
, send a POST
request
to /api/v1/organizations/smarthosts/$ORG_ID
.
Retrieve a Organization Smarthost
Retrieve an existing Organization Smarthost
curl -v -X GET https://baruwa.example.com/api/v1/organizations/smarthosts/$ORG_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
orgid = 9
serverid = 4
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.get_org_smarthost(orgid, serverid)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $serverid = 12;
my $orgid = 1;
my $res = $api->get_org_smarthost($orgid, $serverid);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.OrgSmartHost
b []byte
err error
oid, id int
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetOrgSmartHost(oid, id); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output for Retrieve an existing Organization Smarthost
{
"enabled": true,
"require_tls": false,
"id": 2,
"address": "192.168.1.150",
"username": "andrew",
"description": "outbound-archiver",
"port": 25
}
To retrieve an existing Organization Smarthost
, send a GET
request
to /api/v1/organizations/smarthosts/$ORG_ID/$SERVER_ID
.
Update a Organization Smarthost
Update a Organization Smarthost
curl -v -X PUT https://baruwa.example.com/api/v1/organizations/smarthosts/$ORG_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151" \
-d "protocol=1" \
-d "port=25"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
orgid = 9
serverid = 4
data = {
"address": "192.168.1.152",
"username": "andrew",
"description": "outbound-archiver",
"port": "25",
"require_tls": "n",
"enabled": "y"
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.update_org_smarthost(orgid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
username => "andrew",
password => "p4ssw0rd",
port => 25,
require_tls => 1,
enabled => 1,
description => "outbound-archiver",
};
my $serverid = 12;
my $orgid = 1;
my $res = $api->update_org_smarthost($orgid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.OrgSmartHost
err error
oid, port int
enabled, requireTLS bool
address, username, password, description string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.OrgSmartHost{
Address: address,
Username: username,
Password: password,
Description: description,
Enabled: enabled,
RequireTLS: requireTLS,
Port: port,
}
if err = c.UpdateOrgSmartHost(oid, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The organization smarthost: %s has been updated\n", s.Address)
}
Sample output from Update a Organization Smarthost
{
"enabled": true,
"require_tls": false,
"id": 2,
"address": "192.168.1.150",
"username": "andrew",
"description": "outbound-archiver",
"port": 25
}
To update a Organization Smarthost
, send a PUT
request to
/api/v1/organizations/smarthosts/$ORG_ID/$SERVER_ID
.
Delete a Organization Smarthost
Delete a Organization Smarthost
curl -v -X DELETE https://baruwa.example.com/api/v1/organizations/smarthosts/$ORG_ID/$SERVER_ID \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "address=192.168.1.151"
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
orgid = 9
serverid = 4
data = {
"address": "192.168.1.153",
}
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
api.delete_org_smarthost(orgid, serverid, data)
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $data = {
address => "192.168.1.151",
username => "andrew",
password => "p4ssw0rd",
port => 25,
require_tls => 1,
enabled => 1,
description => "outbound-archiver",
};
my $serverid = 12;
my $orgid = 1;
my $res = $api->delete_org_smarthost($orgid, $serverid, $data);
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
)
func main() {
var (
c *api.Client
s *api.OrgSmartHost
err error
oid, port int
enabled, requireTLS bool
address, username, password, description string
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
s = &api.OrgSmartHost{
Address: address,
Username: username,
Password: password,
Description: description,
Enabled: enabled,
RequireTLS: requireTLS,
Port: port,
}
if err = c.DeleteOrgSmartHost(oid, s); err != nil {
log.Fatal(err)
}
fmt.Printf("The organization smarthost: %s has been deleted\n", s.Address)
}
To delete a Organization Smarthost
, send a DELETE
request
to /api/v1/organizations/smarthosts/$ORG_ID/$SERVER_ID
.
The Organization Smarthost will be deleted and the response status will be a 204
.
This indicates a successful request with no body returned
System Status
System status gives you a dash board view of your Baruwa
system or cluster.
The following information is provided:
- Global status
- Mail Queues
Retrieve System Status
Retrieve System Status
curl -v -X GET https://baruwa.example.com/api/v1/status \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
require 'baruwa'
api = BaruwaAPI.new('token', 'https://baruwa.example.com')
from BaruwaAPI import BaruwaAPIClient
api = BaruwaAPIClient('token', 'https://baruwa.example.com')
use Net::BaruwaAPI;
my $api = Net::BaruwaAPI->new(
api_token => 'token',
api_url => 'https://baruwa.example.com'
);
my $res = $api->get_status();
package main
import (
"fmt"
"log"
"os"
"github.com/baruwa-enterprise/baruwa-go/api"
prettyjson "github.com/hokaccha/go-prettyjson"
)
func main() {
var (
c *api.Client
s *api.SystemStatus
b []byte
err error
)
serverURL := os.Getenv("BARUWA_API_SERVER")
apiToken := os.Getenv("BARUWA_API_TOKEN")
if c, err = api.New(serverURL, apiToken, nil); err != nil {
log.Fatal(err)
}
if s, err = c.GetSystemStatus(); err != nil {
log.Fatal(err)
}
if b, err = prettyjson.Marshal(s); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", b)
}
Sample output from Retrieve System Status
{
"inbound": 0,
"outbound": 0,
"status": true,
"total": {
"clean": 29,
"highspam": 0,
"infected": 0,
"lowspam": 0,
"spam": 0,
"total": 29,
"virii": 0
}
}
To retrieve System Status
, send a GET
request to /api/v1/status
.