4

I have a civi instance installed on WP and would like to access and display a contact's data on a different (non WP) site.

Tried to embed the whole civi page and pass the contact ID using this url format but since cross origin framing is not allowed it didn't work:

http://myserver/wordpress/wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fcontact%2Fview&cid=**XXX**

How can I fetch and display a contact's details on an external page?

5

The best way to do that is to make use of the CiviCRM REST API.

It can be used via PHP or via JavaScript.

With that method you collect the data you need, and then you can display it as you like.

Much more information can be found: https://wiki.civicrm.org/confluence/display/CRMDOC/REST+interface

  • 2
    I recommend not using the REST api from javascript in the browser (from a node.js is fine, the language isnt' the issue), it's a security issue to leave the api_key and keys visible to everyone. – Xavier Feb 12 '16 at 9:42
3

We are just working on a situation where a customer wants to send data from a Wordpress form on the website to CiviCRM on another site, check https://civicrm.org/blogs/erikhommel/passing-form-data-from-wordpress-to-civicrm

2

Using the REST API is probably a good venture when your instance wants to communicate with other servers and systems.

Very important things are to be taken into consideration

1) you have tried to use the API explorer on your civi instance on WP to fetch and display contacts in JSON, from which a request URL will be provide for performing the same operation through REST

2) The site key is replaced in the REST URL with the site key in the civicrm.settings.php probably in ".../wp-content/plugins/civicrm"

3) The security verification process is validated. This is done by ensuring that the current user who sends the request has an api_key to authenticate the request. you could verify this by searching the contact on your civi instance, getting the id, and then querrying you database with " select api_key from civicrm_contact where id='user_id;'

If the api_key is not there update the record with " update civicrm_contact set api_key='chosen_key' where id='user_id "

with all of this you should specify how you want the server to return the data probably in JSON ( by adding argument in URL &json=1 )

Finally you should have a URL that looks like this http://your-server/wordpress/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&id=203&api_key=XXXXXXXXX&key="XXXXXXXXXXXXXXXXXXXXXXXX"&json=1

The returned data should be useful you can now manipulate and display on the other server page.

You can find more at CiviCRM REST API.

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.