Help with API Data Imports - Updating Existing Fields

  • 0
  • 1
  • Question
  • Updated 2 months ago
  • In Progress
  • (Edited)
I work at a solar company, and I'm trying to utilize the API of the NREL's PVWatts tool (https://developer.nrel.gov/docs/solar/pvwatts/v6/). 

I have written a URL field that will create the HTML link with all of the inputs already entered. This uses other fields on the table that are filled out by the user. What I would like to do is utilize the data returned to update different fields on the same record.

An example report of what's being returned can be found here: https://developer.nrel.gov/api/pvwatts/v6.xml?api_key=DEMO_KEY&address=1600%20Ampitheater%20Park...

I would like the 12 numbers returned under the "ac-monthly" section of data to update 12 fields on the same record with those numbers.

Here is a glimpse of the page I'm working with:
https://drive.google.com/file/d/1kFFJEQGp_Fq0-wrsvWByCe7izyNPfP_U/view?usp=sharing

The goal is that the user will put in the array data, press the button, and the output of that array will be placed into the A1 Jan - A1 Dec fields.

Sorry if this concept is already on the forums somewhere, but I've been searching for a few hours and everything I find seems to related to using the Quickbase API, not having Quickbase use other APIs.

Update: The PVWatts API can return XML or JSON data, if one would be easier to accomplish this than the other.
Photo of Jacob Bailey

Jacob Bailey

  • 72 Points

Posted 2 months ago

  • 0
  • 1
Photo of John Rogers

John Rogers

  • 340 Points 250 badge 2x thumb
Are you trying to do this completely through Quickbase?

To my knowledge it is not possible. I also work for a Solar Company and have tons of running API integrations with our QuickBase CRM. I use Zapier as a middleman to manipulate the data. 

You can send as much data as you want from QuickBase, that is the easy part. Then you have to find something (your own server, or in my case Zapier) to take the response and POST it in the field_IDS you want into QuickBase since you cannot filter responses in QuickBase itself.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,402 Points 20k badge 2x thumb
I don't work for a solar company but QuickBase is so successful in this industry I have been thinking about starting my own solar company. QuickBase can easily handle this task without involving an external service.

Normally, one web site cannot access data from another web site because of a policy all browsers implement called the Same Origin Policy. However, the good folks over at National Renewable Energy Laboratory (NREL) have made their API work across domains by including a special header in their response that allows access from all domains:

      Access-Control-Allow-Origin: *

Because of this you can directly call this API from QuickBase without involving an intermediate server.

This is the essential code that will call the API and populate 12 fields with fids 6 through 17 with the ac-monthly values:
var url = "https://developer.nrel.gov/api/pvwatts/v6.xml";
url += "?api_key=DEMO_KEY";
url += "&address=1600 Ampitheater Parkway, Mountain View, California";
url += "&system_capacity=3.05";
url += "&azimuth=180";
url += "&tilt=18.43";
url += "&array_type=1";
url += "&module_type=1";
url += "&losses=11.72";
var fids = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17];
$.get(url, function(xml) {
  console.dirxml(xml);
  $("response outputs ac-monthly[type=array] ac-monthly[type=float]", xml).each(function(index) {
    console.log(`_fid_${fids[index]}`, $(this).text());
    $(`#_fid_${fids[index]}`).val($(this).text());
  });
});
You can run this code from the console on an add or edit form assuming you have specified your 12 fid values. A complete solution would involve implementing the IOL technique and the appropriate logic to assign the input parameters in the URL.

I am tied up at the moment starting my own solar company but if you need additional help with this task feel free to contact me off-world using the information in my profile:

https://getsatisfaction.com/people/dandiebolt
(Edited)
Photo of John Rogers

John Rogers

  • 340 Points 250 badge 2x thumb
Is Access-Control-Allow-Origin a type of substitution to a Bearer token?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,402 Points 20k badge 2x thumb
No. An Access-Control-Allow-Origin header is included in the response from the server indicating if the server will allow cross domain access,