CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Can I add a contact via the API specifying the contact_id?
Pages: [1]

Author Topic: Can I add a contact via the API specifying the contact_id?  (Read 760 times)

murrayb

  • Guest
Can I add a contact via the API specifying the contact_id?
November 01, 2010, 01:57:09 am
I am implementing CiviCRM and am importing data from an ancient MIS system. The MIS system has a member number for each contact. This member number is known to the members and extensively used by them, including being printed on their membership card. We would therefore like to keep these member numbers when we move to CiviCRM as they are so weel used and known by our members.

I can import the member number into a custom field and have this working fine. I am doing the contact import using the API as all the data is known and I have no problem with duplicates since the member number is unique. However what we would much prefer to do is to use the existing member number as the CiviCRM contact id. That way it would be the primary key and we would not have to search for members by member number. This would a much cleaner and more efficient method.

However neither the contact add nor the contact update API allow the contact_id to be set or changed. Is there some way we can achieve this?

It seems to me that there must be many others who are the same position of importing contacts that already have a unique identifier.

Thanks . . . Murray

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Can I add a contact via the API specifying the contact_id?
November 01, 2010, 02:16:57 am
Quote
However neither the contact add nor the contact update API allow the contact_id to be set or changed. Is there some way we can achieve this?
Nope we don't allow update of contact id. "id" is auto increment field in DB.

You can use external identifier field to store for storing unique identifier.

Kurund
Found this reply helpful? Support CiviCRM

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Can I add a contact via the API specifying the contact_id?
November 01, 2010, 02:21:03 am
Hi,

You can't set the value of an autoincrement field (at the db level), so you can't set the internal id.

What I did for a customer was to be sure the internal contact id was > than their last membership number, create a membership number (not sure anymore if it was a custom field or external identifier), and then create a hook so every time they create a new membership, it sets this membership number to the contact_id number.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: Can I add a contact via the API specifying the contact_id?
November 01, 2010, 02:23:45 am
murrayb :
Quote
However neither the contact add nor the contact update API allow the contact_id to be set or changed. Is there some way we can achieve this?
Nope. You can't update the contact id.

Why don't you use external_identifier mapped as the member number which is also unique for each contact and is meant to be used for cases like yours. External identifier can be be added/updated through apis.

HTH
-Yashodha
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

murrayb

  • Guest
Re: Can I add a contact via the API specifying the contact_id?
November 01, 2010, 03:25:27 am
Thanks very much for the prompt and helpful reply. Great for a newbie like me.

I missed the external id field so will try this as it sounds like what I need.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Can I add a contact via the API specifying the contact_id?

This forum was archived on 2017-11-26.