Zimbra SOAP创建帐户

时间:2015-12-10 14:17:35

标签: php api rest soap zimbra

我想用 SOAP API 创建Zimbra用户帐户并且无法使其工作 - 这很奇怪,因为我可以获得 AuthToken 甚至可以通过请求 GetAccountRequest 查看已创建的帐户信息(通过管理员面板),但帐户的创建不起作用。

这是我的AuthToken(POST)请求代码:

Header: Content-Type: application/soap+xml

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header xmlns="urn:zimbra">
    <context></context>
  </soap:Header>
  <soap:Body>
    <AuthRequest xmlns="urn:zimbraAdmin" password="myPassword"> 
        <account by="adminName">my.name@mydomain.com</account> 
    </AuthRequest>
  </soap:Body>
</soap:Envelope>

这就行了,我收回了Auth令牌。

接下来,我尝试使用此(POST)请求创建新用户帐户:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header xmlns="urn:zimbraAdmin">
    <context>
<authToken> 0_69cd602eef3cf46bb488b02c6a173da698d17bdb_69643blablaTherestofmyauthtoken</authToken>
</context>
  </soap:Header>
  <soap:Body>
     <CreateAccountRequest xmlns="urn:zimbraAdmin" name="john.doe@mydomain.com" password="john123!"> 
        <a n="givenName">John</a>
        <a n="sn">Doe</a>
        <a n="displayName">John Doe</a>
    </CreateAccountRequest>
  </soap:Body>
</soap:Envelope>

这是我得到的回应:

SimpleXMLElement Object
(
    [soap:Code] => SimpleXMLElement Object
        (
            [soap:Value] => soap:Sender
        )

    [soap:Reason] => SimpleXMLElement Object
        (
            [soap:Text] => no valid authtoken present
        )

    [soap:Detail] => SimpleXMLElement Object
        (
            [Error] => SimpleXMLElement Object
                (
                    [Code] => service.AUTH_REQUIRED
                    [Trace] => btpool0-3022://zimbra.mydomain.com:7071/service/admin/soap:1449756733826:bc04a0eab6d6c7ec:SoapEngine368
                )

        )

)

有人能帮帮我吗?感谢..

1 个答案:

答案 0 :(得分:1)

所以我想出来了 - 当你发出AuthToken请求时,你会收到一个带有AuthToken值的cookie,当你尝试创建一个新的用户帐户时,你必须将这个cookie发送回头部分,如下所示: / p>

Cookie: ZM_ADMIN_AUTH_TOKEN=0_69cd602eef3cf46bb488b02c6a173da698d17bdb_69643blablaTherestofmyauthtoken

整个请求必须如下所示:

$request= array(
    'http' => array(
        'method'  => 'POST',
        'header'  => array(
            'Content-Type: application/soap+xml',
            'Cookie: ZM_ADMIN_AUTH_TOKEN=0_69cd602eef3cf46bb488b02c6a173da698d17bdb_69643blablaTherestofmyauthtoken',
        ),
        'timeout'  => 20, 
        'ignore_errors' => true,  
        'content'  => '
            <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
                <soap:Header xmlns="urn:zimbraAdmin">
                    <context>
                        <authToken> 0_69cd602eef3cf46bb488b02c6a173da698d17bdb_69643blablaTherestofmyauthtoken</authToken>
                    </context>
                </soap:Header>
                <soap:Body>
                    <CreateAccountRequest xmlns="urn:zimbraAdmin" name="john.doe@mydomain.com" password="john123!"> 
                        <a n="givenName">John</a>
                        <a n="sn">Doe</a>
                        <a n="displayName">John Doe</a>
                    </CreateAccountRequest>
                </soap:Body>
            </soap:Envelope>
        ',
    ),
);

documentation中说明了管理员授权令牌是必需的,但它并没有说明您必须通过请求标头中的cookie发送回来。