I need to use the Zimbra Soap API for a new feature we're working on. However, I have not been able to find a lot of examples of Java clients using this API and I am overall a bit lost as to what I need to look into. (I am pretty new to using SoAP in general)
Basically, I will need to send a username and get some sort of zimbra ID for the user, modify user info with my java code, and then push that data back to the server.
I have found the wsdl files for this on the server, but I'm not sure where to go from here. Any help would be appreciated - anything from high level explanations to examples to detailed steps.
Thanks in advance!
Sadly, the Zimbra SOAP API isn't really SOAP. It's basically XML-over-HTTP. So you'll have to manually create the xml-documents you send to zimbra.
I don't know about a Java library for this, I did a Python one.
You can use Zimbra libraries for calling SOAP API:
package com.example.test
import com.zimbra.common.account.ZAttrProvisioning;
import com.zimbra.common.service.ServiceException;
import com.zimbra.common.soap.AdminConstants;
import com.zimbra.common.soap.Element;
import com.zimbra.common.soap.SoapHttpTransport;
import com.zimbra.cs.account.AccountServiceException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
public class ZimbraApi {
private static SoapHttpTransport soapHttpTransport = null;
private String baseUrl = "https://mail.example.com:7071/service/admin/soap/";
public String getAdminToken(String username, String password) {
URL url = new URL(baseUrl);
soapHttpTransport = new SoapHttpTransport(url.toURI().toString());
soapHttpTransport.setVoidOnExpired(true);
Element request = Element.XMLElement.mFactory.createElement(AdminConstants.AUTH_REQUEST);
request.addAttribute(AdminConstants.E_NAME, username);
request.addAttribute(AdminConstants.E_PASSWORD, password);
Element response = soapHttpTransport.invoke(request);
String token = response.getAttribute(AdminConstants.E_AUTH_TOKEN);
soapHttpTransport.setAuthToken(token);
return token;
}
public void createAccount(String username, String password) {
Element request = Element.XMLElement.mFactory.createElement(AdminConstants.CREATE_ACCOUNT_REQUEST);
request.addAttribute(AdminConstants.E_NAME, username);
request.addAttribute(AdminConstants.E_PASSWORD, password);
soapHttpTransport.invoke(request);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With