function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vincent Drader 2Vincent Drader 2 

Salesforce & Google Civics Information API Integration

Hello all - a seasoned administrator here, but a novice developer. I am trying to set up a field in Salesforce on contact records that will give me the contact's local voting information based on their address. This seems possible with Google Civics Information API (https://developers.google.com/civic-information). However, I don't really know how to go about setting this up in Salesforce...

I have obtained an API key, and Google is very helpful in letting you test drive the API so that I know the following url: 

https://www.googleapis.com/civicinfo/v2/representatives?address=1200+C+Street+SE%2C+Washington%2C+DC+20003&includeOffices=false&key={YOUR_API_KEY}

gives me the following good results (see screen shot below):
Google Civics API sample results

I suppose my question is, where do I start at turning this into an apex code? And is that the best way to get the results I want?

Is there a developer willing to help an admin just beginning to learn coding? Any input is appreciated. Thank you!

 
Best Answer chosen by Vincent Drader 2
pconpcon
You will want to look at using callouts [1] [2] to make the call to the google API.  Then you'll want to parse the JSON [3] and the "do something" with it.  If you try to write this and you have any specific problems we will be more than happy to help you.

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts.htm
[2] https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts
[3] http://blog.deadlypenguin.com/blog/2015/11/30/json-deserialization-in-salesforce/

All Answers

pconpcon
You will want to look at using callouts [1] [2] to make the call to the google API.  Then you'll want to parse the JSON [3] and the "do something" with it.  If you try to write this and you have any specific problems we will be more than happy to help you.

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts.htm
[2] https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts
[3] http://blog.deadlypenguin.com/blog/2015/11/30/json-deserialization-in-salesforce/
This was selected as the best answer
Vincent Drader 2Vincent Drader 2
Thanks, pcon, for the resources. I will try my hand and get back.