Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Migration

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-07-2008, 08:11 AM
Senior Member
 
Posts: 50
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>
Reply With Quote
  #2 (permalink)  
Old 03-07-2008, 08:24 AM
Senior Member
 
Posts: 50
Default

I see this is a bug.

Bug 24793 - Rest interface doesn't work for specific csv import using curl
Reply With Quote
  #3 (permalink)  
Old 03-07-2008, 08:30 AM
Senior Member
 
Posts: 50
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."
Reply With Quote
  #4 (permalink)  
Old 03-07-2008, 02:16 PM
Trained Alumni
 
Posts: 343
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
Reply With Quote
  #5 (permalink)  
Old 03-19-2008, 06:22 PM
New Member
 
Posts: 3
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
Reply With Quote
  #6 (permalink)  
Old 03-20-2008, 06:16 AM
Senior Member
 
Posts: 50
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
Reply With Quote
  #7 (permalink)  
Old 03-20-2008, 04:00 PM
New Member
 
Posts: 3
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();
}
Reply With Quote
  #8 (permalink)  
Old 03-20-2008, 04:00 PM
New Member
 
Posts: 3
Default test

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.