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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • SOLVED! REST API - How to add new email to a new contact
Pages: [1]

Author Topic: SOLVED! REST API - How to add new email to a new contact  (Read 896 times)

primerg

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 3.4
  • CMS version: drupal 6
  • MySQL version: 5.x
  • PHP version: 5.2
SOLVED! REST API - How to add new email to a new contact
September 11, 2012, 08:17:26 pm
I have created a new contact using the REST API. I need to add 1 or 2 email information for the contact. the connection works and the api gives back some data (no error) but the ID is still NULL and when I check it, the email is still not updated.

(I'm calling to a Drupal 6 with Civicrm v2.4)

Below is the actual call
/sites/all/modules/civicrm/extern/rest.php?json=1&debug=1&api_key=[API]&key=[KEY]&PHPSESSID=[SESSID]&entity=Email&action=create&id=&contact_id=3073&location_type_id=5&email=test@test[dot]net&is_billing=0&on_hold=0&is_bulkmail=0

Here is the response:
Quote
Array
(
    [success] => 1
    [response] => stdClass Object
        (
            [is_error] => 0
            [undefined_fields] => Array
                (
                   
  • => api_key
  • [1] => PHPSESSID
                    )

                [version] => 3
               
[count] => 1
            [id] => null
            [values] => stdClass Object
                (
                    [null] => stdClass Object
                        (
                            [id] => null
                            [contact_id] => 3073
                            [location_type_id] => 5
                            [email] => test@test[dot]net
                            [is_primary] => 0
                            [is_billing] => 0
                            [on_hold] => 0
                            [is_bulkmail] => 0
                            [hold_date] =>
                            [reset_date] =>
                            [signature_text] =>
                            [signature_html] =>
                        )

                )

        )

)

I tried doing the following based on another forum thread here:
/sites/all/modules/civicrm/extern/rest.php?json=1&debug=1&api_key=APII&key=KEY&PHPSESSID=SESSID&entity=Contact&action=update&id=3073&contact_type=Individual&first_name=James&last_name=Radford&is_opt_out=0&sort_name=Radford, James&display_name=James Radford&preferred_mail_format=Both&email_greeting_id=1&email_greeting_display=Dear James&postal_greeting_id=1&postal_greeting_display=Dear James&addressee_id=1&addressee_display=James Radford&is_deceased=0&is_deleted=0&contact_is_deleted=0&preferred_mail_format_display=Both&custom_1=0&custom_374=1698&custom_376=Chicago&custom_428=0&contact_id=3073&api.email.replace={"values":{"location_type_id":"5","email":"test@test[dot]net","is_primary":"1","is_billing":"0","on_hold":"0","is_bulkmail":"0"}}


that doesn't work either. Am I missing something?

(I could not use the code tag, giving me error so  I just used the quote tag above.)
« Last Edit: October 11, 2012, 01:12:55 am by primerg »

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: REST API - How to add new email to a new contact
September 11, 2012, 08:35:04 pm
In the first example you have id=& - does removing that make a difference?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: REST API - How to add new email to a new contact
September 11, 2012, 11:15:52 pm
Hi,

Are you using civicrm 2.4 or 3.4?

The response should  be xml or json, not array. Looks like a dump debug msg.

Anyway, civi rest has improved a lot in the latest versions. you should update to 4.2

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

primerg

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 3.4
  • CMS version: drupal 6
  • MySQL version: 5.x
  • PHP version: 5.2
Re: REST API - How to add new email to a new contact
October 09, 2012, 07:13:43 pm
Figured the problem. I just need to add urlencode() for some values.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: REST API - How to add new email to a new contact
October 09, 2012, 11:39:13 pm
Be careful, if you are using civicrm version 2 it means the entity/action combination in the API call will not work (as far as I know)!
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

primerg

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 3.4
  • CMS version: drupal 6
  • MySQL version: 5.x
  • PHP version: 5.2
Re: REST API - How to add new email to a new contact
October 11, 2012, 01:12:03 am
sorry for the confusion, I'm using Civicrm 3.4 with Drupal 6.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: SOLVED! REST API - How to add new email to a new contact
October 11, 2012, 01:32:12 am
That makes more sense :-)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • SOLVED! REST API - How to add new email to a new contact

This forum was archived on 2017-11-26.