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 ??
Pages: [1]

Author Topic: Rest API ??  (Read 612 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Rest API ??
May 25, 2014, 04:35:53 pm
I have just been trying to use the REST interface (which I don't normally do) & am not seeing what the documentation suggests I should. (I am working on a 4.5 sandbox & the filter below is the subject of an open PR)

Using this
http://civi45/sites/all/modules/civicrm/extern/rest.php?&entity=Contact&key=QAXw6JAlOx4YAoqE&api_key=api&action=get&json={%22sequential%22:1,%22return%22:%22modified_date%22,%22modified_date%22:{%22%3E=%22:%22yesterday%22}}

I get {"error_message":"Unknown function invocation.","is_error":1}

This is because in CRM_Utils_Rest the values of $requestParams['q'] &  $requestParams['r'] are not useful - ie

args is the contents of the q field in the request object - it is
      Array
(
   
  • => node
  • [1] => 1
    )
    & here are the request params
    Array
    (
       
[entity] => Contact
    [key] => QAXw6JAlOx4YAoqE
    [api_key] => api
    [action] => get
    [json] => {"sequential":1,"return":"modified_date","modified_date":{">=":"yesterday"}}
    [q] => node/1
)
{"error_message":"Unknown function invocation.","is_error":1}


I can make it work by adding &fnName=civicrm/contact/get to the URL - but the documentation doesn't suggest that should be required....
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

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Rest API ??
May 25, 2014, 05:38:04 pm
Normally with rest.php I'd put entity & action as GET params, and put the rest as POST.

This conceals the API keys from being recorded to webserver logs by default, and still gives you a bit of visibility to what the request was doing there.

Pretty sure CRM_Utils_REST checks $_REQUEST for everything.

Drupal is probably why you're seeing $_GET['q'] == 'node/1'? Are you using devel PHP on node/1 or something? If you were in civicrm/ajax/rest you might get that as an array there instead. I wouldn't expect to see it in a hit on extern/rest.php though unless it was actually submitted.

EDIT: Probably, Drupal got bootstrapped and set $_GET['q'] because no $_GET['q'] was detected, so you're seeing the site default front page there.

Bit hard to read the code snippets below so forgive if I missed something there.
« Last Edit: May 25, 2014, 06:01:35 pm by Chris Burgess »
@xurizaemon ● www.fuzion.co.nz

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Rest API ??
May 25, 2014, 06:00:13 pm
Doesn't the json parameter also get used to signify the result format from the API? Submitting query parameters via that value doesn't seem to be documented.
@xurizaemon ● www.fuzion.co.nz

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 ??
May 25, 2014, 11:02:22 pm
Quote from: Eileen on May 25, 2014, 04:35:53 pm
I have just been trying to use the REST interface (which I don't normally do) & am not seeing what the documentation suggests I should. (I am working on a 4.5 sandbox & the filter below is the subject of an open PR)

There is a PR to fix the q  param issue, (Bjorn tested my code and did it if I recall, can't find it right now anymore).


-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: Rest API ??
May 26, 2014, 12:06:41 am
No - I can't find it either...
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 ??
May 26, 2014, 12:27:41 am
https://issues.civicrm.org/jira/browse/CRM-14506

putting json=json_encode ($params) definitely works, but you should put it in post (at least mandatory if you have any create/delete action in the chain)

I *think* you can still perform get chain on http get, but it's not recommended past the testing stage

X+
-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: Rest API ??
May 26, 2014, 12:36:05 am
OK - that's not in 4.5 yet - looks like it's waiting to be merged in from 4.4

https://github.com/civicrm/civicrm-core/blob/4.4/CRM/Utils/REST.php#L252

https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/REST.php#L280
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

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

This forum was archived on 2017-11-26.