Hello,
I am new to all this, so be gentle I have been trying use Excel to manage my data. I want to be able to import data from FreeAgent, change it and load it back in. I also want to be able to load new data. However, I have been banging my head against the wall and not even managed the first hurdle.
I have successfully obtained an authorization code which I now want to swop for tokens (access and refresh) using VBA. I have tried several different iterations of the code and I have tried to start from refreshing my authorization code too (no luck ) and keep getting the same error message returned,:
âHTTP Basic: Access deniedâ
Please see my (one of many attempted and failed) code below (Iâm hoping it is something obvious - I have xxx for sensitive values, all these have been triple checked):
Sub CommandButton1_Click()
Dim TargetURL As String
TargetURL = âhttps://api.freeagent.com/v2/token_endpointâ
Dim getTokenBody As String
getTokenBody = âgrant_type=authorization_codeâ & _
â&code=xxxâ & _
â&redirect_uri=http%3A%2F%2Flocalhostâ
Dim authUser As String
authUser = âxxxâ
Dim authPass As String
authPass = âxxxâ
Set HTTPReq = CreateObject(âWinHttp.WinHttpRequest.5.1â)
HTTPReq.Option(4) = 13056 â
HTTPReq.Open âPOSTâ, TargetURL, False
HTTPReq.SetCredentials authUser, authPass, 0
HTTPReq.setRequestHeader âContent-Typeâ, âapplication/x-www-form-urlencodedâ
HTTPReq.send (getTokenBody)
MsgBox (HTTPReq.responseText)
End Sub
Any help is welcome!
Thanks,
Diane