get token (1 Viewer)

irade92

Registered User.
Local time
Today, 04:52
Joined
Dec 26, 2010
Messages
229
Hi
Can anyone help me getting token using this:

curl --location --request POST 'http://api.fzo.org.mk/api/Auth/GetToken' \
--data-raw '<LogIn>
<UserName>farmaceft@fzo.org.mk</UserName>
<Password>P@ssw0rd</Password>
</LogIn>


I am using this code but no success

Dim req As New XMLHTTP60
Dim resp As New DOMDocument60

Dim Sxml As String
Sxml = "<?xml version='1.0' encoding='UTF-8' ?>" & vbNewLine _
& "<LogIn>" & vbNewLine _
& "<UserName>farmaceft@fzo.org.mk</UserName>" & vbNewLine _
& "<Password>P@ssw0rd</Password>" & vbNewLine _
& "</LogIn>" & vbNewLine _


req.Open "POST", "http://api.fzo.org.mk/api/Auth/GetToken", False

req.setRequestHeader "Content-Type", "application/xml"
req.send Sxml


resp.LoadXML req.responseText
resp.Save ("c:/apteka/token.txt")
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:52
Joined
Oct 29, 2018
Messages
21,477
Hi. Can you post a link to the API documentation? If we understood what the endpoint is expecting, we can guide you better.
 

irade92

Registered User.
Local time
Today, 04:52
Joined
Dec 26, 2010
Messages
229
I am afraid you will not understand it. it is in macedonian language. The endpoint is when I get the token i use it after as a bearer token to get some info about recipe and patients and issuing drug in a pharmacy..My app is in pharmacy and is about issuing drugs in a pharmacy...
The UserName and Password are not in a xml format, and maybe they are as plain text concatenating the string in http...this is only a pre-use period and impleneting will be maybe in july, So I have to solve until then.
Hope this will help
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:52
Joined
Oct 29, 2018
Messages
21,477
I am afraid you will not understand it. it is in macedonian language. The endpoint is when I get the token i use it after as a bearer token to get some info about recipe and patients and issuing drug in a pharmacy..My app is in pharmacy and is about issuing drugs in a pharmacy...
The UserName and Password are not in a xml format, and maybe they are as plain text concatenating the string in http...this is only a pre-use period and impleneting will be maybe in july, So I have to solve until then.
Hope this will help
Okay that is fair. I don't speak Macedonian, so it won't do me any good to read the documentation. But, you speak Macedonian, so you should be able to read and understand it. Right?

If we can't see the documentation, how can we tell if your XML is constructed properly? Maybe you can translate it for us.

Or, you could still choose to post the link, and maybe we can use Google or Bing Translator to understand it.

Just a thought...
 

irade92

Registered User.
Local time
Today, 04:52
Joined
Dec 26, 2010
Messages
229
Okay that is fair. I don't speak Macedonian, so it won't do me any good to read the documentation. But, you speak Macedonian, so you should be able to read and understand it. Right?

If we can't see the documentation, how can we tell if your XML is constructed properly? Maybe you can translate it for us.

Or, you could still choose to post the link, and maybe we can use Google or Bing Translator to understand it.

Just a thought...
good logic...don't misunderstand me please.. so..here is a bit of documentation that is in cURL language and says this:

This is given to us as an example:

curl --location --request POST 'http://api.fzo.org.mk/api/Auth/GetToken' \
--data-raw '<LogIn>
<UserName>farmaceft@fzo.org.mk</UserName>
<Password>P@ssw0rd</Password>
</LogIn>

Now with your great logic see if it is a proper xml or not..As far as I can see it is not. this line is missing "<?xml version="1.0" encoding="utf-8"?>

here is another example in other code language: Java - Unirest

Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("http://api.fzo.org.mk/api/Auth/GetToken")
.body("<LogIn>\r\n <UserName>izbran_lekar@fzo.org.mk</UserName>\r\n <Password>P@ssw0rd</Password>\r\n</LogIn>\r\n")
.asString();


here is another example in code language: JavaScript -JQuery

var settings = {
"url": "http://api.fzo.org.mk/api/Auth/GetToken",
"method": "POST",
"timeout": 0,
"data": "<LogIn>\r\n <UserName>izbran_lekar@fzo.org.mk</UserName>\r\n <Password>P@ssw0rd</Password>\r\n</LogIn>\r\n",
};

$.ajax(settings).done(function (response) {
console.log(response);
})


so...this examples are given to us...
the goal is to get JWT token in this format:

"eyJhbGciOiJSUzI1NiIsImtpZCI6Ijg0RDdDNUJCRjFFQkM5RjdCOTZGQzg2Njk3MDAxQjQ2NTJGREZCNDYiLCJ0eXAiOiJKV1QifQ.eyJ1bmlxdWVfbmFtZSI6Iml6YnJhbl9sZWthckBmem8ub3JnLm1rIiwiZmlyc3ROYW1lIjoi0JLQkNCh0JUiLCJsYXN0TmFtZSI6ItCf0JDQndCU0JXQkiIsImNlcnR0aHVtYnByaW50IjoiOEFEQzQ5MTkwNkRERTQ2NkY4MTExMDdDNTdGQUU0MTU2RjM4NERGMiIsImNvZGUiOiIxMTUxNDEiLCJpZGVudGlmaWVyIjoiMDQwNjk3ODQ3MDM5MiIsInJvbGUiOiJQcmltYXJ5RG9jdG9yIiwibmJmIjoxNjAxMzY4OTg3LCJleHAiOjE2MDEzOTc3ODcsImlhdCI6MTYwMTM2ODk4NywiaXNzIjoiRlpPTSIsImF1ZCI6IkZ6b21BcGkifQ.kH7lHOH6DrYQ3QEvRGBhdITeub6HV30Rbd0IUeNTspE9bULVZWYKpGt4ROomlAoBP5QLsjAMhXKKZKwodiI7wsQYGh1WWM9N2PIlqqaYDNKni0DKNAQRs97IXqpLYb2VAT0AnCDkiwpAyA4pZG2OG6Ui1xZ0hB7wimKFq4ErbB9aJpyF2dmA9TSFBk8xKjtGQse64e0EPfDrBvHnnKqJmBG2QuOwfu53YD9d23I5v5eG8rrwq4ivleVC7k0cvbobckBRAPqQtrjCCid8CL8eSUIX9eGUqxx5EMMZpIeLryjB0ShiBq4X_f6n5I25_BiqzTfI9ApNlADz-fInsAsBcA"

Now, It is very clear why I ask for help...I am using VBA, my app is in access 2010/2013 and there is no correct example for me.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 21:52
Joined
Feb 28, 2001
Messages
27,193
OK, that token will have to be received in a LongText slot in order for you to work with it, because that is clearly an encryption string that exceeds 255 bytes. Part of your problem is that VBA isn't normally used for socket operations. Look up the following on the web: VBA using WinSock

You might find some articles that would show you how to directly "diddle" with the network using Windows Sockets. I found at least a screen full of references on that subject, many of them using Excel VBA, but that won't stop you. In either case, you will see the name winsock.OCX, a file to add to your references after which certain socket calls become viable.

I would take you further than that but I have never played with WinSock networking so have no experiences to share.
 

irade92

Registered User.
Local time
Today, 04:52
Joined
Dec 26, 2010
Messages
229
OK, that token will have to be received in a LongText slot in order for you to work with it, because that is clearly an encryption string that exceeds 255 bytes. Part of your problem is that VBA isn't normally used for socket operations. Look up the following on the web: VBA using WinSock

You might find some articles that would show you how to directly "diddle" with the network using Windows Sockets. I found at least a screen full of references on that subject, many of them using Excel VBA, but that won't stop you. In either case, you will see the name winsock.OCX, a file to add to your references after which certain socket calls become viable.

I would take you further than that but I have never played with WinSock networking so have no experiences to share.
Well, thanks for your effort..but first things first...I am not able to get to the server, which means request.readystate = 4...after that I should receive response i.e JWT token and about long text I will think after...
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:52
Joined
Oct 29, 2018
Messages
21,477
good logic...don't misunderstand me please.. so..here is a bit of documentation that is in cURL language and says this:

This is given to us as an example:

curl --location --request POST 'http://api.fzo.org.mk/api/Auth/GetToken' \
--data-raw '<LogIn>
<UserName>farmaceft@fzo.org.mk</UserName>
<Password>P@ssw0rd</Password>
</LogIn>

Now with your great logic see if it is a proper xml or not..As far as I can see it is not. this line is missing "<?xml version="1.0" encoding="utf-8"?>

here is another example in other code language: Java - Unirest

Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("http://api.fzo.org.mk/api/Auth/GetToken")
.body("<LogIn>\r\n <UserName>izbran_lekar@fzo.org.mk</UserName>\r\n <Password>P@ssw0rd</Password>\r\n</LogIn>\r\n")
.asString();


here is another example in code language: JavaScript -JQuery

var settings = {
"url": "http://api.fzo.org.mk/api/Auth/GetToken",
"method": "POST",
"timeout": 0,
"data": "<LogIn>\r\n <UserName>izbran_lekar@fzo.org.mk</UserName>\r\n <Password>P@ssw0rd</Password>\r\n</LogIn>\r\n",
};

$.ajax(settings).done(function (response) {
console.log(response);
})


so...this examples are given to us...
the goal is to get JWT token in this format:

"eyJhbGciOiJSUzI1NiIsImtpZCI6Ijg0RDdDNUJCRjFFQkM5RjdCOTZGQzg2Njk3MDAxQjQ2NTJGREZCNDYiLCJ0eXAiOiJKV1QifQ.eyJ1bmlxdWVfbmFtZSI6Iml6YnJhbl9sZWthckBmem8ub3JnLm1rIiwiZmlyc3ROYW1lIjoi0JLQkNCh0JUiLCJsYXN0TmFtZSI6ItCf0JDQndCU0JXQkiIsImNlcnR0aHVtYnByaW50IjoiOEFEQzQ5MTkwNkRERTQ2NkY4MTExMDdDNTdGQUU0MTU2RjM4NERGMiIsImNvZGUiOiIxMTUxNDEiLCJpZGVudGlmaWVyIjoiMDQwNjk3ODQ3MDM5MiIsInJvbGUiOiJQcmltYXJ5RG9jdG9yIiwibmJmIjoxNjAxMzY4OTg3LCJleHAiOjE2MDEzOTc3ODcsImlhdCI6MTYwMTM2ODk4NywiaXNzIjoiRlpPTSIsImF1ZCI6IkZ6b21BcGkifQ.kH7lHOH6DrYQ3QEvRGBhdITeub6HV30Rbd0IUeNTspE9bULVZWYKpGt4ROomlAoBP5QLsjAMhXKKZKwodiI7wsQYGh1WWM9N2PIlqqaYDNKni0DKNAQRs97IXqpLYb2VAT0AnCDkiwpAyA4pZG2OG6Ui1xZ0hB7wimKFq4ErbB9aJpyF2dmA9TSFBk8xKjtGQse64e0EPfDrBvHnnKqJmBG2QuOwfu53YD9d23I5v5eG8rrwq4ivleVC7k0cvbobckBRAPqQtrjCCid8CL8eSUIX9eGUqxx5EMMZpIeLryjB0ShiBq4X_f6n5I25_BiqzTfI9ApNlADz-fInsAsBcA"

Now, It is very clear why I ask for help...I am using VBA, my app is in access 2010/2013 and there is no correct example for me.
To verify the endpoint is working and that the documentation is correct, were you able to get what you want by using cURL or Java or jQuery?

Not all APIs are created equal, so only using code samples may not be the best way to understand how to use it. For instance, here's an example of a token request I have to use for a financial company:
Code:
POST /Token HTTP/1.1
Host: subdomain.company.com
Accept: application/json
Partner-Id: %PARTNERID%
Content-Type: application/x-www-form-urlencoded
grant_type=password&amp;username=%USERNAME%&amp;password=%PASSWORD%
I then wrap that up in VBA as follows:
Code:
    With objHTTP
        .Open "POST", TOKEN_URL, False
        .setRequestHeader "Accept", "application/json"
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .setRequestHeader "Partner-Id", PARTNER_ID
        .Send ("grant_type=password&username=" & user & "&password=" & pwd)
        strJSON = .responseText
        Set objJSON = JsonConverter.ParseJson(strJSON)

        If .Status = 200 Then
            strAccessToken = objJSON("access_token")
...
So, to me, reading, understanding, and following the documentation is the best way to get your app to work with the API, because the documentation is the API developer's way to tell the users what they need to do to use the API.

Hope that makes sense...
 

Users who are viewing this thread

Top Bottom