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 REST API // Problems
Pages: [1]

Author Topic: Using REST API // Problems  (Read 1594 times)

DylanRao

  • I’m new here
  • *
  • Posts: 10
  • Karma: 0
Using REST API // Problems
April 12, 2011, 06:46:26 am
This is really frustrating for me as I have followed the instructions to the letter, but again nothing works as it is supposed to... All I want to do is configure civicrm to allow access to admin user through REST API.

I have read both:
           a) http://en.flossmanuals.net/civicrm/ch066_api
           b) http://wiki.civicrm.org/confluence/display/CRMDOC33/REST+interface

Steps followed:
           a) Configured Site_Key in civicrm.settings.php
           b) Uncommented out lines in civicrm/CRM/Utils/REST.php
           c) Went to address: http://ip-address/sites/all/modules/civicrm/extern/rest.php?q=civicrm/login&name=<user>&pass=<pass>&key=<site_key>&json=1
           d) Returned:
               {"is_error":0,"api_key":"<api_key>","PHPSESSID":"<phpsessid>","key":"<key>"}
           e) Went to address when not logged in: http://ip-address/civicrm/ajax/rest?fnName=civicrm/contact/search&json=1&key=<key>&PHPSESSID=<phpsessid>

All i get is access denied, I have also checked the civicrm_contact field and it shows my api_key (specified in civicrm.settings.php) for the <user> inside the table.

Can someone please tell me what I am doing wrong?

Thank you for your time, greatly appreciated ^_^
« Last Edit: April 12, 2011, 09:14:32 am by DylanRao »

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: Using REST API // Problems
April 12, 2011, 10:55:51 am
Hi,
do you have clean URL's enabled? If not, the call should be:
Code: [Select]
http://www.yoursite.org/?q=civicrm/ajax/rest&fnName=civicrm/contact/get&json=1&key=<sitekey>&PHPSESSID=<phpsessid>
Although I would expect your login not working if you did it that way. I have changed your call to the following:
Code: [Select]
http://localhost/sandbox/?q=civicrm/ajax/rest&fnName=civicrm/contact/search&json=1&key=and it works on my sandbox (using Drupal 6.20, CiviCRM 3.3.5, using both Firefox and Chromium).
I am confused what you mean when you say:
Quote
it shows my api_key (specified in civicrm.settings.php) for the <user> inside the table
As far as I know you have to set the api_key in the database table, it does not come from your civicrm.settings.php?
« Last Edit: April 12, 2011, 11:27:20 am by Erik Hommel »
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

DylanRao

  • I’m new here
  • *
  • Posts: 10
  • Karma: 0
Re: Using REST API // Problems
April 12, 2011, 11:34:10 am
Hi, thank you very much for your reply. I do have clean urls enabled. The links you send unfortunately did not work on any browser... I was wondering if this is a problem since I generated a new phpsessid / key for a user that already had api access previously.... I am also confused about which key to use in the path? My <site_key> defined in civicrm.settings.php or the <key> returned from the response when registering (/login/civicrm) a user for api access?

Response
{"is_error":0,"api_key":"<api_key>","PHPSESSID":"<phpsessid>","key":"<key>"}

Path to enter in browser( which key should be used? <api_key> or <key>??)
http://www.yoursite.org/?q=civicrm/ajax/rest&fnName=civicrm/contact/get&json=1&key=<WHICH KEY?>&PHPSESSID=<phpsessid>

P.S. The api_key for my user in civicrm_contact refers to api_key defined in civicrm.settings.php is this right?

Thanks again for any help as this is extremely weird why doesn't work...

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 REST API // Problems
April 12, 2011, 11:40:54 am
Could you try the way we described in the book and tell me if it worked ?

http://en.flossmanuals.net/CiviCRM/DevelopAPI

It returns a session id. You can then use any API adding the extra param PHPSESSID = the value returned by the log-in call.

For example:

http://www.example.org/civicrm/ajax/rest?fnName=civicrm/contact/search&json=1&key=
yoursitekey&PHPSESSID=4984783cb5ca0d51a622ff35fb32b590


-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: Using REST API // Problems
April 12, 2011, 11:44:47 am
Use the site key from the civicrm.settings.php as &key=<site_key>

Use either the PHPSESSID returned once you are logged in, or the api_key. The api_key has to be set for the specific user you are loggin in with, and you need to set it directly in the civicrm_contact table using phpmyadmin (or another tool to get to the table), it does NOT refer to the key you set in civicrm.settings.php!

Hope this helps.....there is nothing wrong with the call in itself, they work on my machine. Something is not right in your setup, and I have suspicions about the api_key :-). As Xavier just mentioned, follow the instruction from the manual? And Xavier, I am correct in thinking that the user HAS to have an api_key even if you use the PHPSESSID, am I not?
« Last Edit: April 12, 2011, 11:46:58 am by Erik Hommel »
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: Using REST API // Problems
April 12, 2011, 11:53:27 am
Quote from: Erik Hommel on April 12, 2011, 11:44:47 am
I am correct in thinking that the user HAS to have an api_key even if you use the PHPSESSID, am I not?

Pretty sure you can't login if you don't have a key.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

DylanRao

  • I’m new here
  • *
  • Posts: 10
  • Karma: 0
Re: Using REST API // Problems
April 12, 2011, 02:07:22 pm
You guys are awesome, I really appreciate your help, the problem was I was confused about site_key in civicrm.settings.php and api_key in the returned response... In addition to this varnish had to be bypassed in order to not get the access denied error.

Again great community and I really appreciate the effort!

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

This forum was archived on 2017-11-26.