0
votes

I'm trying to use the new Rest features in LotusScript (Notes Client Release 10.0.1) to retrieve address information from Google. Unfortunately, I get an error when trying to get a response. If I try the same url in the browser, I get no errors. There is no proxy configured.

Here's some sample code

Dim Session As New NotesSession        
Dim ret As String
Dim URL As String
Dim headers As Variant
Dim webRequest As NotesHTTPRequest
Set webRequest = session.createhttprequest()

url = "https://maps.googleapis.com/maps/api/geocode/json?address=Antwerp&<my Google API key>"

ret  = webrequest.Get(URL)

When I run this code in an agent, I get the following error on the last line:

Type mismatch in method CoerceString: Unknown found, Unknown expected

2
Strange: the code works for me here.. but documentation sais, that return value should be a variant: Return value Variant Returns Variant content which contains JSON string.Torsten Link
Hi Torsten. Using a Variant works. However, it does not return a JSON string, but a byte array. Converting the array to a string gives me the JSON I require. ThanksTom Van Aken

2 Answers

3
votes

The documentation for that command states:

Return value
Variant

Returns Variant content which contains JSON string.

And the error message that you get is typical for getting a variant and trying to cast it to a string.

The strange thing: With some websites it seams to work (probably depending of the type of data the website returns) with

Dim ret as String

Although the documentation is wrong in stating that the variant contains a JSON string (indeed it simply contains whatever the called website returns, that might be a JSON string, but can simply be the source code of the website as well), it still is right, that one should expect a variant as return value.

So this line should work:

Dim ret as Variant
0
votes

I'm a little late to the party here but I thought I would add that the simple solution is to set:

webRequest.Preferstrings = True

Then you will get a string back from the call ;-)