API HELP

Forums: 

I'm trying to build a working URL string to call data with the API. I think I'm close but something is still wrong. Here's the URL I'm using.

https://developer.nrel.gov/api/solar/nsrdb_0512_download.csv?wkt=POINT({39.5%20-104.5})&names=1998&leap_day=false&email=xyz@hotmail.com&interval=30&utc=false&api_key=xyz&attributes=dhi,dni

Here's the message I'm getting:

{"errors":["Parameter wkt must be a valid geometry formatted as well known text."],"inputs":{"wkt":"POINT({39.5 -104.5})","names":[1998],"leap_day":false,"email":"xyz@hotmail.com","interval":30,"utc":false,"attributes":["dhi","dni"]}}

What changes do I need to make to the URL string to download this file?

Here is the basic code I'm using to download csv files with VBA. I wrapped this CODE in For Loops that scroll through a list of Lat/Long combinations for all the Solar Plants in the US. It's running slower than expected but it's running.

Option Explicit

Sub GET_NSRDB()

Dim Latitude As String
Dim Longitude As String
Dim Year_x As String
Dim API As String
Dim Attributes As String

Dim URL As String
Dim URL1 As String
Dim URL2 As String
Dim ARG As String
Dim oStream As Object

Longitude = 33.21
Latitude = -97.12
API = YOUR_API_KEY
Attributes = "attributes=air_temperature,dew_point,dhi,dni,ghi,wind_direction,wind_speed&leap_day=false&utc=false&interval=30"

For Year_x = 2000 to 2016

'Build URL
URL1 = "https://developer.nrel.gov/api/solar/nsrdb_psm3_download.csv?api_key=YOU...
URL2 = "wkt=POINT(" & Latitude & "+" & Longitude & ")&names=" & Year_x & "&" & Attributes

URL = URL1 + URL2

ARG = "C:\" & Latitude & "_" & Longitude & "_" & Year_x & ".csv" 'This is your Save Location and Filename

Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", URL, False, "username", "password"
WinHttpReq.send

URL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile ARG, 2 ' 1 = no overwrite, 2 = overwrite
oStream.Close
End If

Next Year_x

End Sub