You are viewing limited content. For full access, please sign in.

Question

Question

Using Forms to Look-up Census Tract Data from census.gov API and JSON Values

asked on April 2, 2019

I'm trying to take an address in Forms and look-up the census tract data from the census.gov API.

I can get this to work by just putting the URL into a browser:

https://geocoding.geo.census.gov/geocoder/geographies/address?street=2687+West+7800+South&city=West+Jordan&state=UT&benchmark=Public_AR_Census2010&vintage=Census2010_Census2010&layers=14&format=json

This returns the values for my work address.

But I cannot get this to work via Javascript in LFForms: 

  $('#testbutton').click(function(){
    var url = new URL('https://geocoding.geo.census.gov/geocoder/geographies/address')
    var params = [['street', '2687+West+7800+South'], ['city', 'West+Jordan'], ['state', 'UT'], ['benchmark', 'Public_AR_Census2010'], ['vintage', 'Census2010_Census2010'], ['layers', '14'], ['format', 'json']]
    url.search = new URLSearchParams(params)
    fetch(url, {mode: "no-cors"})
      .then(function(response) {
        return response.json();
      })
      .then(function(myJson) {
        console.log(JSON.stringify(myJson));
      });
  });

This is what I get in the console when I click the "#testbutton":

Does anyone have any experience with this kind of stuff and could give me some guidance?

0 0

Replies

replied on October 6, 2020

Hi there.  Did you ever get guidance on this topic?  I'm interested in doing something with pulling data like that from the address fields.

 

Thanks,

Kevin

1 0
replied on October 7, 2020

Hello @████████

Unfortunately, I was never able to resolve the CORS/CORB issue in order to contact this API or any other API from within LFForms.  I probably spend 100+ hours researching, testing, tweaking, and never getting it to work.  Untimately, we pursued another avenue to deal with the census tract data we needed.

However, I more recently found a need to try to work with a couple other APIs, that of course had similar CORS/CORB issues, but were a much more pressing need.  Ultimately, I ended up building my own API (using C# in Visual Studio) and hosting that on the same server that runs LFForms.  LFForms passes information to/from my API, which in turn passes information to/from the third party API.  Because LFForms is communicating with an API on the same server that it is housed on, the CORS/CORB issue never arises.  It's a giant pain to set-up, and I'm limited to the specific items of the third-party API which I have already identified as needed for the LFForms process (because adding anything else means modifying my API to add it instead of just adding new calls in LFForms).

This isn't a small solution or one for someone without at least intermediate coding skills - but it works well if you can do it.

An easier solution - if you don't need the functionality available directly within LFForms, but could run in-between tasks - you might be able to do the API calls from within LFWorkflow and pass the resulting data back to LFForms.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.