Avatar of João serras-pereira
João serras-pereira
Flag for Portugal asked on

web browser for rest interface

Hi,

I am using ms/access and need to invoke a REST interface. I have designed a form and, within, I  did put a web browser control and tested its source with a test string. It looks perfect.

Now I need to automate the function which means that at a click of a button I need to construct a string and this string will be used as the control source of the browser. How do I do it?

thanks in advance
Microsoft AccessREST

Avatar of undefined
Last Comment
João serras-pereira

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jim Dettman (EE MVE)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jim Dettman (EE MVE)

Dang new editor....could not add more text.

The above example shows an example of talking to Mapquest to get a geocode for an address.   You set a reference to the XLM lib, and it has the functions you can call to work with a REST interface.

Jim.
João serras-pereira

ASKER
Hi Jim!

´Thanks a lot for the reply.

The site is the nexmo site and I am using the line:

=https://rest.nexmo.com/sms/json?api_key=WWWW&api_secret=XXXX&from=YYYY&to=+XXXX&text=blablablabla"
   

(just replace the keys for confidentiality

How to I know about jason?
Jim Dettman (EE MVE)

Looking at the developer docs:

https://developer.nexmo.com/concepts/overview 

 you'll probably want to use the lib on Github.   But I have never worked with a JWT (Jason Web Token), which needs to be used for authentication and I don't think the lib handles that.

Jim. 
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
João serras-pereira

ASKER
Ok

I'll try first your direct approach. It it works, then I'll be happy as a clam
João serras-pereira

ASKER
'got a 1st problem:

Dim objRequest As New MSXML2.XMLHTTP

Screenshot-2020-03-04-at-16.20.50.png
can you help?
Bill Prew

You'll need to include a reference, as shown below.
sshot-163.png
»bp
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
João serras-pereira

ASKER
mmmh.. not yet

'got the same error

Screenshot-2020-03-04-at-16.37.00.png


I have no V4 but have a v3

shall I also adfd that one?
Jim Dettman (EE MVE)

<<I'll try first your direct approach. It it works, then I'll be happy as a clam >>

That was an example, not the actual code you will need.

Jim.
Bill Prew

You don't want version 6, use version 3 then.


»bp
Your help has saved me hundreds of hours of internet surfing.
fblack61
João serras-pereira

ASKER
Ok. I am on V3 and cleaned the example code.

It is progressing. Now I am getting  on the instruction " objRequest.Open "GET", strPostURL, False" a type mismatch err

Screenshot-2020-03-04-at-18.02.50.png
any ideas?
Bill Prew

Can you post the full code you are testing please.


»bp
João serras-pereira

ASKER
sure!
Option Compare Database

Public Function sendSMS(strTarget As String, strText As String) As Boolean

    Const RoutineName = "sendSMS"
    

    Dim strPostURL As String
    strPostURL = "=https://rest.nexmo.com/sms/json?api_key=ttt&api_secret=uuu&from=vvvto=xxx&text=estamos fritos e cozidos e comidos"

    Dim arrResponse

    On Error GoTo Error_Handler

    ' Default to false in case anything goes wrong.
    sendSMS = False
    ' We use xmlHTTP to submit the input values and record the response
    Dim objRequest As New MSXML2.XMLHTTP
    objRequest.Open "GET", strPostURL, False
    objRequest.Send
    ' The response string is broken into an array using the specified delimiting character
    arrResponse = Split(objRequest.responseText, "|", -1)
    sendSMS = True

Exit_Handler:
    On Error Resume Next
    Set objRequest = Nothing
    Exit Function

Error_Handler:
      MsgBox Err.Description, _
        "ERROR " & Err.Number

    Resume Exit_Handler

End Function

Open in new window



This is ther actual function invoked from a button
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Bill Prew

The error is actually occuring on the Send, not the Open.

It looks like you have a stray equal sign in:

strPostURL = "=https://rest.nexmo.com/sms/json?api_key=ttt&api_secret=uuu&from=vvvto=xxx&text=estamos fritos e cozidos e comidos"

removing that removed the error for me.

When I am debugging things like this I typically drop back to the default error handling of VBA, so that I see as much info as possible right at the spot it occurs.  So I commented out this line:

On Error GoTo Error_Handler

for testing and when I got the error it was a bit more obvious the exact line that was executing, even without breakpoints.  SO when I ran the code with the error in the URL string, it popped up this message box.
sshot-165.pngAnd then when I clicked Debug it took me right to the line of code and stopped there as if it was a breakpoint.  This give us the opportunity to inspect values, etc.
sshot-166.png
»bp
Jim Dettman (EE MVE)

and FYI, you need a POST operation, not a GET (I'm assuming your are trying to send):

https://developer.nexmo.com/messaging/sms/overview 

Jim.
João serras-pereira

ASKER
Yes, definitely.

I am willing to send a message and get a result to be stored in a text field in the DB. I just pasted the sample code you have provided in the beginning but without knowing anything about it. Cleaned a bit for by specific case. But I do not know anything about the POST and GET. Can you please point me to a doc on it?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Bill Prew

It's not perfect but this seems like one of the better overviews I could find, I'm sure you will know more after reading than before.  Hope it helps.



»bp
Bill Prew

Also, to Jim's point, are you trying to fetch information with this interaction, or send information?

And since the API is secure, if there is JSON returned that needs to be processed, you will need to share a sample of that here if we are to get more specific about how to process it.  If it is very simple you may be able to handle it with just string manipulations, pulling out the needed parts.  But if it is a bit more complex in nature you will need a JSON library to assist with that, like VBA-tools/VBA-JSON: JSON conversion and parsing for VBA


»bp
João serras-pereira

ASKER
Hi,
I am sorry, I had to stall.

Here is what I need:
1. send a message (as per the sample code)
2. store the result in a text field (NEXMOS sends back a simple text easy to parse

Nothing else...

kindest regards
joao
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Bill Prew

Okay, so I think you should have enough to do that at this point.  If not post specific errors / questions.


»bp
João serras-pereira

ASKER
Ok. I agree. Im am closing que question with a big thanks!
João serras-pereira

ASKER
Thanks for the help!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck