Results 1 to 8 of 8

Thread: Contact Import 5.0.2

  1. #1
    drhughes is offline Senior Member
    Join Date
    Dec 2007
    Posts
    50
    Rep Power
    7

    Default Contact Import 5.0.2

    Has the import for 5.0.2 changed from:
    curl -u schemers: password --data-binary @/tmp/new.csv http://server/service/home/schemers/contacts?fmt=csv

    I get:

    <body><h2>HTTP ERROR: 400</h2><pre>could not parse csv file</pre>

  2. #2
    drhughes is offline Senior Member
    Join Date
    Dec 2007
    Posts
    50
    Rep Power
    7

  3. #3
    drhughes is offline Senior Member
    Join Date
    Dec 2007
    Posts
    50
    Rep Power
    7

    Default

    Anybody out there can shed some light on this work around?

    "the workaround before 5.0.3 is to upload the csv file FileUploadServlet, then use the SOAP call
    ImportContactsRequest with the upload-id returned from FileUploadServlet."

  4. #4
    Chewie71 is offline Trained Alumni
    Join Date
    Sep 2006
    Location
    Illinois
    Posts
    371
    Rep Power
    8

    Default

    dr...

    We voted on and put in a support ticket for that bug since we are preparing to migrate about 10000 students to our servers. We came up with a different workaround using 'zmmailbox cct' (see zmmailbox help contact) before they published that SOAP workaround.

    I don't know enough about SOAP to know anything about that method, but what we figured out seems to work. If you want some help figuring out the 'zmmailbox cct' method, PM me and I'll get you my contact info.

    Matt

  5. #5
    benwong is offline New Member
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    7

    Default Workaround working?

    Hi,

    Has anybody been able to get the work around working? I'm able to auth, get an auth token but when I submit it via the CURL command, it gives back a

    401,null response. No attachment id like it says in the work around.

    I'm on 5.0.2

  6. #6
    drhughes is offline Senior Member
    Join Date
    Dec 2007
    Posts
    50
    Rep Power
    7

    Default

    benwong,

    I'm working on a perl script as a work around until 5.0.3 is out. When I'm done with it, I will be more then happy to share. I wouldn't use it for a huge number of accounts to convert. I'm using SSH along with Chewie71's suggestion of 'zmmailbox cct'.

    I ran a test with Zimbra 5.0.1 on a single 1U Dell 1950 with about 30 accounts. Our student's loved it. I now have a production multi-server (Suse Enterprise 10.1) environment that I need to bring those test users over to. The catch is that for this script to work you will have to know the user's password. We run Novell eDirectory with Univerisal Passwords turned on. My co-worker was put togther some tools to lookup passwords

    Cool Solutions: Universal Password Retrieval Utility

  7. #7
    benwong is offline New Member
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    7

    Default

    After much hacking and trial and error I created this PHP script, runnable from the shell, to import a user's address book.

    I tested this with our own installation and it works. All you need is to have PHP CLI available, compiled with CURL.

    For linux systems might be necessary to change the first line to: #!/usr/bin/php

    Use it like this:

    ./import-to-zimbra.php username password csvfile.csv zimbra.domain.com

    Output looks like this:

    PHP Code:
    Getting Auth Key 
      
    SuccessAuth Token0_2ab13ad27196762b.....8303b
    Uploading CSV File  
    csvs/emailtest.csv 
      - 
    DoneAIDa9c937fe-485f-4cee-8abb-f50398342295:a55aacab-62c3-42ee-b4c9-e1ab39bd9480 
    Sending SOAP Request to Import Contacts
    ... 
      - 
    Done 
    Have fun!


    PHP Code:
    #!/usr/local/bin/php
    <?php
    /*********************************
     * Work around code to import .csv address books into Zimbra 5.0.2 
     *
     * Date  : March 20, 2008
     * Author: Benson Wong
     *   email: benwong@sutton.com
     *   web: http://www.mostlygeek.com
     *********************************/


    $username $argv[1]; 
    $password $argv[2];
    $csvfile  $argv[3]; 
    $server   $argv[4];

    if (!
    file_exists($csvfile)) {
        
    print_die_usage("CSV File: $csvfile does not exist");
    }

    if (!
    $server) {
        
    print_die_usage("Server name missing");
    }

    $url "https://$server/service/soap";

    // Get the AUTH Key
    echo "Getting Auth Key \n";
    $SOAPMessage sprintf('<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
                                <soap:Header><context xmlns="urn:zimbra"/></soap:Header>
                                <soap:Body><AuthRequest xmlns="urn:zimbraAccount">
                                    <account by="name">%s</account> 
                                    <password>%s</password>
                                </AuthRequest></soap:Body></soap:Envelope>'
    ,$username,$password);
                      
    $CurlHandle GetCurlHandler($url);
    curl_setopt($CurlHandleCURLOPT_POSTFIELDS$SOAPMessage);                  

    if(!(
    $ZimbraSOAPResponse curl_exec($CurlHandle)))  {
        print(
    "ERROR: curl_exec - (" curl_errno($CurlHandle) . ") " curl_error($CurlHandle));
    }

    if (
    strstr($ZimbraSOAPResponse,'AUTH_FAILED'))
        die(
    "  - ERROR: Authentication Failed\n"); 

    $auth_token ereg_replace('^.*<authToken>','',$ZimbraSOAPResponse);
    $auth_token ereg_replace('</authToken>.*$','',$auth_token);

    echo 
    '  - Success. Auth Token: 'substr($auth_token,0,18) . '.....' substr($auth_token,-5)."\n"

    // upload the file 
    echo "Uploading CSV File  [ $csvfile ] \n"
    $cmd "curl -u $username:$password --header \"Content-Type: text/csv; name=$username.csv\" "
              
    ."--header \"Cookie: ZM_AUTH_TOKEN=$auth_token\" "
              
    ."--data-binary @$csvfile \"https://$server/service/upload?fmt=raw\" 2>/dev/null";

    $resp = `$cmd`;
    $resp str_replace("'",'',$resp);
    $aid array_pop(explode(',',$resp));
    $aid trim($aid);
    echo 
    "  - Done. AID: $aid \n"

    $SOAPMessage sprintf('<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header>
                        <context xmlns="urn:zimbra">
                            <authToken>%s</authToken>
                        </context></soap:Header><soap:Body>
                        <ImportContactsRequest ct="csv" xmlns="urn:zimbraMail">
                            <content aid="%s"/>
                        </ImportContactsRequest>
                        </soap:Body></soap:Envelope>'
    ,$auth_token,$aid);

    echo 
    "Sending SOAP Request to Import Contacts... \n";
    $CurlHandle GetCurlHandler($url);
    curl_setopt($CurlHandleCURLOPT_POSTFIELDS$SOAPMessage);
    curl_setopt($CurlHandleCURLOPT_USERPWD,"$username:$password);

    if(!(
    $ZimbraSOAPResponse curl_exec($CurlHandle)))  {
        print(
    "ERROR: curl_exec - (" curl_errno($CurlHandle) . ") " curl_error($CurlHandle));
    }
    echo 
    "  - Done\n";

    /**** FUNCTIONS ****/

    function GetCurlHandler($url,$verbose=0) {
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_URL,            $url);
        
    curl_setopt($chCURLOPT_POST,           true);
        
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
    curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
        
    curl_setopt($chCURLOPT_TIMEOUT15);
        if (
    $verbose)
            
    curl_setopt($chCURLOPT_VERBOSE,1);    
        return 
    $ch;
    }

    function 
    print_die_usage($message '') {
        global 
    $argv
        
        echo 
    "Error: $message\n"
        echo 
    "Usage: $argv[0] username password csvfilename server\n";
        echo 
    "  example: $argv[0] emailtest PassWord944 emailtest.csv zimbra.domain.com\n";
        die();
    }

  8. #8
    benwong is offline New Member
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    7

    Default test

    testing... i had a bunch of code but it doesn't seem to post.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 12
    Last Post: 06-13-2013, 08:55 AM
  2. ical4j.data.ParserException
    By amit_saini54 in forum Migration
    Replies: 0
    Last Post: 12-06-2007, 07:45 AM
  3. Replies: 1
    Last Post: 07-27-2007, 12:19 PM
  4. Can't import contact data to OTHER: Web Page?
    By gihrig in forum Administrators
    Replies: 0
    Last Post: 10-11-2006, 02:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •