Inserting code of other languages in vba procedure (1 Viewer)

irade92

Registered User.
Local time
Today, 14:06
Joined
Dec 26, 2010
Messages
228
Hi
I have a question. can I insert code of other languages in VBA procedure?
like this in HTTP:

POST /api/Auth/GetToken HTTP/1.1
Host: api.fzo.org.mk
Content-Length: 101

<LogIn>
<UserName>farmacevt@fzo.org.mk</UserName>
<Password>P@ssw0rd</Password>
</LogIn>

or like this in Java-Okhttp:

OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "<LogIn>\r\n <UserName>izbran_lekar@fzo.org.mk</UserName>\r\n <Password>P@ssw0rd</Password>\r\n</LogIn>\r\n");
Request request = new Request.Builder()
.url("http://api.fzo.org.mk/api/Auth/GetToken")
.method("POST", body)
.build();
Response response = client.newCall(request).execute();

BECAUSE i HAVE A PROBLEM DOING IT IN VBA
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:06
Joined
Jul 9, 2003
Messages
16,244
BECAUSE i HAVE A PROBLEM DOING IT IN VBA

I'm having difficulty grasping your problem, and what you mean.

Could you post an example of the VBA you are having problems with?
 

irade92

Registered User.
Local time
Today, 14:06
Joined
Dec 26, 2010
Messages
228
I need to get a token using this location and Username and password
curl --location --request POST 'http://api.fzo.org.mk/api/Auth/GetToken' \
--data-raw '<LogIn>
<UserName>farmacevt@fzo.org.mk</UserName>
<Password>P@ssw0rd</Password>
</LogIn>
'
I have tried a lot of combination like ie

Sxml = "<LogIn><UserName>farmaceft@fzo.org.mk</UserName><Password>P@ssw0rd</Password></LogIn>"
req.Open "POST", "http://api.fzo.org.mk/api/Auth/GetToken?" & Sxml, False
req.send

but with no success and get error No 12029


I have examples of the solution in other code languages so I thought I could use some of them inserting as a code in my VBA procedure..
I hope I am more clear now
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:06
Joined
Oct 29, 2018
Messages
21,357
Simply inserting other languages code into a VBA procedure won't work. You'll have to use a separate compiler/interpreter for that language. Have you checked the API documentation? Can you post a link to it?
 

irade92

Registered User.
Local time
Today, 14:06
Joined
Dec 26, 2010
Messages
228
Simply inserting other languages code into a VBA procedure won't work. You'll have to use a separate compiler/interpreter for that language. Have you checked the API documentation? Can you post a link to it?
Please read my reply to UncleGizmo..Thanks
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:06
Joined
Jul 9, 2003
Messages
16,244
I could use some of them inserting as a code in my VBA procedure..

Yes I see what you mean now. I'm assuming that the API provider has given you some examples in various languages. Unfortunately they seldom give VBA examples. However if there's a VB or vb.net example, sometimes these will give you enough information to be able to shoehorn it into VBA.
 

irade92

Registered User.
Local time
Today, 14:06
Joined
Dec 26, 2010
Messages
228
i can give examples of other languages if it helps, like cURL, Java-Okhttp, Java-Unirest, JavaScrip Fetch, JavaScript Jquery, php, Python and so on
Yes I see what you mean now. I'm assuming that the API provider has given you some examples in various languages. Unfortunately they seldom give VBA examples. However if there's a VB or vb.net example, sometimes these will give you enough information to be able to shoehorn it into VBA.
Ok..now let's find a solution...http is correct, and Username and pass are corect so method is "POST" and user and pass are body...
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:06
Joined
Feb 28, 2001
Messages
26,996
Sxml = "<LogIn><UserName>farmaceft@fzo.org.mk</UserName><Password>P@ssw0rd</Password></LogIn>"
req.Open "POST", "http://api.fzo.org.mk/api/Auth/GetToken?" & Sxml, False
req.send

When I look up that error it comes back as a problem with the network and a possible setting or registry error. I doubt that to be true, so what REALLY must be happening is that internally, your request is being interpreted by the VBA parser when you didn't want it to be. As a suggestion, change this line by adding a layer of quotes.

Code:
Sxml = """<LogIn><UserName>farmaceft@fzo.org.mk</UserName><Password>P@ssw0rd</Password></LogIn>"""

I think what is happening is that in the next line, because of the concatenation being interpreted by VBA, a layer of quotes is being removed. So the extra quotes will be stripped away in my modified version, but you will get one more layer of quotes that persist across the concatenation. I'll admit I'm shooting from the hip here and this might blow up too. But you have to understand that cross-language operations are going to be tricky in any combination of languages for which ONE of the languages involved is NOT known to the compiler you are using.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:06
Joined
Oct 29, 2018
Messages
21,357
Please read my reply to UncleGizmo..Thanks
Hi. I know exactly what you're trying to do, because you have posted about it in your other threads already. And the best advice I can give you is always the same, try to read the API documentation. That's why I asked for a link to it, so we can help you interpret it for VBA application.


 

Isaac

Lifelong Learner
Local time
Today, 06:06
Joined
Mar 14, 2017
Messages
8,738
Your case kind of looks like a REST or SOAP type of request.
Also if you search using "SOAP VBA" etc, you'll find plenty of examples, (or 'REST API VBA', although not sure if you'll be quite as successful on that one).

If so, does this help?

SOAP Request via VBA in Excel - Spiceworks
 

Users who are viewing this thread

Top Bottom