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) »
  • Rest API not returning contacts that user can view in GUI
Pages: [1]

Author Topic: Rest API not returning contacts that user can view in GUI  (Read 753 times)

naomi

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.5
Rest API not returning contacts that user can view in GUI
December 07, 2014, 06:50:38 am
Hi,

I have given the "Ajax API" permission to authenticated users.

I have two users, A and B, which have API keys.

User A has full administrative rights. Using A's API key I can get all contacts, as expected. So the API is working.

User B is merely an authenticated user and as such does NOT have the "View all contacts" permission in Drupal. But she is a member of a CiviCRM Group with an ACL configured (inside CiviCRM) allowing her to view contacts from another group. When I log on as user B in the GUI, I can view these contacts. But when I try to use the REST API with user B's API key, I get NO contacts.

Please can anyone advise on how to make these contacts available via the API like they are via the GUI?

Edit: In fact, B cannot even get her own contact from the API, despite authenticated users having the "CiviCRM: view my contact" permission.

Thank you,

Naomi



« Last Edit: December 07, 2014, 06:54:06 am by naomi »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Rest API not returning contacts that user can view in GUI
December 07, 2014, 07:43:08 am
Hmm, is it limited to the rest api? Can you try the ajax api? This is easy to test, just paste this code into your browser console:

Code: [Select]
CRM.api3('contact', 'get', {});
« Last Edit: December 07, 2014, 02:51:00 pm by Coleman Watts »
Try asking your question on the new CiviCRM help site.

naomi

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.5
Re: Rest API not returning contacts that user can view in GUI
December 07, 2014, 08:48:43 am
Thanks! That works. But the goal is to script it. Is there a way to script logging in and calling the Ajax API?

Edit: I used `CRM.api3` as `CRM.api` did not work.
« Last Edit: December 07, 2014, 10:03:16 am by naomi »

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 not returning contacts that user can view in GUI
December 07, 2014, 12:22:46 pm
what is the rest url you are trying (obviously without showing your keys??
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

naomi

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.5
Re: Rest API not returning contacts that user can view in GUI
December 08, 2014, 01:08:54 am
Hi Xavier,

/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&json={}&api_key=myapikey&key=mysitekey

When using the api key of a user with "View all contact" permissions, the URL returns the expected results, so I suspect  the URL is correct

Thanks

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 not returning contacts that user can view in GUI
December 08, 2014, 01:43:01 am
Hi,

you don't need the json= param, it's another way to pass params (when they are linked). can you try without and add debug=1 (probably not going to be useful but might give extra info)?

what's your civicrm version?
What's the result? count=0 and not values?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

naomi

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.5
Re: Rest API not returning contacts that user can view in GUI
December 08, 2014, 02:54:10 am
Hi Xavier, thanks for your reply.

I'm using the json parameter because I want the results in json rather than xml.

Civi version is 4.5.2

Here are the results in JSON and in XML:

Code: [Select]
{"is_error":0,"version":3,"count":0,"values":[]}
Code: [Select]
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" count="0"></ResultSet>

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Rest API not returning contacts that user can view in GUI

This forum was archived on 2017-11-26.