Closed jniltinho closed 10 years ago
Erm... Do you mean to add an account (a user, that can use Zimbra) or a mail (a mail, that is sent by a user?) ;-)
For CreateAccount, the code should look like this:
account_request = RequestXml()
account_request.set_auth_token(auth_token) # Assuming you have created the auth_token before
account_request.add_request(
'CreateAccountRequest',
{
"name": "jniltinho",
"password": "secret",
"a": [
{
"n": "mail",
"_content": "jniltinho@company.com"
}
]
},
"urn:zimbraAdmin"
)
That should work.
:+1: Thanks!
I will test here
Error create account
>>> account_response = ResponseXml()
>>> comm.send_request(account_request, account_response)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pythonzimbra/communication.py", line 52, in send_request
self.timeout
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Server Error
>>>
File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: Server Error
This points towards a Zimbra Server error. When you watch the mailbox.log on your server, there should be an error as well. If that doesn't help, post the mailbox.log-error here as well.
Thanks.
Created preauth http://geobaby.in/zimbra-preauth-keys/
Create token ?
2014-01-01 11:29:57,753 WARN [qtp1044962984-127082:https://192.168.10.5:7071/service/admin/soap] [name=admin@domain.com.br;mid=1;ip=192.168.10.10;] SoapEngine - cannot dispatch request
com.zimbra.common.service.ServiceException: permission denied: need adequate admin token
ExceptionId:qtp1044962984-127082:https://192.168.10.5:7071/service/admin/soap:1388582997753:f28d550404fd7318
Code:service.PERM_DENIED
at com.zimbra.common.service.ServiceException.PERM_DENIED(ServiceException.java:288)
at com.zimbra.soap.SoapEngine.dispatchRequest(SoapEngine.java:468)
at com.zimbra.soap.SoapEngine.dispatch(SoapEngine.java:385)
at com.zimbra.soap.SoapEngine.dispatch(SoapEngine.java:258)
at com.zimbra.soap.SoapServlet.doWork(SoapServlet.java:293)
at com.zimbra.soap.SoapServlet.doPost(SoapServlet.java:209)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at com.zimbra.cs.servlet.ZimbraServlet.service(ZimbraServlet.java:208)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:654)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1320)
at com.zimbra.cs.servlet.RequestStringFilter.doFilter(RequestStringFilter.java:52)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1291)
at com.zimbra.cs.servlet.SetHeaderFilter.doFilter(SetHeaderFilter.java:57)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1291)
at org.eclipse.jetty.servlets.UserAgentFilter.doFilter(UserAgentFilter.java:82)
at org.eclipse.jetty.servlets.GzipFilter.doFilter(GzipFilter.java:256)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1291)
at com.zimbra.cs.servlet.ETagHeaderFilter.doFilter(ETagHeaderFilter.java:45)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1291)
at com.zimbra.cs.servlet.ZimbraQoSFilter.doFilter(ZimbraQoSFilter.java:105)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1291)
at org.eclipse.jetty.servlets.DoSFilter.doFilterChain(DoSFilter.java:474)
at org.eclipse.jetty.servlets.DoSFilter.doFilter(DoSFilter.java:345)
at org.eclipse.jetty.servlets.DoSFilter.doFilter(DoSFilter.java:316)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1291)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:443)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:556)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1044)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:372)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:978)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:317)
at org.eclipse.jetty.server.handler.DebugHandler.handle(DebugHandler.java:81)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:369)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:486)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:944)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1005)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:724)
2014-01-01 11:29:57,754 INFO [qtp1044962984-127082:https://192.168.10.5:7071/service/admin/soap] [name=admin@domain.com.br;mid=1;ip=187.103.131.250;] soap - CreateAccountRequest elapsed=1
SoapEngine - cannot dispatch request com.zimbra.common.service.ServiceException: permission denied: need adequate admin token That's quite obvious. You either specified a non-admin-account or got the username/password-combo wrong. Could that be?
When I put the login and password of the admin token returns empty How do I generate the token for the user admin
How do I generate the token for the user admin
Normally you would use
from pythonzimbra.tools import auth
token = auth.authenticate(
<Zimbra-Preauth-URL>,
<Admin-user>,
<Domain preauth-key>
)
to generate the token. This will work for admins and non-admins. That token can then be used in RequestXml or RequestJson-Objects.
Did you use it that way?
Yes, return token like:
u'0_1cf3436c135b98dd033293a3146ff6d3dc22bf8b_69643d33363a61613630623265372d343266362d343635392d623665622d3236656439353232623864333b578703d31333a313338383833303337333630393b76763d313a313b747970653d363a7a696d672613b'
from pythonzimbra.tools import auth
from pythonzimbra.request_xml import RequestXml
from pythonzimbra.response_xml import ResponseXml
from pythonzimbra.communication import Communication
url = "https://webmail.domain.com:7071/service/admin/soap"
comm = Communication(url)
token = auth.authenticate(url,'admin@domain.com','caefc9665fe75f39fc7bc2e4762926fb872f3bed475049cb9b11bbdcee8a')
account_request = RequestXml()
account_request.set_auth_token(token)
account_request.add_request(
'CreateAccountRequest',
{
"name": "jniltinho",
"password": "pass12345678",
"a": [
{
"n": "mail",
"_content": "jniltinho@domain.com"
}
]
},
"urn:zimbraAdmin"
)
account_response = ResponseXml()
comm.send_request(account_request, account_response)
Hmm... should work. What version of Zimbra are you using? Does the admin you're using in the request actually has the right to create an account?
8.0.5_GA_5839.FOSS, yes super admin
Changed to "Enhancement". The problem is, that Admin-Authentications needs to be on a specific URL, with a specific namespace and only with password.
This should be supported by the auth tool.
Fixed in 35e476d1bc6cb2ba1736a88c22c86ef3ca7751c8 and the upcoming new release candidate.
Please try again then. Use the admin password instead of the preauth key and set admin_auth to True.
Just noticed, that I myself opened an enhancement request for this ages ago: https://bugzilla.zimbra.com/show_bug.cgi?id=48176
:-)
[ask] how to create function to get all users on zimbra with this following doc http://files.zimbra.com/docs/soap_api/8.0.7/soap-docs-807/api-reference/index.html ?
@rephapeng Please create a new bug for your question or - even better - ask the question on the Zimbra developer forum. :)
How do I create a function to add an e-mail using their api following this doc
http://files.zimbra.com/docs/soap_api/8.0.4/soap-docs-804/api-reference/index.html