SQL Server
SQL Server
DocuSign List Folder Items
See more DocuSign Examples
Retrieves a list of the envelopes in the specified folder.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Implements the following HTTP request:
-- GET /restapi/v2.1/accounts/{accountId}/folders/{folderId}
-- Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header.
DECLARE @jsonToken int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT
-- Load a previously obtained OAuth2 access token.
EXEC sp_OAMethod @jsonToken, 'LoadFile', @success OUT, 'qa_data/tokens/docusign.json'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @jsonToken, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jsonToken
RETURN
END
EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'access_token'
EXEC sp_OASetProperty @http, 'AuthToken', @sTmp0
-- Use your account ID and a valid folderId here:
EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'accountId', '7f3f65ed-5e87-418d-94c1-92499ddc8252'
EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'folderId', '94644782-31b7-4f82-a2c1-26d8a9306f8c'
DECLARE @sbResponseBody int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://demo.docusign.net/restapi/v2.1/accounts/{$accountId}/folders/{$folderId}', @sbResponseBody
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jsonToken
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jsonToken
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "resultSetSize": "sample string 1",
-- "startPosition": "sample string 2",
-- "endPosition": "sample string 3",
-- "totalSetSize": "sample string 4",
-- "previousUri": "sample string 5",
-- "nextUri": "sample string 6",
-- "folderItems": [
-- {
-- "ownerName": "sample string 1",
-- "envelopeId": "sample string 2",
-- "envelopeUri": "sample string 3",
-- "status": "sample string 4",
-- "senderName": "sample string 5",
-- "senderEmail": "sample string 6",
-- "createdDateTime": "sample string 7",
-- "sentDateTime": "sample string 8",
-- "completedDateTime": "sample string 9",
-- "subject": "sample string 10",
-- "templateId": "sample string 11",
-- "name": "sample string 12",
-- "shared": "sample string 13",
-- "password": "sample string 14",
-- "description": "sample string 15",
-- "lastModified": "sample string 16",
-- "pageCount": 17,
-- "uri": "sample string 18",
-- "is21CFRPart11": "sample string 19",
-- "isSignatureProviderEnvelope": "sample string 20",
-- "customFields": [
-- {
-- "fieldId": "sample string 1",
-- "name": "sample string 2",
-- "show": "sample string 3",
-- "required": "sample string 4",
-- "value": "sample string 5",
-- "configurationType": "sample string 6",
-- "errorDetails": {
-- "errorCode": "sample string 1",
-- "message": "sample string 2"
-- }
-- }
-- ]
-- }
-- ]
-- }
-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
DECLARE @ownerName nvarchar(4000)
DECLARE @envelopeId nvarchar(4000)
DECLARE @envelopeUri nvarchar(4000)
DECLARE @status nvarchar(4000)
DECLARE @senderName nvarchar(4000)
DECLARE @senderEmail nvarchar(4000)
DECLARE @createdDateTime nvarchar(4000)
DECLARE @sentDateTime nvarchar(4000)
DECLARE @completedDateTime nvarchar(4000)
DECLARE @subject nvarchar(4000)
DECLARE @templateId nvarchar(4000)
DECLARE @name nvarchar(4000)
DECLARE @shared nvarchar(4000)
DECLARE @password nvarchar(4000)
DECLARE @description nvarchar(4000)
DECLARE @lastModified nvarchar(4000)
DECLARE @pageCount int
DECLARE @uri nvarchar(4000)
DECLARE @is21CFRPart11 nvarchar(4000)
DECLARE @isSignatureProviderEnvelope nvarchar(4000)
DECLARE @j int
DECLARE @count_j int
DECLARE @fieldId nvarchar(4000)
DECLARE @show nvarchar(4000)
DECLARE @required nvarchar(4000)
DECLARE @value nvarchar(4000)
DECLARE @configurationType nvarchar(4000)
DECLARE @errorDetailsErrorCode nvarchar(4000)
DECLARE @errorDetailsMessage nvarchar(4000)
DECLARE @resultSetSize nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @resultSetSize OUT, 'resultSetSize'
DECLARE @startPosition nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @startPosition OUT, 'startPosition'
DECLARE @endPosition nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @endPosition OUT, 'endPosition'
DECLARE @totalSetSize nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @totalSetSize OUT, 'totalSetSize'
DECLARE @previousUri nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @previousUri OUT, 'previousUri'
DECLARE @nextUri nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @nextUri OUT, 'nextUri'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'folderItems'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @ownerName OUT, 'folderItems[i].ownerName'
EXEC sp_OAMethod @jResp, 'StringOf', @envelopeId OUT, 'folderItems[i].envelopeId'
EXEC sp_OAMethod @jResp, 'StringOf', @envelopeUri OUT, 'folderItems[i].envelopeUri'
EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'folderItems[i].status'
EXEC sp_OAMethod @jResp, 'StringOf', @senderName OUT, 'folderItems[i].senderName'
EXEC sp_OAMethod @jResp, 'StringOf', @senderEmail OUT, 'folderItems[i].senderEmail'
EXEC sp_OAMethod @jResp, 'StringOf', @createdDateTime OUT, 'folderItems[i].createdDateTime'
EXEC sp_OAMethod @jResp, 'StringOf', @sentDateTime OUT, 'folderItems[i].sentDateTime'
EXEC sp_OAMethod @jResp, 'StringOf', @completedDateTime OUT, 'folderItems[i].completedDateTime'
EXEC sp_OAMethod @jResp, 'StringOf', @subject OUT, 'folderItems[i].subject'
EXEC sp_OAMethod @jResp, 'StringOf', @templateId OUT, 'folderItems[i].templateId'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'folderItems[i].name'
EXEC sp_OAMethod @jResp, 'StringOf', @shared OUT, 'folderItems[i].shared'
EXEC sp_OAMethod @jResp, 'StringOf', @password OUT, 'folderItems[i].password'
EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'folderItems[i].description'
EXEC sp_OAMethod @jResp, 'StringOf', @lastModified OUT, 'folderItems[i].lastModified'
EXEC sp_OAMethod @jResp, 'IntOf', @pageCount OUT, 'folderItems[i].pageCount'
EXEC sp_OAMethod @jResp, 'StringOf', @uri OUT, 'folderItems[i].uri'
EXEC sp_OAMethod @jResp, 'StringOf', @is21CFRPart11 OUT, 'folderItems[i].is21CFRPart11'
EXEC sp_OAMethod @jResp, 'StringOf', @isSignatureProviderEnvelope OUT, 'folderItems[i].isSignatureProviderEnvelope'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'folderItems[i].customFields'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @fieldId OUT, 'folderItems[i].customFields[j].fieldId'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'folderItems[i].customFields[j].name'
EXEC sp_OAMethod @jResp, 'StringOf', @show OUT, 'folderItems[i].customFields[j].show'
EXEC sp_OAMethod @jResp, 'StringOf', @required OUT, 'folderItems[i].customFields[j].required'
EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'folderItems[i].customFields[j].value'
EXEC sp_OAMethod @jResp, 'StringOf', @configurationType OUT, 'folderItems[i].customFields[j].configurationType'
EXEC sp_OAMethod @jResp, 'StringOf', @errorDetailsErrorCode OUT, 'folderItems[i].customFields[j].errorDetails.errorCode'
EXEC sp_OAMethod @jResp, 'StringOf', @errorDetailsMessage OUT, 'folderItems[i].customFields[j].errorDetails.message'
SELECT @j = @j + 1
END
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jsonToken
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO