0

I'm new to CiviCRM and REST API Calls. I'm attempting to create a new contact using POST via Postman. I'm submitting the following:

http://www.mysite.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=create&api_key=(myAPIkey)&key=(mySiteKey)&json:{“contact_type":"Individual","first_name":"Tester","last_name":"Yolanda"}

But I get the response back:

     <br />
    <b>Warning</b>:  Invalid argument supplied for foreach() in
<b>/wp-content/plugins/civicrm/civicrm/CRM/Utils/REST.php</b> on line
<b>167</b>
<br />
<?xml version="1.0"?>
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
      </ResultSet>

I glanced at line 167 - it seems to be about constructing the response. I know I'm getting some kind of connection - If I change a character in the site or API key, I get "failed to authenticate" - so that part seems to be working.

CiviCRM version 4.7.27, Wordpress version 4.9.1

Thanks for any pointers!

  • 1
    Hi SteadH. The ':' after the json argument, Is it a typo? it should be a '='. – Kainuk - CiviCooP Dec 15 '17 at 7:26
  • Thanks! It does seem to be. I started with the correct syntax but when I received a JSON error back even though it was valid, I started experimenting! – SteadH Dec 22 '17 at 5:36
3

As kainuk mentioned, you don't have the right syntax for the json field, i needs to be json= instead of json:

http://www.mysite.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=create&api_key=(myAPIkey)&key=(mySiteKey)&json={“contact_type":"Individual","first_name":"Tester","last_name":"Yolanda"}

(it needs to be post, not get for all operations like create that modify the database)

and I would strongly recommend you to do rest over an encrypted connection (https instead of http), otherwise you risk having your keys being read by someone else than civi

X+

0

I tried the same but not with Postman but with a different application outside civicrm - I managed to create a contact without any error message

so, Please try as below this should work

http://www.mysite.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=create&api_key=(myAPIkey)&key=(mySiteKey)&json=1&contact_type='Individual'&first_name='Tester'&last_name='Yolanda'

I guess this helps !!!

  • What other program and parameters did you use? – SteadH Dec 15 '17 at 14:37
  • I am trying to access this link from VB.NET web_request which worked alright also I did tried using POSTMAN too – Ramesh - ARTECH Consultancy Dec 18 '17 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.