Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact Import Error: VCard object with uid already exists in this addressbook collection. #3821

Open
schast opened this issue Feb 22, 2024 · 3 comments
Labels

Comments

@schast
Copy link

schast commented Feb 22, 2024

Describe the bug

Error on importing already existing vcards.

Steps to reproduce

  1. Go to contacts -> contact settings
  2. Click on contact import
  3. Upload File (Toni_Testeroni.vcf):
BEGIN:VCARD
VERSION:3.0
N:Testeroni;Toni;;;
FN:Toni Testeroni
TEL;TYPE=home,voice:+43 123 456789
TEL;TYPE=cell,voice:+43 664 123456789
ADR;TYPE=home:;;Straße 123-456;Ort;;1234;Land
URL;TYPE=home:http://toni.testeroni.com
X-SOCIALPROFILE;TYPE=FACEBOOK:FacebookUser
X-SOCIALPROFILE;TYPE=SKYPE:SkypeUser
X-SOCIALPROFILE;TYPE=LINKEDIN:LinkedInUser
X-SOCIALPROFILE;TYPE=INSTAGRAM:InstagramUser
X-SOCIALPROFILE;TYPE=MASTODON:MastodonUser
BDAY:1990-01-01
EMAIL;TYPE=home:toni.testeroni@mydomain.com
REV:20240222T081751Z
UID:urn:uuid:9130b79c-9f59-456e-a96b-bf633fac5882
END:VCARD
  1. The vcard is successfully imported the first time it is created.
  2. Upload the card again (the error also occurs with the REV field updated to the current timestamp).
  3. See error in Browser Debug Console (Networking Tab)
  • Request:
PUT https://NEXTCLOUD-SERVER-URL/remote.php/dav/addressbooks/users/NEXTCLOUD-USERNAME/NEXTCLOUD-CALENDAR-NAME/F69E2CA2-A5F4-443D-9478-392AC94847E7.vcf
  • Response:
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\BadRequest</s:exception>
  <s:message>VCard object with uid already exists in this addressbook collection.</s:message>
</d:error>

Expected behavior

Existing vcards shlould be updated.

Actual behavior

Error on import for existing contacts.

Contact version

5.5.2

Operating system

Ubuntu 22.04, Nextcloud Server 28.0.2

PHP engine version

PHP 8.1

Web server

Apache (supported)

Database

MariaDB

Additional info

Without the UID field, the contact will be created twice!

@LionelHoudelier
Copy link

LionelHoudelier commented Apr 22, 2024

Same problem !
Since when does it appear for you?

STRANGE:

  1. export a contact vcf file via web UI: afilenameofcontactexport.vcf
    If the file name in the url is the same of a contact export file, it works with this command:
  2. with curl -X PUT -u "$user":"$pass" "https://${cloud}/remote.php/dav/addressbooks/users/$user/$addressbook/afilenameofcontactexport.vcf" -T "$xfile"
    You can change the content for any contact UID. It works. but with another name, it does not.
  3. with curl -X PUT -u "$user":"$pass" "https://${cloud}/remote.php/dav/addressbooks/users/$user/$addressbook/" -T "$xfile" it sends the error "VCard object with uid already exists in this addressbook collection"

@LionelHoudelier
Copy link

SOLUTION :
extract the UID of file :
uid=$(grep UID "$xfile" | sed 's/.*://')
add it to the url + ".vcf"
then it works
PS: we have to have added first the new contacts with this procedure.

@LionelHoudelier
Copy link

LionelHoudelier commented Apr 26, 2024

Here is a full script to add AND update contacts from one file with some vcard:

#!/bin/bash
#### ENTER YOUR DATAS ##########
# folder to parse the file
temp_folder=/home/.....
# folder where is the vcf file
folder='/home/...'
filename='VCARD_FILE.vcf'
user='XXX'
pass='XXXXX'
addressbook='XXXX'
cloud='your.nextcloud.url'
##########################################################
filepath="$folder""$filename"
url="https://${cloud}/remote.php/dav/addressbooks/users/$user/$addressbook"
echo $url
# parse the file in multiple random files name
mkdir -p $temp_folder
rm -f $temp_folder/*
echo "$folder"
inotifywait --format="%w%f" -m "$folder" -e moved_to |
    while read file; do
  if [[ "$file" == *".vcf" ]]
  then 
  awk -v temp_folder="$temp_folder" 'BEGIN {
        RS="END:VCARD";
        }
        {
        command = "echo -n '$temp_folder'/$(pwgen 20 1).vcf"
        command | getline filename
        close(command)
        print $0 "END:VCARD" > filename
        close(filename)
        }' "${filepath}"
      for xfile in "$temp_folder"/*.vcf; do
        if grep -q "BEGIN:" "$xfile"; then
          uid=$(grep UID "$xfile"  | sed 's/.*://')
          echo "UID : " "$uid"
          curl -X PUT -u "$user":"$pass" "$url/$uid.vcf" -T "$xfile"
          echo "ok"
          rm "$xfile"
        fi
      done
  fi
done
command = "echo -n '$temp_folder'/$(pwgen 20 1).vcf"
        command | getline filename
        close(command)
        print $0 "END:VCARD" > filename
        close(filename)
        }' "${filepath}"
# upload the files
      for xfile in "$temp_folder"/*.vcf; do
        if grep -q "BEGIN:" "$xfile"; then
      for xfile in "$temp_folder"/*.vcf; do
        if grep -q "BEGIN:" "$xfile"; then
          uid=$(grep UID "$xfile"  | sed 's/.*://')
          echo "UID : " "$uid"
          curl -X PUT -u "$user":"$pass" "$url/$uid.vcf" -T "$xfile"
          echo "ok"
          rm "$xfile"
        fi
      done
  fi
done
rm -f $temp_folder/*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants