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) »
  • location API with REST
Pages: [1] 2

Author Topic: location API with REST  (Read 2162 times)

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
location API with REST
September 27, 2010, 08:18:02 am
The location API does not seem to work with the REST interface? When I call the core location API with
Code: [Select]
http://<mysite>/sites/all/modules/civicrm/extern/rest.php?q=civicrm/location/get&api_key=testapi&key=testkey&contact_id=1
I get XML parse errors?

When I make the call with json=1 I do get results:
Code: [Select]
http://<mysite>/sites/all/modules/civicrm/extern/rest.php?q=civicrm/location/get&api_key=testapi&key=testkey&contact_id=1&json=1
gets me:
Code: [Select]
[{"location_type_id":"2","phone":{"1":{"id":"2","contact_id":"1","location_type_id":"2","is_primary":"1","is_billing":"0","phone":"06 30 05 40 96","phone_type_id":"2"},"2":{"id":"48608","contact_id":"1","location_type_id":"2","is_billing":"0","phone":"0575-565347","phone_type_id":"1"}},"is_primary":true,"email":{"1":{"id":"3","contact_id":"1","location_type_id":"2","email":"hommel@ee-atwork.nl","is_primary":"1","is_billing":"0","on_hold":"0","is_bulkmail":"0"}}}
,{"location_type_id":"1","phone":{"1":{"id":"48607","contact_id":"1","location_type_id":"1","is_billing":"0","phone":"0575-562683","phone_type_id":"1"}},"email":{"1":{"id":"2","contact_id":"1","location_type_id":"1","email":"erik.hommel63@gmail.com","is_billing":"0","on_hold":"0","is_bulkmail":"0"}},"address":{"id":"57680","contact_id":"1","location_type_id":"1","is_primary":"1","is_billing":"0","street_address":"21 Ambachtstraat","street_number":"21","street_name":"Ambachtstraat","city":"Brummen","postal_code":"6971 BN","country_id":"1152","geo_code_1":"52.0876372","geo_code_2":"6.155052","display":"21 Ambachtstraat\n6971 BN Brummen\n","display_text":"21 Ambachtstraat\n6971 BN Brummen\n"}}]

We are already planning to check the location API in the UK code sprint, but perhaps someone already experienced this problem and found a solution?
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: location API with REST
September 27, 2010, 11:10:03 am
What's broken ? A 1000char long line is a bit hard to read ;)

(btw, adding a debug=1 that would add \n might be a something to add in the sprint

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: location API with REST
September 27, 2010, 01:50:29 pm
Xavier - I think you may need to think about permissions on the debug=1 option. Good idea but you may not want everyone to be able to see it
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: location API with REST
September 27, 2010, 02:14:06 pm
hi,

debug might not be the right  name. nice=1? the only thing was to get the json formatted, not to display more info
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: location API with REST
September 27, 2010, 10:15:15 pm
The json is not broken, the problem is that I get no results with XML?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: location API with REST
September 27, 2010, 11:24:51 pm
encoding problem, < > somewhere in the data is a common issue, as is accentuated chars.

Try wget the page, will be easier to analyse.

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

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: location API with REST
September 27, 2010, 11:50:26 pm
Will do that, location API is definitely in need of Angleterrian attention  :)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: location API with REST
September 28, 2010, 12:25:04 am
Hi,

Just flagging that Lobo suggested I try to refine our discussions into a standard for the API. I have been trying to write it onto the Wiki

http://wiki.civicrm.org/confluence/display/CRM/API+Conventions.

What I have written may not be entirely correct but you can hash it into something that you think is correct over a warm beer

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

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: location API with REST
September 28, 2010, 12:30:51 am
Looks decent at a glance, I will study in more detail before the warm beers arrive. Perhaps it would be good to have a to-do list of what will be left for the standardization of the API's after the UK code sprint.
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: location API with REST
September 28, 2010, 12:39:45 am
Yeah - so the bit that I'm trying to do now is the 'gap analysis - just noting down things I know of that need attention.

One thing that I can't quite figure out is what value 'update' functions add. To me an add function that will update is an ID is passed is more useful. Update to me makes sense potentially where the values passed in are NOT the id - ie. if you pass in first_name & last_name and it is a dedupe match which matches EXACTLY one contact (or similar for phone number, address bassed on location_type & phone_type) then it gets updated otherwise error=1 & error_message="x records match your query"
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

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: location API with REST
September 28, 2010, 12:44:31 am
Hmmm I must confess I would always expect an update function to work on a primary key, so the ID is required. If I would have the situation where I only have names I would use the get function first to work out what id I need.
If I try to step back and would be new to CiviCRM I would expect a get, create, update and delete as this sort of matches the CRUD? So I would suggest we will have an update, even if it is only to validate the id and the call the create with an ID?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: location API with REST
September 28, 2010, 12:49:10 am
I'm not anti-update ... as long as create does the same thing - the contact api currently has add, update & create. Add is deprecated but it allows you pass in an array and if contact_id is part of that array it adds otherwise it updates - create doesn't do this - making it much less useful to me
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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: location API with REST
September 28, 2010, 01:28:50 am
OK - I've finished jotting down all the 'gaps' I could think of off the top of my head. However, I think it would be most valuable for you guys to come up with a 'perfect' api (maybe butcher my pledge one into that sort of shape) rather than knocking off as many problems as possible. Also, coming up with as 'rigid' a specification / standard as you can. That way we have something to align the others with
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

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: location API with REST
September 28, 2010, 01:38:35 am
I agree with you, creating a create and update would mean more work for me too. But I think that if I were new to this, I would expect a CRUD set of API's? So in that situation I would be confused by having an add to create and update, and I would be comforted by seeing create and update as separate things.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: location API with REST
September 28, 2010, 01:39:38 am
That is a nice one for Bristol, to create the 'as perfect as can be' API with rigid standards and take it from there.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • location API with REST

This forum was archived on 2017-11-26.