SQL Server
SQL Server
Yousign: List Files
See more Yousign Examples
List Yousign files.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 CURL command:
-- curl --location --request GET 'https://staging-api.yousign.com/files' \
-- --header 'Authorization: Bearer YOUR_API_KEY' \
-- --header 'Content-Type: application/json'
-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code
-- Adds the "Authorization: Bearer YOUR_API_KEY" header.
EXEC sp_OASetProperty @http, 'AuthToken', 'YOUR_API_KEY'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @sbResponseBody int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://staging-api.yousign.com/files', @sbResponseBody
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @json, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @json, '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, 'LastHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @json
RETURN
END
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "id": "\/files\/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
-- "name": "abc.pdf",
-- "type": "signable",
-- "contentType": "application\/pdf",
-- "description": null,
-- "createdAt": "2020-05-27T09:14:12+02:00",
-- "updatedAt": "2020-05-27T09:14:12+02:00",
-- "sha256": "ea2a92b0eff5bebfa3ccd869fd61e27bb7fe973d0dff63f106d8b0d614469fa0",
-- "metadata": [
-- ],
-- "workspace": "\/workspaces\/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
-- "creator": null,
-- "fileObjects": [
-- ],
-- "protected": false,
-- "position": 0,
-- "parent": null,
-- "fieldsCompatible": true,
-- "company": "\/companies\/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
-- }
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
DECLARE @id nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'id'
DECLARE @name nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @name OUT, 'name'
DECLARE @v_type nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @v_type OUT, 'type'
DECLARE @contentType nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @contentType OUT, 'contentType'
DECLARE @description nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @description OUT, 'description'
DECLARE @createdAt nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @createdAt OUT, 'createdAt'
DECLARE @updatedAt nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @updatedAt OUT, 'updatedAt'
DECLARE @sha256 nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @sha256 OUT, 'sha256'
DECLARE @workspace nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @workspace OUT, 'workspace'
DECLARE @creator nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @creator OUT, 'creator'
DECLARE @v_protected int
EXEC sp_OAMethod @json, 'BoolOf', @v_protected OUT, 'protected'
DECLARE @position int
EXEC sp_OAMethod @json, 'IntOf', @position OUT, 'position'
DECLARE @parent nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @parent OUT, 'parent'
DECLARE @fieldsCompatible int
EXEC sp_OAMethod @json, 'BoolOf', @fieldsCompatible OUT, 'fieldsCompatible'
DECLARE @company nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @company OUT, 'company'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'metadata'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @json, 'I', @i
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'fileObjects'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @json, 'I', @i
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @json
END
GO