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) »
  • Using the Rest interface
Pages: [1]

Author Topic: Using the Rest interface  (Read 5996 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Using the Rest interface
October 17, 2008, 08:16:35 am
Hi,

On 2.1, I'm trying to use the rest interface.

I can authenticate and get a key
http://www.example.org/path/to/civi/codebase/civicrm/extern/rest.php?q=civicrm/login&name=user&pass=password

But on the second step, I get an error message:
[error_message] => session keys do not match, please re-auth

http://www.example.org/path/to/civi/codebase/civicrm/extern/rest.php?q=civicrm/contact/search&key=62c1b4c363d4f8b9815d9d573f4b6100552a7ad6&return.first_name=1&return.email=1

That doesn't work from a php client (using simplexml_load_file) but does from the browser.

I assume that's because the session is empty on the second call. What is the proper way ? shall I use curl to go through that ?

(I'm using that "documentation" btw http://civicrm.org/node/412 )
 





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

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using the Rest interface
October 17, 2008, 09:28:40 am

u should use something like curl and maintain cookie state between various calls. curl has options to basically store/retrieve session keys

lobo


A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using the Rest interface
October 17, 2008, 12:48:09 pm
Hi,

Yes, where I ended up indeed.

Any specific reason not to return the session ID, and allowing it to be sent as a get param instead of a cookie ? Would make it easier and more readable on the client front.

Also is it possible to have a json return instead of a ResultSet tag ?

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

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using the Rest interface
October 17, 2008, 01:35:53 pm

patches to do both of the above would be gladly accepted. Please file an issue and attach the patch to the issue

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using the Rest interface
October 17, 2008, 10:32:18 pm
Ok, it seems that the only extra param is PHPSESSID

Suggested change on the API:

1) It can either accept a couple PHPSESSID+key or the login+pwd
Rationale: when you have only one list of contact to grab, no need to have to requests (login+contact/search)
The session ID is better otherwise.
(the password still is in clear on the wire, as an evolution, offer an api with challenge/response ?)

2) Return a constant error_id on the top of is_error=1 and the error message.
Rationale: easier to parse and act differently (eg if the error if session expired, then reauthenticate

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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using the Rest interface
October 17, 2008, 11:39:53 pm
The json interface works (add json=1 in the query)
You don't need cookie anymore to use the rest interface (add PHPSESSID=<value returned by the login> in the query)
http://issues.civicrm.org/jira/browse/CRM-3726
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Using the Rest interface

This forum was archived on 2017-11-26.