View Single Post
  #4 (permalink)  
Old 07-05-2007, 08:27 AM
mikes2277 mikes2277 is offline
Member
 
Posts: 11
Default

Thanks! That got me to the point to where I could get an account to be added using the code below but I am having a hard time passing attributes i.e. COS. I know what the SOAP packet should look like but I can't get the PHP SOAP functions to put the attribute in correctly. Using CURL would be 100x easier because I could just get the traces from zmprov and then just toss in the values I needed to substitue where appropriate.

I want to send (I got my object ID from "zmproc gc basicemail"):
<a n="zimbraCOSid">f070eede-c0c5-4867-a158-1f35f1c39e15</a>

But what my code is sending is:
<a n="zimbraCOSid">f070eede-c0c5-4867-a158-1f35f1c39e15</a n="zimbraCOSid">

I get back a:
<soap:Reason><soap:Text>parse error: Error on line 2 of document : The end-tag for element type "a" must end with a '>' delimiter. Nested exception: The end-tag for element type "a" must end with a '>' delimiter.</soap:Text></soap:Reason>

I can't seem to get the closing </a> to not include the n="zimbraCOSid". I am also wondering if the SOAP PHP functions are doing anything special (other than frustrating me) or if I can just make a string of the XML/SOAP that I want to send and just use CURL to send it over. Frankly, all of my problems have come from trying to guess how the PHP SOAP lib works, not how Zimbra's SOAP interface works... Any insight on how to fix my closing tag problem and/or if CURL can do it on its own would be greatly appreciated. Thanks!

Code:
function ZimbraAdminCreateAccount($Trace, $ServerAddress, $AdminUserName, $AdminPassword, $NewUserName, $NewPassword)
{
        $client = new SoapClient(NULL,
                array
                (
                        "location"      => "https://$ServerAddress:7071/service/admin/soap",
                        "uri"           => "urn:zimbra",
                        "trace"         => $Trace,
                        "exceptions"    => "1",
                        "soap_version"  => SOAP_1_1,
                        "style"         => SOAP_RPC,
                        "use"           => SOAP_LITERAL
                )
        );

        try
        {
                $ZimbraSession = $client->__soapCall("AuthRequest",
                        array
                        (
                                new SoapParam("$AdminUserName", "name"),
                                new SoapParam("$AdminPassword", "password")
                        ),
                        array
                        (
                                "uri"           => "urn:zimbraAdmin",
                                "soapaction"    => "urn:zimbraAdmin#AuthRequest"
                        ),
                        new SoapHeader("urn:zimbra", "context")
                );
        }
        catch (SoapFault $exception)
        {
                echo "Login exception caught<br><br>";
                echo htmlentities($client->__getLastRequest()) . "<br><br>";
                echo htmlentities($client->__getLastResponse()) . "<br><br>";
                echo $exception . "<br><br>";
        }


        // echo "----- Logged in<BR><BR>";

                try
        {
                $ZimbraReturn = $client->__soapCall("CreateAccountRequest",
                        array
                        (
                                new SoapParam("$NewUserName", "name"),
                                new SoapParam("$NewPassword", "password"),
                                new SoapParam("f070eede-c0c5-4867-a158-1f35f1c39e15", "a n=\"zimbraCOSid\"")
                        ),
                        array
                        (
                                "uri"           => "urn:zimbraAdmin",
                                "soapaction"    => "urn:zimbraAdmin#CreateAccountRequest"
                        ),
                        array
                        (
                                new SoapHeader("urn:zimbra", "context", new SoapVar("<ns2:context><authToken>" . $ZimbraSession[authToken] . "</authToken></ns2:context>", XSD_ANYXML))
                        )
                );
        }
        catch (SoapFault $exception)
        {
                echo "CreateAccountRequest exception caught<br><br>";
                echo "Sent: " . htmlentities($client->__getLastRequest()) . "<br><br>";
                echo "Received: " . htmlentities($client->__getLastResponse()) . "<br><br>";
        }


        // echo "Sent: " . htmlentities($client->__getLastRequest()) . "<br><br>";
        // echo "Received: " . htmlentities($client->__getLastResponse()) . "<br><br>";
        return($ZimbraReturn);
}
Reply With Quote