Discussions

 View Only
  • 1.  Get data from external source and save to record. Standardizing Addresses

    Posted 05-24-2017 16:34
    I'm new to learning how api's working so forgive me if i am missing something completely obvious.
    I would like to setup a button within the page on one of my tables, that when i click on it while editing a record, it can make a request from and external source, and then put the returned data in appropriate field in quickbase.
    More specifically what i'm trying to do is when i setup a new customer after I enter their address, I would like to query the USPS api for address standardization, take the returned data from USPS and put is into new custom address fields.

    The first part i can't figure out is how to i make the request.   The request goes to something along the lines of: https://servername/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest">https://servername/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest">https://servername/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="username">.......</AddressValidateRequest>.  
    I know how to populate the data for that line, but i can't figure out how do i actually make the request.   
    The second part is the response if formated in xml.  Where is that response stored? in a Variable? How to i extract the data from that to fit into my fields.

    The google addresses from quickbase are unfortunately not standardized, that is why am doing this.   Any help or pointers to the right direction are much appreciated.


  • 2.  RE: Get data from external source and save to record. Standardizing Addresses



  • 3.  RE: Get data from external source and save to record. Standardizing Addresses

    Posted 06-02-2017 20:02
    You have to obtain a key from USPS and reference their docs:

    https://www.usps.com/business/web-tools-apis/general-api-developer-guide.pdf

    Here is the relevant code applied from the console that used the second example on page 16 as a test case.


    //Emulate Filling In Address2, City, State and Zip5 fields
    _fid_7.value = "8 Wildwood Drive";
    _fid_8.value = "Old Lyme";
    _fid_9.value = "CT";
    _fid_10.value = "06371";
    //Form the URL using HTTP (HTTPS not Allowed)
    var url = '';
    url += 'http://production.shippingapis.com/ShippingAPITest.dll?API=Verify';
    url += '&XML=<AddressValidateRequest USERID="416NETEL6870">';
    url += '<Address ID="1">';
    url += '<Address1></Address1>';
    url += '<Address2>' + _fid_7.value + '</Address2>';
    url += '<City>' + _fid_8.value + '</City>';
    url += '<State>' + _fid_9.value + '</State>';
    url += '<Zip5>' + _fid_10.value + '</Zip5>';
    url += '<Zip4>' + _fid_11.value + '</Zip4>';
    url += '</Address>';
    url += '</AddressValidateRequest>';
    //jQuery to Fill in Zip4 field from server XML response
    $.get(url)
      .then(function(xml) {
        console.dirxml(xml);
        var Address2 = $("Address2", xml).text();
        var City = $("City", xml).text();
        var State = $("State", xml).text();
        var Zip5 = $("Zip5", xml).text();
        var Zip4 = $("Zip4", xml).text();
        _fid_11.value = Zip4;
      });

    See the annotated screenshot of applying these commands from the console:



    Note that the USPS API does not support https so you will have to click on the shield that appears to the right of the address bar to allow mixed content (https and http on same page).