Connect. Communicate. Collaborate. Securely.

Home » Developer Zone » API/SDK Writers » Create domains in API
  •  
nhoague

Messages: 853
Karma: 18
Send a private message to this user
Hello, I'm trying to work a script to automatically create domains on our backup servers.

I can get the list of domains on the production server, but how would I create domains on the backup servers? Here is what my goal is:

primary mail server = mail.company.com
backup mail server = backup.company.com

domain on primary: acme.com

So I would want to do this on the backup server via API

1) domains.create acme.com
2) domains.set FwHost='mail.company.com', FwPort='25'

I have tried many variations of this and I can't figure it out!

{
"jsonrpc":"2.0",
"id":1,
"method":"Domains.create",
"params":{"query":{"fields":{}}
},"domainList":"acme.com"
}

  •  
Miroslav Osladil (Kerio)

Messages: 188

Karma: 27
Send a private message to this user
Hello,
to create a domain with a forwarding to another server, call
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "Domains.create",
  "params": {
    "domains": [
      {
        "name": "domain.com",
        "forwardingOptions": {
          "isEnabled": true,
          "host": "backup.domain.com",
          "port": 25,
          "how": "Online",
          "preventLoop": false
        }
      }
    ]
  }
}


Best regards,

Miroslav Osladil
Senior Developer
Kerio Technologies

The views I express are my own and do not necessarily reflect the views of Kerio Technologies.
  •  
nhoague

Messages: 853
Karma: 18
Send a private message to this user
Awesome!

Now, last question. I realized that some of our domains have domain aliases.

How would I a) get the domain alias from the primary server? and b) use API to setup domain alias on backup server?

Thank you!!!
  •  
nhoague

Messages: 853
Karma: 18
Send a private message to this user
Scratch that, I figured it out!

I found the aliasList function that works for me.

Thanks anyways!
  •  
Miroslav Osladil (Kerio)

Messages: 188

Karma: 27
Send a private message to this user
Exactly! Smile

If you call Domains.get with query fields containing 'aliasList' then you will the list of its domain aliases, e.g.
"params": {
  "query": {
    "fields": [
      "aliasList"
    ]
  }
}


Anyway, to create a domain on your backup server also with a domain alias, extend previous query by
"aliasList": [
  "some-alias.com"
]


Cheers,

[Updated on: Fri, 09 December 2011 14:49]


Miroslav Osladil
Senior Developer
Kerio Technologies

The views I express are my own and do not necessarily reflect the views of Kerio Technologies.
  •  
nhoague

Messages: 853
Karma: 18
Send a private message to this user
Ok, now the reverse. How do I delete domains?

I've tried all variants of domains.remove but the syntax just isn't clicking for me Sad

{
"jsonrpc":"2.0",
"id":1,
"method":"Domains.remove",
"params":{
"domains":{

}
},"domainId":"keriodb://domain/b4ab21c8-08a1-4fee-b334-27420a1d4fd4"
}

Thank you.
  •  
Miroslav Osladil (Kerio)

Messages: 188

Karma: 27
Send a private message to this user
Hello,
according to documentation you need to put domainIds as a param where domainIds is a list, e.g.:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "Domains.remove",
  "params": {
    "domainIds": [
      "keriodb://domain/6518 ... 2c88",
      "keriodb://domain/5d2f ... fcc1",
      "keriodb://domain/359c ... bd89"
    ]
  }
}


Best regards,

Miroslav Osladil
Senior Developer
Kerio Technologies

The views I express are my own and do not necessarily reflect the views of Kerio Technologies.
  •  
nhoague

Messages: 853
Karma: 18
Send a private message to this user
I have a script that keeps multiple Kerio servers' domains in sync. It keeps 72 domains in sync and works, most of the time. Occasionally my script will timeout with these errors:

Warning: feof() expects parameter 1 to be resource, boolean given in /var/www/ops/class/KApiSocket.class.php on line 83 Warning: fgets() expects parameter 1 to be resource, boolean given in /var/www/ops/class/KApiSocket.class.php on line 84

The weird thing is sometimes the script works flawlessly, sometimes it fails on the first domain, sometimes in the middle. There is no rhyme or reason! I havent modified the API scripts at all, so perhaps you can help me understand what this line is listening for?

  •  
Miroslav Osladil (Kerio)

Messages: 188

Karma: 27
Send a private message to this user
Hmm, weird. I'm just guessing... a network timeout?

Try to set 5 sec of timeout by method $api->setTimeout(5).

Miroslav Osladil
Senior Developer
Kerio Technologies

The views I express are my own and do not necessarily reflect the views of Kerio Technologies.
  •  
nhoague

Messages: 853
Karma: 18
Send a private message to this user
Awesome. My script has now run 3 times in a row without fail. I'll keep an eye on it, but this may have just helped!

Thanks!
Previous Topic: Set custom spam rule list
Next Topic: experience using API with .NET Framework (VB/C#)
Goto Forum:
  


Disclaimer:
Kerio discussion forums are intended for open communication between forum members and may contain information and material posted by members which may be useful in learning about Kerio products. The discussion forums are not intended to provide technical support for any specific product. Any information implied or expressed in the discussion forums is that of the posting member. Kerio is in no way responsible for the information posted in the forums, or its accuracy. Kerio employees may participate in the discussions, but their postings do not represent an offical position of the company on any issues raised or discussed. Kerio reserves the right to monitor and maintain the forums to promote free and accurate exchange of information.

Current Time: Wed Nov 22 21:33:04 CET 2017

Total time taken to generate the page: 0.00445 seconds
.:: Contact :: Home ::.
Powered by: FUDforum 3.0.4.