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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • How to use Civi data to call external API, and return result to Civi?
Pages: [1]

Author Topic: How to use Civi data to call external API, and return result to Civi?  (Read 360 times)

coopersquare

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
    • Cooper Square Committee
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress 3.8
  • MySQL version: 5.1
  • PHP version: 5.3.3
How to use Civi data to call external API, and return result to Civi?
October 24, 2014, 02:34:31 pm
Hi, I'd like to know generally what path to go on.  I suspect it involves editing some templates or tokens, but not quite sure. Some of you with more programming experience must have a suggestion; I am still learning PHP.

We do tenant organizing. When viewing a Contact Dashboard, I would like to see information about their building. This is greatly facilitated if we translate their address into block/lot numbers as listed in a Building Database I will upload.  Here is an example of a workflow:

Say John Doe lives at 102 Norfolk St.
Pass the relevant houseNumber and street in "102 Norfolk St" to a NYC API (I would ideally want to take the parsed Street Number and Street Name from Civi's automatic parse fields)

the Request that would be passed to the API is this (this is XML, it can also do JSON format):

Code: [Select]
curl -v  -X GET "https://api.cityofnewyork.us/geoclient/v1/address.xml?houseNumber=102&street=norfolk&borough=Manhattan&app_id=3f88824d&app_key=f2a2b535bdc9cc8f9a5e1b589002531c"
Its Response includes this:

Code: [Select]
<geosupportResponse>
  <address>
        <bbl>1003530049</bbl>
     </address>
</geosupportResponse>

Then I want it to return the bbl value to Civi. (in this case, 1003530049)  That will be the External Identifier for Building that John Doe lives in (I am uploading the Building Database as a list of a new kind of sub-contact, Buildings.)  Ideally this returned value would be displayed as a Contact Reference on John Doe's dashboard, upon clicking would lead to the Building's contact dashboard.

Anyone have any suggestions for what direction I should go in to start this project?

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: How to use Civi data to call external API, and return result to Civi?
October 24, 2014, 03:20:58 pm
Hi there,

We've written some very similar code - for allied organizations of yours, in fact.  I haven't used that NYC API before though.

What you'll want to do is write an extension.  Check out this page: http://wiki.civicrm.org/confluence/display/CRMDOC/Create+an+Extension

Use the civicrm_post hook (http://wiki.civicrm.org/confluence/display/CRMDOC/Hook+Reference) and hook either addresses or contact records being saved (depends on your workflow).  Use API calls to get the fields you need and pass them to php_curl.  Parse the results that come back (you can probably get away with a search function instead of a full-blown XML interpreter) and use an API call to save the building number to a custom field.

This is probably a bit overwhelming if you haven't done it before - but once you've done it, you can knock out something like this in an hour or two.  If you'd like to come to Brooklyn one day next week, you're welcome to set up a laptop next to me and hack at this and ask me questions when you get stuck.

Jon
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

jaapjansma

  • I post frequently
  • ***
  • Posts: 247
  • Karma: 9
    • CiviCoop
  • CiviCRM version: 4.4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.4
Re: How to use Civi data to call external API, and return result to Civi?
October 28, 2014, 01:17:48 am
I did a similar job here in the Netherlands were the neighborhood data is looked up in an external database and stored into custom fields at address level. So that we know which neighborhood of the city the person is living in.

I made an extension for this which did a look up of the data in the Post hook of the address object and then store the data into the custom fields I had created for this purpose.
Developer at Edeveloper / CiviCoop

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • How to use Civi data to call external API, and return result to Civi?

This forum was archived on 2017-11-26.