I need to upload some files in a server, that requieres a login to get a token to be used when I upload my files.
To do login, I have this:
ADAPTED FROM How do we use restful APIs from Excel macros (vba)?
Sub LOGIN()
Dim Request As Object
Dim authKey As String
Dim stUrl As String
Dim response As String
Dim requestBody As String
stUrl = "https://WEB/oauth/connect/token?grant_type=client_credentials"
Set Request = CreateObject("MSXML2.XMLHTTP")
requestBody = "{ ""client_id"": ""USERNAME"", " & """client_secret"": ""PASSWORD""}"
With Request
.Open "POST", stUrl, False
.setRequestHeader "Content-type", "application/json"
.send (requestBody)
response = .responseText
End With
MsgBox responseText
After that, I need to know the Token to upload the files, byt responseText is in blank. If I try to save it in an excel cell, it is also in blank.
If I try to do in a CMD screen with
curl -X POST -H “client_id:USERNAME” -u USERNAME:PASSWORD “https://WEB/oauth/token” -d “grant_type=client_credentials”
I don’t receive any error, but any information.
How I can know the token response?
I don’t know how to get the token and / or how to save it in a variable in VBA.
This is the web: https://api.valenciaportpcs.net/messaging/swagger/index.html
Antonio Moyano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.