• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Refresh RESTful Token Using VBA

Ron Anderson

New Member
Hi, I have a main Excel application which downloads data from a web server using VBA and a REST API. Currently I need to RENEW the token daily. I've built a test application to REFRESH the token because I don't want to renew the token daily. The test app only works after I've ran the main apps daily renewal. Furthermore, The test app will only work if the main app is in the background. Using the test app by itself will not work.

I'd really appreciate it if someone can look at the code and offer suggestions to get the test app working without needing the main app to be open. Here's the code:-

>>> use code - tags <<<
Code:
Sub RefreshToken()
Dim hReq As Object, json As Dictionary
Dim sht As Worksheet
Dim strUrl As String
Set sht = Sheet1

strUrl = Cells(1, 5).value 'Variable text held in this cell

Set hReq = CreateObject("MSXML2.XMLHTTP")

With hReq
.Open "GET", strUrl, False
.SetRequestHeader "Authorization", "<Basic Base64Encode>"
.SetRequestHeader "Content_Type", "application/x-www-form-urlencoded"
.SetRequestHeader "grant_type", "refresh_token"
.SetRequestHeader "refresh_token", “<MyRefreshToken>”
.Send
End With

Response = hReq.ResponseText

‘//Do other things here

End Sub

I've checked and double checked my credential and they are correct.

Thanks, in anticipation, Ron
 
Last edited by a moderator:
Some questions:

1) What's a token? (Could be we don't need to know, but it might help give context.)

2) By "test application" do you mean an Excel program?

3) Are the "main apps" also Excel programs? I'm a little doubtful about this; it isn't clear to me why a VBA program would fail to run unless another VBA program is "in the background" (and by the way 4) what does "in the background" mean in this context?).
 
Back
Top