RonAnderson
New Member
- Joined
- Jan 2, 2018
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hi, I have a VBA procedure which works when AFTER I've renewed the RESTful API token. Obviously I don't want to have to renew the token daily. I've amended the code to request a refresh token but it returns an error message "Authorization has been denied for this request.". I've checked all of the necessary credentials and they are correct. I'd greatly appreciate any help offered. Here's the 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
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