Cannot get correct VBA code to shorten URL via tinyurl using an autentication toke

39 Views Asked by At

I am trying to get VBA to run an API via tinyurl.com, which requires an authentication token. Whilst I can get the authentication to work (I think! I used to get an authentication error, but now I don't). But I can't figure out the code for it to actually accept the long URL to shorten. Here's the code I have, the error I get is: "The URL field is required".

Function GetTinyUrl(LongURL As String) As String

Dim xml
Set xml = CreateObject("WinHttp.WinHttpRequest.5.1")

xml.Open "POST", "https://api.tinyurl.com/create", False
xml.setrequestheader "Authorization", "Bearer " & "my api token"
xml.setrequestheader "url", LongURL

GetTinyUrl = xml.responseText

Set xml = Nothing
End Function

Any idea how I might "send" my long url via this API?

Thanks!

0

There are 0 best solutions below