Forum Discussion

  • Use this code with your API KEY:
    var url = "https://developer.nrel.gov/api/alt-fuel-stations/v1.json";
    var options = {
      fuel_type: "E85,ELEC",
      state: "CA",
      limit: "2",
      api_key: "MY KEY",
      format: "JSON"
    }
    $.get(url, options).then(function(resp) {
      console.log(JSON.stringify(resp, null, "  "));
    });

    The response will look like this:
    {
      "station_locator_url": "http://www.afdc.energy.gov/afdc/locator/stations/";,
      "total_results": 4731,
      "station_counts": {
        "total": 16526,
        "fuels": {
          "E85": {
            "total": 156
          },
          "ELEC": {
            "total": 16370,
            "stations": {
              "total": 4575
            }
          },
          "HY": {
            "total": 0
          },
          "LNG": {
            "total": 0
          },
          "BD": {
            "total": 0
          },
          "CNG": {
            "total": 0
          },
          "LPG": {
            "total": 0
          }
        }
      },
      "fuel_stations": [
        {
          "access_days_time": "24 hours daily; pay lot",
          "cards_accepted": null,
          "date_last_confirmed": "2017-05-04",
          "expected_date": null,
          "fuel_type_code": "ELEC",
          "id": 1495,
          "groups_with_access_code": "Public",
          "open_date": "1995-08-30",
          "owner_type_code": "P",
          "status_code": "E",
          "station_name": "Sacramento County Public Garage",
          "station_phone": "916-874-6227",
          "updated_at": "2017-05-04T13:14:52Z",
          "geocode_status": "GPS",
          "latitude": 38.58431244,
          "longitude": -121.4956055,
          "city": "Sacramento",
          "intersection_directions": "7th St & G St",
          "plus4": null,
          "state": "CA",
          "street_address": "725 7th St",
          "zip": "95814",
          "bd_blends": null,
          "e85_blender_pump": null,
          "ev_connector_types": null,
          "ev_dc_fast_num": null,
          "ev_level1_evse_num": null,
          "ev_level2_evse_num": null,
          "ev_network": null,
          "ev_network_web": null,
          "ev_other_evse": "1 SP Inductive",
          "hy_status_link": null,
          "lpg_primary": null,
          "ng_fill_type_code": null,
          "ng_psi": null,
          "ng_vehicle_class": null
        },
        {
          "access_days_time": null,
          "cards_accepted": null,
          "date_last_confirmed": "2016-10-04",
          "expected_date": null,
          "fuel_type_code": "ELEC",
          "id": 1517,
          "groups_with_access_code": "Private - Government only",
          "open_date": "1999-10-15",
          "owner_type_code": "LG",
          "status_code": "E",
          "station_name": "LADWP - Truesdale Center",
          "station_phone": null,
          "updated_at": "2017-11-27T21:20:16Z",
          "geocode_status": "200-8",
          "latitude": 34.2491037,
          "longitude": -118.3875613,
          "city": "Sun Valley",
          "intersection_directions": null,
          "plus4": null,
          "state": "CA",
          "street_address": "11791 Truesdale St",
          "zip": "91352",
          "bd_blends": null,
          "e85_blender_pump": null,
          "ev_connector_types": [
            "J1772"
          ],
          "ev_dc_fast_num": null,
          "ev_level1_evse_num": null,
          "ev_level2_evse_num": 4,
          "ev_network": null,
          "ev_network_web": null,
          "ev_other_evse": null,
          "hy_status_link": null,
          "lpg_primary": null,
          "ng_fill_type_code": null,
          "ng_psi": null,
          "ng_vehicle_class": null
        }
      ]
    }
  • Nice but what if I want to put a value from a quickbase field in the URL like [tilt]. Could i do
    var options = {
      fuel_type: [fuel],
      state: [state],
      limit: [limits],
      api_key: "MY KEY",
      format: "JSON"
    }
  • Then you use the IOL technique with this formula text filed:

    [iol] & "module.js" & [/iol]
    &
    "<a class='QBU_Button Vibrant Success' " &
    "  data-state='" & [state] & "'" &
    "  data-limit='" & [limit] & "'" &
    ">Button</a>"

    and this module.js code page:

    (function(){
      var dbid = "application dbid";
      var dbidTable = "table dbid";
      var apptoken = "app token";
      $.ajaxSetup({data: {apptoken: apptoken}});
      $("a.QBU_Button").on("click", function(event) {
        console.log("onclick in module.js");
        var state = this.dataset.state;
        var limit = this.dataset.limit;
        console.log("state: ", state);
        console.log("limit: ", limit);
        var url = "https://developer.nrel.gov/api/alt-fuel-stations/v1.json";
        var options = {
          fuel_type: "E85,ELEC",
          state: state,
          limit: limit,
          api_key: "MY KEY",
          format: "JSON"
        }
        
        $.get(url, options).then(function(resp) {
          console.log(JSON.stringify(resp, null, "  "));
        });
      });
    })();

    Notes:

    (1) [state] and [limits] are passed to the script module.js as data attributes and read in the script using the dataset property.
  • Very nice! thanks for your help but now im getting this error 
    This table does not contain a field called iol. To see available fields, click the Fields & Function dropdown to the right of the formula box.
  • The IOL Technique (Image On Load) is one of several techniques used to inject JavaScript into QuickBase pages. It is use as a workaround on Class C planets such as Earth where convergence of script and QuickBase have not yet occurred. Other techniques used to inject JavaScript into the pages include BOL (Branding On Load), SW (Service Worker), OEH (On Error HTML), US (User Script).

    The IOL Technique is described here:

    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=294

    The Pastie Database contains hundreds of examples of using IOL:

    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=td