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 (Moderator: Donald Lobo) »
  • Failed to Decode JSON [Solved:API Explorer Conflict]
Pages: [1]

Author Topic: Failed to Decode JSON [Solved:API Explorer Conflict]  (Read 716 times)

vmantese

  • I’m new here
  • *
  • Posts: 19
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Wordpress 4.1
  • MySQL version: 5.6.21
  • PHP version: 5.6.3
Failed to Decode JSON [Solved:API Explorer Conflict]
May 05, 2015, 06:40:40 pm
Hi all,
I realize I must be formatting something incorrectly but right now I'm at a loss at what.
I want to be able to directly copy/paste a RESTFUL url to access the civiCRM API.

Example.

myinstallroot/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&json=1&api_key=mysitekey&key=mykey returns the first 25 contacts in JSON format as intended.

However, as soon as I try to detail my JSON....

myinstallroot/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&json={"sequential"=1,"display_name":"TestCorp"}&api_key=mysitekey&key=mykey

I receive the error:

{"is_error":1,"0":"error_message","1":"Unable to decode supplied JSON."}

Any ideas how I'm misformatting it?

Thanks,
V
« Last Edit: May 05, 2015, 06:48:09 pm by vmantese »

vmantese

  • I’m new here
  • *
  • Posts: 19
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Wordpress 4.1
  • MySQL version: 5.6.21
  • PHP version: 5.6.3
Re: Failed to Decode JSON
May 05, 2015, 06:47:33 pm
Welp, I figured it out but for anyone else who was being led astray by the api explorer's example REST URLs like I was the proper notation is:


// For external services
http://www.example.com/sites/all/modules/civicrm/extern/rest.php
  ?api_key=t0ps3cr3t
  &key=an07h3rs3cr3t
  &json=1
  &debug=1
  &version=3
  &entity=Contact
  &action=get
  &first_name=Alice
  &last_name=Roberts


I guess that the API explorer's REST output is just out of date...

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Failed to Decode JSON [Solved:API Explorer Conflict]
May 05, 2015, 07:06:34 pm
Quote from: vmantese on May 05, 2015, 06:40:40 pm
myinstallroot/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&json={"sequential"=1,"display_name":"TestCorp"}&api_key=mysitekey&key=mykey

In the 'json' field, shouldn't the "=" be ":" ?

Also, if there's an "=" sign in the data, it would be need to be encoded as "%3D" (not as a literal equal sign).

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Failed to Decode JSON [Solved:API Explorer Conflict]

This forum was archived on 2017-11-26.