Set group field in contacts in bulk?

Hello,

I have import 1000 contacts via VCard 3.0 import to nc.
Now I want to mass add a group, but I don’t want to click each contact by contact and set the group manually.
Is it possible to set the group in bulk?

If is not possible by the GUI, perhaps it is possible with UPDATE command in the database?

Regards
Michael

Possible solutions I can think of:

  • Bash script using the occ user:list and user:setting commands
  • Use the OCS API’s
  • Not sure if you can safely edit the db, but that is probably the easiest way using SQL commands

Do you have an example or documentation-link, how I can implement “script with occ user” or access via OCS API?

Thanks!
Michael

I’m sorry I must have misunderstood your issue. Too many tasks in parallel today…
You mean the Contacts app and not Nextcloud’s user management?

The occ command is probably not applicable in this case.
And it doesn’t seem that there’s a Nextcloud specific API:

But it might be possible using CardDAV. But I cannot help you with that.
Maybe someone else is able to?

Manipulating the DB is still an option, but probably a dangerous one!

You can do it using the CardDAV interface. Details here: https://sabre.io/dav/building-a-carddav-client/. The hardest part is constructing the query properly. Here’s a near sample (it’s taken from working code, but I’ve manually trimmed it down a bit and removed language-specific constructs, and so it may have errors). In my requirement, I was pulling data from NC, whereas you want to do updates, so you’ll have to read some to convert my example to match your need.

First, you need a URL for the NC server you want to reach. Here’s an example of what I used:

`https://nextcloud.example.com/remote.php/dav/addressbooks/users/jsmith/contacts_shared_by_djones/`

You’ll need some headers in there. When I send the HTTP request, I include headers declaring the content type as “application/x-www-form-urlencoded” and the depth as 1. You’ll also need to pass user credentials. In my case, I created a new user in NC just for this, and shared my contacts with that user.

Finally, for retrieval at least, I needed to send XML to describe what I needed. Here’s the XML I sent:

<card:addressbook-query xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">
    <d:prop>
      <card:address-data>
       <card:prop name="FN"/>
       <card:prop name="EMAIL"/>
       <card:prop name="TEL"/>
       <card:prop name="CATEGORIES"/>
      </card:address-data>
    </d:prop>
</card:addressbook-query>

More details on the whole CardDAV interface is at the link I provided earlier in this post. Lots of bits and pieces there, but hopefully some of this will help get you going.

Good luck. Have fun.

3 Likes