send email through dropbox tokenaccess.

tronto12
NewLounger
Posts: 1
Joined: 29 Mar 2023, 10:56

send email through dropbox tokenaccess.

Post by tronto12 »

So I have this code which runs perfectly. but the things is that tokenaccess expires after 4 hours. so i need to adapt this so to generate/refreshes a new tokenaccess through vba, and store it for example in Sheet1 Cell A1. And then continue the rest code. So for the next time, it runs with the new token from cell A1, generates a new tokenaccess and store it again and continue the rest code.

(if needed the documentation page of dropbox: "officialweb"/developers/documentation/http/documentation i have tried several ways but couldn't adapt successfully. Could anyone help?)

Thanks in advance!

Code:

Code: Select all

Sub UploadToDropbox()

Dim accessToken As String
Dim filePath As String
Dim fileName As String
Dim folderPath As String
Dim url As String
Dim http As Object
Dim payload As Variant
Dim currentDate As String


accessToken = "mytoken"
filePath = Environ("USERPROFILE") & "\Desktop\" & Sheets("Admin1").Range("N3").Value & ".xlsx"
fileName = Sheets("Admin1").Range("N3").Value & "-" & Format(Date, "dd. mm. yyyy") & ".xlsx"
folderPath = "/myfolder/"
url = "https://content.dropboxapi .com/2/files/upload"


Open filePath For Binary As #1
payload = Input(LOF(1), 1)
Close #1

Set http = CreateObject("MSXML2.XMLHTTP")

http.Open "POST", url, False
http.SetRequestHeader "Authorization", "Bearer " & accessToken
http.SetRequestHeader "Dropbox-API-Arg", "{""path"": """ & folderPath & fileName & """, ""mode"": ""overwrite"", ""autorename"": true, ""mute"": false}"
http.SetRequestHeader "Content-Type", "application/octet-stream"
http.Send payload

If http.Status >= 400 Then
    Sheets("Admin1").Visible = xlVeryHidden
    Err.Raise 9999
End If

End Sub
Last edited by Leif on 29 Mar 2023, 11:45, edited 1 time in total.
Reason: To add CODE tags around code

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: send email through dropbox tokenaccess.

Post by HansV »

Welcome to Eileen's Lounge, and sorry for the lack of replies. I fear that few of use here have experience with the Dropbox API.
Best wishes,
Hans