mailcow / mailcow-dockerized

mailcow: dockerized - 🐮 + 🐋 = 💕
https://mailcow.email
GNU General Public License v3.0
8.95k stars 1.17k forks source link

CRUD api #1374

Closed mhf-ir closed 6 years ago

mhf-ir commented 6 years ago

is there any api for CRUD domains/users/aliases ?

Braintelligence commented 6 years ago

You mean other than the aliases page for admins? EDIT: Or do you mean a documented API?

Does this line help you to find the/create an appropriate API? https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/mailbox.php#L152 Here's the function: https://github.com/mailcow/mailcow-dockerized/blob/2ee983c1a14ed89014cabbb02933cedc802f5f1a/data/web/inc/functions.mailbox.inc.php#L1676

Other than that, there's no official API yet: https://github.com/mailcow/mailcow-dockerized/issues/1316#issuecomment-386197945

mhf-ir commented 6 years ago

An http api for create user, domain, domain alias, user alias, forwarded and etc.. seems be the application. if php application based on micro frameworks like slim framework will be awesome.

Braintelligence commented 6 years ago

I think I've read something about an endeavor to port mailcow UI to a framework. Lemme search real quick.

Braintelligence commented 6 years ago

There it is: https://github.com/mailcow/mailcow-dockerized/issues/708

mritzmann commented 6 years ago
# create domain:
curl -X POST https://mail.example.com/api/v1/add/domain -d attr='{"domain":"example.com","description":"demo+domain","aliases":"20","mailboxes":"20","maxquota":"3072","quota":"10240","active":"1"}'  -H "X-API-Key: <API-KEY>"

# create user:
curl -X POST https://mail.example.com/api/v1/add/mailbox -d attr='{"local_part":"demo","domain":"example.com","name":"John Doe","quota":"100","password":"moohoo","password2":"moohoo","active":"1"}'  -H "X-API-Key: <API-KEY>"

But it is not documented and maybe work in Progress. You can set the API key in mailcow.conf.

https://github.com/mailcow/mailcow-dockerized/blob/3c2249e87cb7eb98872d7050c1e29de6530968b2/generate_config.sh#L144-L145

The listing of domains, users, etc. is certainly also possible. The easiest way is to look in the developer console of your browser and see which POST requests are sent. From this you can in most cases derive the API 1:1.

shivangpatel commented 6 years ago

@mritzmann : I can see, my API key entry in api table. But when i tried to post(using postman) for domain and mailbox, it will return nothing(200 status code) and no changes in database !

So, can you help me where i made mistake !?

andryyy commented 6 years ago

allow_from is probably not correct.

shivangpatel commented 6 years ago

@andryyy Sorry but I can't insert data using API ! Same issue !

in mailcow.conf

....
....
# Create or override API key for web uI
# You _must_ define API_ALLOW_FROM, which is a comma separated list of IPs
API_KEY=2f123d029cb0
API_ALLOW_FROM=127.0.0.1,192.168.1.111,192.168.1.188,xxx.xxx.120.204

192.168.1.111 - my system 192.168.1.188 - server where mailcow docker system installed 127.0.0.1 - localhost for server xxx.xxx.120.204 - our public ip

curl -X POST https://mail.example.com/api/v1/add/domain -d attr='{"domain":"123example.com","description":"demo+domain","aliases":"10","mailboxes":"10","maxquota":"100","quota":"2048","active":"1"}' -H "X-API-Key:2f123d029cb0"

Any suggestion for how to debug and find mistakes....

mritzmann commented 6 years ago

API_KEY=2f123d029cb0

Maybe your API key is too short? But I don't know if that's a problem or not. The built-in API generator builds at least much longer keys:

https://github.com/mailcow/mailcow-dockerized/blob/ed9fae075b973cc0eb4374e0e100f823d1a514ed/data/web/inc/functions.inc.php#L941-L947

Any suggestion for how to debug and find mistakes....

Did you check in the log from which IP address your request comes from? Maybe the source address is an IPv6 address you forgot?

shivangpatel commented 6 years ago

@mritzmann :

1) Actually, I was forgot to write full API key (full key is : dc73c84f-7674-42c6-8461-2f123d029cb0). So, there is no issue with short or full key.

2) IP address is OK. same as my public IP. and I was checked logs in Debug tab. System generated and my post requests are same.

3) Lastly you wrote about IPv6, I didn't understand what you want to say....!! You mean, I need to disable IPv6??! or in API_ALLOW_FORM must be in IPv6 form ?

My config settings are default. I didn't change anything to relate it....

# Skip running ACME (acme-mailcow, Let's Encrypt certs) - y/n
SKIP_LETS_ENCRYPT=n

# Skip IPv4 check in ACME container - y/n
SKIP_IP_CHECK=n

# Skip ClamAV (clamd-mailcow) anti-virus (Rspamd will auto-detect a missing ClamAV container) - y/n
SKIP_CLAMD=n

# Enable watchdog (watchdog-mailcow) to restart unhealthy containers (experimental)
USE_WATCHDOG=n
# Send notifications by mail (no DKIM signature, sent from watchdog@MAILCOW_HOSTNAME)
#WATCHDOG_NOTIFY_EMAIL=

# Max log lines per service to keep in Redis logs
LOG_LINES=9999

# Internal IPv4 /24 subnet, format n.n.n. (expands to n.n.n.0/24)
IPV4_NETWORK=172.22.1

# Internal IPv6 subnet in fc00::/7
IPV6_NETWORK=fd4d:6169:6c63:6f77::/64

# Use this IPv4 for outgoing connections (SNAT)
#SNAT_TO_SOURCE=

# Use this IPv6 for outgoing connections (SNAT)
#SNAT6_TO_SOURCE=

# Disable IPv6
# mailcow-network will still be created as IPv6 enabled, all containers will be created
# without IPv6 support.
# Use 1 for disabled, 0 for enabled
SYSCTL_IPV6_DISABLED=0
andryyy commented 6 years ago

Can you please check your nginx log for the IP that reaches mailcow when you call the API?

shivangpatel commented 6 years ago

@andryyy : nginx logs docker-compose logs --tail="all" | grep 'nginx-mailcow_1'

Add new domain using curl - API :


nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:12:56:47 +0530] "POST /api/v1/add/domain HTTP/1.1" 200 5 "-" "curl/7.58.0"
nginx-mailcow_1      | fd4d:6169:6c63:6f77::e - - [30/Jul/2018:12:56:52 +0530] "HEAD /forwardinghosts.php HTTP/1.1" 200 0 "-" "-"
nginx-mailcow_1      | fd4d:6169:6c63:6f77::e - - [30/Jul/2018:12:56:52 +0530] "GET /forwardinghosts.php HTTP/1.1" 200 27 "-" "-"
nginx-mailcow_1      | fd4d:6169:6c63:6f77::e - - [30/Jul/2018:12:57:21 +0530] "HEAD /settings.php HTTP/1.1" 200 0 "-" "-"
nginx-mailcow_1      | 172.22.1.12 - - [30/Jul/2018:12:57:21 +0530] "GET /settings.php HTTP/1.1" 200 278 "-" "-"
nginx-mailcow_1      | fd4d:6169:6c63:6f77::e - - [30/Jul/2018:12:57:26 +0530] "HEAD /forwardinghosts.php HTTP/1.1" 200 0 "-" "-"
nginx-mailcow_1      | fd4d:6169:6c63:6f77::e - - [30/Jul/2018:12:57:26 +0530] "GET /forwardinghosts.php HTTP/1.1" 200 27 "-" "-"

Add new domain using system :


nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:09 +0530] "POST /api/v1/add/domain HTTP/2.0" 200 41 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:09 +0530] "GET /css/bootstrap.min.css HTTP/2.0" 200 98304 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:09 +0530] "GET /css/numberedtextarea.min.css HTTP/2.0" 200 432 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:09 +0530] "GET /css/jquery.jqplot.min.css HTTP/2.0" 200 3129 "https://mail.example/com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /mailbox.php HTTP/2.0" 200 82448 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/domain/example.com HTTP/2.0" 200 594 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | 172.22.1.12 - - [30/Jul/2018:13:00:10 +0530] "HEAD /settings.php HTTP/1.1" 200 0 "-" "-"
nginx-mailcow_1      | 172.22.1.12 - - [30/Jul/2018:13:00:10 +0530] "GET /settings.php HTTP/1.1" 200 278 "-" "-"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/domain/all HTTP/2.0" 200 8237 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/domain/all HTTP/2.0" 200 8237 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/mailbox/all HTTP/2.0" 200 2248 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/resource/all HTTP/2.0" 200 2 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/domain/all HTTP/2.0" 200 8237 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/alias/all HTTP/2.0" 200 2 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/domain/all HTTP/2.0" 200 8237 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/alias-domain/all HTTP/2.0" 200 2 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/recipient_map/all HTTP/2.0" 200 2 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/bcc/all HTTP/2.0" 200 2 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/filters/all HTTP/2.0" 200 2 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:13:00:10 +0530] "GET /api/v1/get/syncjobs/all/no_log HTTP/2.0" 200 2 "https://mail.example.com/mailbox.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
andryyy commented 6 years ago

Can you try to only add the shown .204 IP to allow_from? Please run up -d afterwards.

shivangpatel commented 6 years ago

@andryyy : Same result.


nginx-mailcow_1      | xxx.xxx.xxx.204 - - [30/Jul/2018:15:12:57 +0530] "POST /api/v1/add/domain HTTP/2.0" 200 0 "-" "curl/7.58.0"
nginx-mailcow_1      | 172.22.1.12 - - [30/Jul/2018:15:13:09 +0530] "GET / HTTP/1.1" 200 27752 "-" "curl/7.60.0"
nginx-mailcow_1      | 172.22.1.11 - - [30/Jul/2018:15:13:18 +0530] "HEAD /forwardinghosts.php HTTP/1.1" 200 0 "-" "-"
nginx-mailcow_1      | 172.22.1.11 - - [30/Jul/2018:15:13:18 +0530] "GET /forwardinghosts.php HTTP/1.1" 200 27 "-" "-"

I was also tried with localhost[ API_ALLOW_FROM=127.0.0.1 ]...

nginx-mailcow_1 | 172.22.1.1 - - [30/Jul/2018:15:19:01 +0530] "POST /api/v1/add/domain HTTP/1.1" 200 5 "-" "curl/7.47.0"

In which file this api listener function defined ? So, I can go there and put some debug point....

andryyy commented 6 years ago

You are not coming from localhost, it will not work. Have you tried from another server?

shivangpatel commented 6 years ago

@andryyy : Same result...

| xxx.xxx.xxx.74 - - [30/Jul/2018:15:42:35 +0530] "POST /api/v1/add/domain HTTP/1.1" 200 5 "-" "curl/7.47.0"

dshaklein commented 6 years ago

I have the same problem. @shivangpatel Did you find any solutions?

shivangpatel commented 6 years ago

@dshaklein : No ! But I will wait ! @andryyy will replay soon.

Alternate method is... manual entry in mariadb. For that check out this link... https://stackoverflow.com/questions/44780571/how-to-connect-with-mysql-db-running-as-container-in-docker?answertab=active#tab-top

mritzmann commented 6 years ago

Manual Entry:

echo "INSERT INTO \`api\` VALUES ('admin','XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX','172.22.1.1','2018-06-03 12:07:27',NULL,1);" | /usr/bin/docker exec -i mailcowdockerized_mysql-mailcow_1 /usr/bin/mysql -uroot -pMYDBPW mailcow
mritzmann commented 6 years ago

I have now installed Mailcow on a test VM to test it. And in my case it worked as expected.

That's what I did:

  1. ./setup.sh
  2. docker-compose pull && docker-compose up -d
  3. Mailcow WebUI opened to initialize the database
  4. vi mailcow.conf (fill in a API Key and a IP address)
  5. docker-compose down && docker-compose up -d
  6. curl -X POST http://IP-OF-MY-TEST-VM/api/v1/add/domain -d attr='{"domain":"example.com","description":"demo+domain","aliases":"20","mailboxes":"20","maxquota":"3072","quota":"10240","active":"1"}' -H "X-API-Key: MY-API-KEY"
  7. I opened http://IP-OF-MY-TEST-VM/debug.php (-> API) and found that I entered an incorrect IP address.
  8. vi mailcow.conf (have corrected the ip address)
  9. docker-compose down && docker-compose up -d
  10. curl -X POST http://IP-OF-MY-TEST-VM/api/v1/add/domain -d attr='{"domain":"example.com","description":"demo+domain","aliases":"20","mailboxes":"20","maxquota":"3072","quota":"10240","active":"1"}' -H "X-API-Key: MY-API-KEY" => and it works
mhf-ir commented 6 years ago

Any documentation about endpoints ?

mritzmann commented 6 years ago

Any documentation about endpoints ?

The API is not yet officially released. Therefore, there is no documentary yet. But feel free to make a pull request ;-) https://github.com/mailcow/mailcow-dockerized-docs

willfri commented 6 years ago

I also had problems until I found out that the key can only contain capital letters, numbers and dashes.

sessions.inc.php: ':api_key' => preg_replace('/[^A-Z0-9-]/', '', $_SERVER['HTTP_X_API_KEY'])

EnriqCG commented 6 years ago

the key can only contain capital letters, numbers and dashes.

This is the cause why my API calls are always returning nothing. I had lowercase letters in the key.

I don't know if this is the intended behaviour. Seems pretty rare to me to not allow lowercase characters.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

dshaklein commented 6 years ago

Hello! I have updated a mailcow to the latest version with the update.sh script. After that API requests started to fail. In nginx logs I have:

nginx-mailcow_1      | x.x.x.115 - - [16/Oct/2018:15:23:51 +0300] "POST /api/v1/add/mailbox HTTP/1.1" 200 5 "-" "python-requests/2.19.1" 

In mailcow.conf: I have API_KEY and API_ALLOW_FROM which includes x.x.x.115

Do you have any suggestions?

andryyy commented 6 years ago

Fixed.

MAGICCC commented 6 years ago

In https://github.com/mailcow/mailcow-dockerized/commit/d39eab53a3d8d3bc9b040521bc041f7b9fc55016 :)

mhf-ir commented 6 years ago

Why did you close issue need more spec and documentation ? I think it's most important feature needed to be added to awesome mailcow.

MAGICCC commented 6 years ago

Because the API is already included in mailcow

andryyy commented 6 years ago

Docs are still a wip and the API may still change a bit. :-(

mhf-ir commented 6 years ago

API is not release yet seem be more stuff. i already ask to write docs, i think main application must be REST ap and UI must be some ui apps like angular js or react or Vue something like that. I could help but your code is very complex for understand way to refactor.

Because the API is already included in mailcow

It's not released yet. i dont see any documentation about it. writing documentation is part of release new feature like this.

Docs are still a wip and the API may still change a bit. :-(

I hop so it's get first RC version for important feature. many developers need email stack with api and mailcow could be the main solution for us.

Thank you in advance.

ThomDietrich commented 5 years ago

A documented API would be neat indeed. In the meantime I can confirm that the unofficial solution still works. I needed to create dozens of mailboxes and was able to after some minutes of tinkering. Here's a short summary for others:

  1. Create random API key, e.g. here
  2. Add key and IP to mailcow.conf:
    API_KEY=394A19-612EA2-F0DAAE-4786E7-0AFC78
    API_ALLOW_FROM=172.22.1.1,127.0.0.1

    Remember that due to the dockerized nature of mailcow-dockerized the IP of your host system is not 127.0.0.1 but e.g. 172.22.1.1. The requesting IP is also logged see docker-compose logs).

  3. docker-compose down && docker-compose up -d
  4. Query API. If the below command doesn't return a resonse, check key and IPs
    curl http://127.0.0.1:80/api/v1/get/domain/all -H "X-API-Key: 394A19-612EA2-F0DAAE-4786E7-0AFC78"
  5. Create new user:
    curl -X POST \
        http://127.0.0.1:8080/api/v1/add/mailbox \
       -H "X-API-Key: 394A19-612EA2-F0DAAE-4786E7-0AFC78" \
       -d attr='{"local_part":"demo","domain":"example.tld","name":"John Doe","quota":"1024","password":"moohoo","password2":"moohoo","active":"1"}'
    [{"type":"success","log":["mailbox","add","mailbox",{"local_part":"demo","domain":"example.tld","name":"John Doe","quota":"1024","password":"*","password2":"*","active":"1"},null],"msg":["mailbox_added","demo@example.tld"]}]

Bonus: You might find a script to automate mass creation useful:

#!/bin/sh

while IFS=',' read -r user domain name pass
do
  if [ -z $user ]; then continue; fi
  echo "\nCreating mailbox: $user @ $domain ($name)"
  curl -X POST -H "X-API-Key: 394A19-612EA2-F0DAAE-4786E7-0AFC78" http://127.0.0.1:80/api/v1/add/mailbox -d attr="{\"local_part\":\"$user\",\"domain\":\"$domain\",\"name\":\"$name\",\"quota\":\"1024\",\"password\":\"$pass\",\"password2\":\"$pass\",\"active\":\"1\"}"
  echo "\n"
done <<< "
username,domain,full name,password
user1,example.tld,Full Name,password_123
user2,example.tld,Full Name,password_456
"

Enjoy!!

lucianlazar1983 commented 5 years ago

Hi all, I am trying to build a bridge betweek WHMCS and Mailcow but i am having some issues using POST instead of CURL:

POST https://MAILCOWHOST/api/v1/add/domain?domain=esempio.it&description=demo+domain&aliases=100&mailboxes=5&maxquota=5120&quota=5120&active=1&X-API-Key=CORRECT-API-KEY

I am always getting this response: { "type": "error", "msg": "Cannot find attributes in post data" }

Is there a mistake in the way i use parameters? Using CURl it works without issues. Thank you

rtulke commented 5 years ago

I also spend some hours to connect to the API. Here are some useful tips...

For the first time of the other things mentioned here I needed a API token entry into the database. Therefore I wrote a small script which does the DB connect automatically. Verify if your docker-container mysql-mailcow has the same name ... if not, please change my script.

vim /root/dev/mailcow-dockerized/dbconnect.sh
!/bin/bash

MPATH="/root/dev/mailcow-dockerized"
MCONF="mailcow.conf"

MYPATH=$(pwd)

## test path/file
if [ ! -f "${MPATH}/${MCONF}" ] ; then
    echo "file or directory not found, please verify the MPATH= and MCONF= variable";
    exit 1
fi

cd $MPATH
source $MCONF

DBPASS=$(grep "DBPASS=" ${MPATH}/${MCONF} |awk -F 'DBPASS=' {'print $2'})

docker-compose exec mysql-mailcow mysql -umailcow -p${DBPASS} mailcow

cd $MYPATH

Connect to the docker container (Maria DB)

/root/dev/mailcow-dockerized/dbconnect.sh

Now I have deposited the API token because I had nothing.

MariaDB [mailcow]> insert into api (allow_from,api_key,active) values ('172.22.1.1,127.0.0.1','D95209-D82428-C289C0-8B0B17-E11487',1);
MariaDB [mailcow]> select * from api;
+------------------------------------+------------------------------------------------------------+---------------------+----------+--------+
| api_key                            | allow_from                                                 | created             | modified | active |
+------------------------------------+------------------------------------------------------------+---------------------+----------+--------+
| D95209-D82428-C289C0-8B0B17-E11487 | 172.22.1.1,127.0.0.1                                       | 2019-04-05 13:30:56 | NULL     |      1 |
+------------------------------------+------------------------------------------------------------+---------------------+----------+--------+
1 row in set (0.00 sec)

Check my mailcow.conf

cat mailcow.conf |egrep API |egrep -v ^#

Output

API_KEY=D95209-D82428-C289C0-8B0B17-E11487
API_ALLOW_FROM=172.22.1.1,127.0.0.1

API Test connect with curl

curl http://127.0.0.1:8880/api/v1/get/domain/all -H "X-API-Key: D95209-D82428-C289C0-8B0B17-E11487"
akaillidan commented 5 years ago

Simple CRUD API for mailbox user

create user:

curl -X POST http://mail.example.com/api/v1/add/mailbox -d attr='{"local_part":"test","domain":"example.com","name":"John Doe","quota":"100","password":"moohoo","password2":"moohoo","active":"1"}' -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea" 

get user:

curl -X POST http://mail.example.com/api/v1/get/mailbox/test@example.com -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea"

update user:

curl -X POST http://mail.example.com/api/v1/edit/mailbox -d items='["test@example.com"]' -d attr='{"sender_acl":"default","active":"0","force_pw_update":["0","1"]ta":"200","password":"Qwerty123","password2":"Qwerty123"}' -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea"

delete user:

curl -X POST http://mail.example.com/api/v1/delete/mailbox -d items='["test@example.com"]' -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea"

get all users:

curl -X POST https://mail.example.com/api/v1/get/mailbox/all -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea"
mhf-ir commented 5 years ago

@akaillidan
I think we need to be part of documentation, also add domain parts and aliases and other stuff.

akaillidan commented 5 years ago

Simple CRUD API for alias

get all alias:

curl -X POST https://mail.example.com/api/v1/get/alias/all -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea"

create alias:

curl -X POST https://mail.example.com/api/v1/add/alias -d attr='{"active":"1","address":"test2@example.com","goto":"test@example.com,test3@example.com"}' -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea"

get alias:

curl -X POST https://mail.example.com/api/v1/get/alias -d items='["<ID>"]' -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea"

update alias:

curl -X POST https://mail.example.com/api/v1/edit/alias -d items='["<ID>"]' -d attr='"active":"0","address":"test2@example.com","goto":"test@example.com,test3@example.com"}' -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea"

delete alias:

curl -X POST https://mail.example.com/api/v1/delete/alias -d items='["<ID>"]' -H "X-API-Key: 28837f83-2a6c-4973-acc1-8e5457596eea"
akaillidan commented 5 years ago

@akaillidan I think we need to be part of documentation, also add domain parts and aliases and other stuff.

how to simply find all api parameters

open chrome

Screenshot_2

press F5 and in "all" you can find all api url

Screenshot_3

then exec simple curl for see all attributes in items

Screenshot_4

in this screenshot we can see, need "item" in curl or not ( -d items='["#ID#"]' )

Screenshot_5

Sorry for my english

andryyy commented 5 years ago

Thanks to @feldsam you can use this https://github.com/mailcow/mailcow-dockerized/pull/2547

fhackenberger commented 5 years ago

For a list of all possible API objects, see the server backend code: https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/json_api.php#L129

ThomDietrich commented 5 years ago

For documentation purposes. According to https://mailcow.email/2019/10/14/mootober-updates there is now an official API.

See also: https://github.com/mailcow/mailcow-dockerized/pulls?utf8=%E2%9C%93&q=is%3Apr+author%3Antimo+API