3

I'm trying to connect to the rest api from a remote server, and the only response I ever get back is:

var jsondata = {"currencySymbol":"$","is_error":true};

I'm able to make api calls from the site's API Explorer (within the same domain). But no matter what I do from my remote host, any calls to this site's rest.php always return that same generic response.

Is there something one must to do allow external access to the REST API? Or does this response hint at some other request filtering taking place?

  • Make sure you have your api_key for the admin user - If you are still getting issue let me know i will help you - thanks – Ramesh - ARTECH Consultancy Dec 19 '17 at 9:39
  • This site has CiviCRM integrated into WordPress. How can I make sure that my user account is an administrator? I do see the "Administer" menu when logged in. But also, shouldn't I get a more specific error message telling me what the problem is? – Troy Dec 19 '17 at 15:58
  • Ramesh, I'd love to take you up on your offer to help. Please reach out when you get a chance. – Troy Dec 19 '17 at 23:22
  • please try the below link by replacing yoursitename, apikey, sitekey against the browser and let me know what error are you getting - "yoursitename/wp-content/plugins/civicrm/civicrm/extern/…" – Ramesh - ARTECH Consultancy Dec 20 '17 at 9:07
  • ping me in chat.civicrm.org – Ramesh - ARTECH Consultancy Dec 20 '17 at 9:16
1

To get the rest API working, you need to call an url looking like that (this example to create a contact)

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"}

The specific path to rest.php depends on what CMS you use

A few pointers:

  • you need to set the key with the site key (from civicrm.settings.php)
  • you need to create an api key on the contact that peforms the operation, and
  • this contact needs to a user that has the appropriate permission (start with an admin account to rule out the permission issue)

This being said, your error message is not normal, you should get a "Failed to authenticate key" error message

https://civicrm.org/sites/all/modules/civicrm/extern/rest.php

it might be that you don't use the proper url to reach the rest.php file, or that something needs to be configured on your webserver so it's properly processed

What is the url you try? it's a different one from the ajax api used by the api explorer

X+

  • My url is something like this: example-domain.com/wp-content/plugins/civicrm/civicrm/extern/…{} – Troy Dec 19 '17 at 15:54
  • Of course I replace the placeholders in that url with the site key and the api key I created for my user account. I've done a previous integration and when I provide an incorrect site key or api key I get back a very specific error message. Until this is all working with my new client, I can't be sure I'm using the correct site key and api key ... but the fact that I'm getting this non-standard error message makes me think there's a bigger configuration issue going on. – Troy Dec 19 '17 at 15:56
  • agree with your analysis, you get a weird error message, that doesn't seem to come from civi. There is something else going on, either at the apache/nginx level or in wp. start debugging (big die ("I'm here") at the top of your rest.php to at least be sure you're talking to the right file – Xavier Dec 20 '17 at 6:15
  • That's an excellent idea, Xavier. I'll contact the hosting company to see if they can modify rest.php so that it should in theory return some other obvious error message. I'll keep you all posted. – Troy Dec 20 '17 at 17:37
0

I assume you have set your site key and api key correctly. This is something the REST will need and your API explorer will not. What API are you actually calling so I can do a test locally as well?

0

We tried turning off all plug-ins except for the CiviCRM plug-in. The rest.php endpoint began working perfectly. We were able to turn back on all plug-ins except for "Recent Tweets". I'm surprised something so benign sounding as "Recent Tweets" was the culprit!

(Thanks to Ramesh for helping me look at some things earlier today!)

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.