Dropbox
Interact with the Dropbox API (v2.0) using SQL Server
- Obtain an App Key and App Secret from Dropbox.com
- Create the stored procedures documented below
- Execute the following SQL statement:
1 2 3 4 5 6 |
EXEC usp_Dropbox_v2_Auth_Init @Profile = 'enter-profile-name-of-your-choosing', @ClientID = 'enter-your-app-id', @ClientSecret = 'enter-your-app-secret', @RedirectURL = 'enter-you-redirecturl' --optional, default: http://localhost:53200 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
CREATE PROCEDURE usp_Dropbox_v2_Auth_Init( @Profile nvarchar(100), @ClientID varchar(50), @ClientSecret varchar(50), @RedirectURL varchar(100)) AS SET NOCOUNT ON DECLARE @UserBrowseToURL varchar(MAX) DECLARE @QueryString nvarchar(MAX) EXEC SQLHTTP.net.AuthParamSet @Profile = @Profile, @Name = 'ClientID', @Value = @ClientID EXEC SQLHTTP.net.AuthParamSet @Profile = @Profile, @Name = 'ClientSecret', @Value = @ClientSecret EXEC SQLHTTP.net.AuthParamSet @Profile = @Profile, @Name = 'RedirectURL', @Value = @RedirectURL SET @UserBrowseToURL = 'https://www.dropbox.com/1/oauth2/authorize' EXEC SQLHTTP.net.QueryStringBuilder @QueryString OUTPUT, @Profile, 'response_type', 'code', 'client_id', @ClientID SET @QueryString = @QueryString + '&redirect_uri=' COLLATE SQL_Latin1_General_CP1_CI_AS + @RedirectURL SET @UserBrowseToURL = @UserBrowseToURL + @QueryString DECLARE @URL nvarchar(MAX) DECLARE @Body nvarchar(MAX) DECLARE @HTTPSessionID uniqueidentifier DECLARE @Response nvarchar(MAX) DECLARE @StatusCode int DECLARE @StatusDescription nvarchar(MAX) DECLARE @RedirectURLCode varchar(50) DECLARE @Timeout int DECLARE @TimeoutReached bit = 0 SET @Timeout = 180 --three minutes wait EXEC SQLHTTP.net.AuthListener @UserBrowseToURL = @UserBrowseToURL, @RedirectURL = @RedirectURL, @Timeout = @Timeout, @QueryString = @QueryString OUTPUT, @TimeoutReached = @TimeoutReached OUTPUT IF @TimeoutReached = 1 BEGIN RAISERROR('Timeout reached waiting for browser authentication', 16, 1) RETURN END SET @RedirectURLCode = SQLHTTP.net.Split(@QueryString, 'code=', 2) SET @URL = 'https://api.dropbox.com/1/oauth2/token' EXEC SQLHTTP.net.FormDataBuilder @Body OUTPUT, @Profile, 'grant_type', 'authorization_code', 'code', @RedirectURLCode, 'client_id', @ClientID, 'client_secret', @ClientSecret SET @Body = @Body + '&redirect_uri=' COLLATE SQL_Latin1_General_CP1_CI_AS + @RedirectURL EXEC SQLHTTP.net.HTTPSession @HTTPSessionID OUTPUT EXEC SQLHTTP.net.HTTPRequest @HttpSessionID, @URL = @URL, @Method = 'POST', @Body = @Body, @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT, @Response = @Response OUTPUT IF @StatusCode >= 400 EXEC SQLHTTP.net.RaiseHttpError @StatusCode, @StatusDescription, @Response ELSE BEGIN DECLARE @BearerToken varchar(MAX) SELECT @BearerToken = [value] FROM SQLHTTP.net.Json_To_NodeTable(@Response) WHERE [Name] = 'access_token' EXEC SQLHTTP.net.AuthParamSet @Profile = @Profile, @Name = 'BearerToken', @value = @BearerToken END GO |
1 2 3 4 5 6 7 8 9 10 |
CREATE PROCEDURE usp_Dropbox_v2_Auth_Header( @Profile nvarchar(100), @HttpSessionID uniqueidentifier) AS DECLARE @AuthorizationHeaderValue varchar(MAX) SET @AuthorizationHeaderValue = 'Bearer ' + SQLHTTP.net.AuthParam(@Profile, 'BearerToken') EXEC SQLHTTP.net.RequestHeaderSet @HTTPSessionID, 'Authorization', @AuthorizationHeaderValue GO |
- Copy Reference – Fetch
- Copy Reference – Save
- File – Unshare
- File / Folder – Copy
- File / Folder – Delete
- File / Folder – Move
- File / Folder – Restore
- File / Folder – Search
- File / Folder Metadata – Fetch
- File Member – Add
- File Member – Delete
- File Members – Fetch
- File Members Batch – Fetch
- File Membership – Relinquish
- File Request – Create
- File Request – Fetch
- File Request – Update
- File Revisions – Fetch
- File URL – Save
- Files – Fetch
- Files / Folders – Batch Copy Status
- Files / Folders – Batch Delete
- Files / Folders – Batch Delete Status
- Files / Folders – Batch Copy
- Files / Folders – Batch Move
- Files / Folders – Batch Move Status
- Folder – Create
- Folder – Share
- Folder – Transfer
- Folder – Unshare
- Folder Member – Add
- Folder Member – Delete
- Folder Members – Fetch
- Job Status – Check
- Mountable Folders – Fetch
- Property Group – Create
- Property Group – Delete
- Property Group – Overwrite
- Property Group – Search
- Property Group – Update
- Received Files – Fetch
- Remove Member Job Status – Check
- Save URL – Check Job Status
- Shared File Metadata – Fetch
- Shared Files Metadata – Fetch
- Shared Folder – Mount
- Shared Folder – Unmount
- Shared Folder Metadata – Fetch
- Shared Folders – Fetch
- Shared Link – Create
- Shared Link – Revoke
- Shared Link – Update
- Shared Link Metadata – Fetch
- Shared Links – Fetch
- Template – Create
- Template – Fetch
- Template – Update
- Template – Delete
- Temporary Link – Fetch
IMPORTANT DISCLAIMER
CODE/SQL ON THESE PAGES ARE PROVIDED AS-IS AND ARE AVAILABLE FOR ILLUSTRATIVE PURPOSES ONLY.
USERS ARE REQUIRED TO ABIDE BY THE TERMS AND CONDITIONS FOR USING REFERENCED THIRD PARTY WEBSITES AND/OR APIs FROM THEIR RESPECTIVE WEBSITES. WE DO NOT CONDONE ANY VIOLATION OF THIRD PARTY WEBSITES AND/OR APIs TERMS AND CONDITIONS USING OUR SOFTWARE.
USERS SHALL BE SOLELY RESPONSIBLE AND BE SOLELY LIABLE FOR VIOLATION OF ANY RULES SPECIFIED BY THIRD PARTIES FOR USING THEIR WEBSITES AND/OR APIs, OR INFRINGEMENT OF RIGHTS OF SUCH THIRD PARTIES.