Sample code for 30+ languages & platforms
SQL Server

Retrieve User Account Data

See more DocuSign Examples

To make an API call to the DocuSign platform, your application needs both an access token (which you obtained in the previous step), and base URI that is unique to the user on whose behalf your application is making the API call. To get the base URI, call the/oauth/userinfoendpoint, supplying your application’s access token as a header.

Chilkat SQL Server Downloads

SQL Server
-- 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 --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" https://account-d.docusign.com/oauth/userinfo

    -- 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 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

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://account-d.docusign.com/oauth/userinfo', @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)

    -- {
    --   "sub": "564f7988-xxxx-xxxx-xxxx-781ee556ab7a",
    --   "name": "Example J Smith",
    --   "given_name": "Example",
    --   "family_name": "Smith",
    --   "created": "2018-04-13T22:03:03.45",
    --   "email": "Example.Smith@exampledomain.com",
    --   "accounts": [
    --     {
    --       "account_id": "18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604",
    --       "is_default": true,
    --       "account_name": "ExampleAccount",
    --       "base_uri": "https://demo.docusign.net"
    --     }
    --   ]
    -- }

    -- 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 @account_id nvarchar(4000)

    DECLARE @is_default int

    DECLARE @account_name nvarchar(4000)

    DECLARE @base_uri nvarchar(4000)

    DECLARE @sub nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sub OUT, 'sub'
    DECLARE @name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'name'
    DECLARE @given_name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @given_name OUT, 'given_name'
    DECLARE @family_name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @family_name OUT, 'family_name'
    DECLARE @created nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @created OUT, 'created'
    DECLARE @email nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'email'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'accounts'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @account_id OUT, 'accounts[i].account_id'
        EXEC sp_OAMethod @jResp, 'BoolOf', @is_default OUT, 'accounts[i].is_default'
        EXEC sp_OAMethod @jResp, 'StringOf', @account_name OUT, 'accounts[i].account_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @base_uri OUT, 'accounts[i].base_uri'
        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