Civic API Civic API

Migration from Old Civic API to New Civic API

The Civic API provides access to government representatives and division-related data. The old API endpoint used representatives?address= to fetch data, whereas the new API endpoint requires divisionsByAddress?address= for better and updated results. This document details the migration process from the old Civic API to the new Civic API due to the expiration of the old API in April.

Changes in API Endpoint

Old API Format:

“url”: “https://content-civicinfo.googleapis.com/civicinfo/v2/representatives?address=” + address_string + “&alt=json&key={key}&includeOffices=false”

New API Format:

“url”: “https://www.googleapis.com/civicinfo/v2/divisionsByAddress?address=” + address_string + “&alt=json&key={key}&includeOffices=false”

Key Differences

FeatureOld API EndpointNew API Endpoint
Base URLhttps://content-civicinfo.googleapis.com/civicinfo/v2/https://www.googleapis.com/civicinfo/v2/
Endpoint/representatives?address=/divisionsByAddress?address=
PurposeFetches representatives based on addressFetches electoral divisions based on address
API ExpiryExpires in AprilLatest version, recommended for future use

Migration Steps

  1. Update API Endpoint: Replace /representatives?address= with /divisionsByAddress?address= in all occurrences.
  2. Modify Request Handling: Ensure that the response handling is adjusted according to the data structure returned by the new API.
  3. Test API Response: Validate the output of the new API to check if it meets the application’s requirements.
  4. Deploy and Monitor: Deploy the updated code and monitor for any issues.

Example Code Before and After Migration

Old Code (Before Migration)

const address_string = "1600 Amphitheatre Parkway, Mountain View, CA";

const url = "https://content-civicinfo.googleapis.com/civicinfo/v2/representatives?address=" + address_string + "&alt=json&key=YOUR_API_KEY&includeOffices=false";

fetch(url)

  .then(response => response.json())

  .then(data => console.log(data));

New Code (After Migration)

const address_string = "1600 Amphitheatre Parkway, Mountain View, CA";

const url = "https://www.googleapis.com/civicinfo/v2/divisionsByAddress?address=" + address_string + "&alt=json&key=YOUR_API_KEY&includeOffices=false";

fetch(url)

  .then(response => response.json())

  .then(data => console.log(data));

Expected Response Differences

  • The new API returns electoral divisions rather than direct representative data.
  • The response format may vary slightly; ensure that JSON parsing is updated accordingly.

Conclusion

The migration to the new API ensures continued functionality and access to up-to-date government data. All implementations must be updated before the expiration of the old API in April to avoid service disruptions.

Recent Blogs


Posted

in

by

Tags:

To Know Us Better

Browse through our work.

Explore The Technology Used

Learn about the cutting-edge technology and techniques we use to create innovative software solutions.