SQL Server
SQL Server
Docusign: Return Brand Data Associated with a User
See more DocuSign Examples
Demonstrates a call using an OAuth2 access token in combination with the account ID for which we have authorization.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 --request GET https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ"
-- 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
-- Use an account ID obtained from DocuSign Get User Account Data
DECLARE @sbResponseBody int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands', @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 @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 @jsonToken
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)
-- {
-- "recipientBrandIdDefault": "sample string 1",
-- "senderBrandIdDefault": "sample string 2",
-- "brands": [
-- {
-- "brandCompany": "sample string 1",
-- "brandId": "sample string 2",
-- "brandName": "sample string 3",
-- "colors": [
-- {}
-- ],
-- "errorDetails": {
-- "errorCode": "sample string 1",
-- "message": "sample string 2"
-- },
-- "isOverridingCompanyName": "sample string 4",
-- "isSendingDefault": "sample string 5",
-- "isSigningDefault": "sample string 6",
-- "landingPages": [
-- {}
-- ],
-- "links": [
-- {
-- "linkType": "sample string 1",
-- "urlOrMailTo": "sample string 2",
-- "linkText": "sample string 3",
-- "showLink": "sample string 4"
-- }
-- ],
-- "emailContent": [
-- {
-- "emailContentType": "sample string 1",
-- "content": "sample string 2",
-- "emailToLink": "sample string 3",
-- "linkText": "sample string 4"
-- }
-- ],
-- "logos": {
-- "primary": "sample string 1",
-- "secondary": "sample string 2",
-- "email": "sample string 3"
-- },
-- "resources": {
-- "email": "sample string 1",
-- "sending": "sample string 2",
-- "signing": "sample string 3",
-- "signingCaptive": "sample string 4"
-- }
-- }
-- ]
-- }
-- 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 @brandCompany nvarchar(4000)
DECLARE @brandId nvarchar(4000)
DECLARE @brandName nvarchar(4000)
DECLARE @errorDetailsErrorCode nvarchar(4000)
DECLARE @errorDetailsMessage nvarchar(4000)
DECLARE @isOverridingCompanyName nvarchar(4000)
DECLARE @isSendingDefault nvarchar(4000)
DECLARE @isSigningDefault nvarchar(4000)
DECLARE @logosPrimary nvarchar(4000)
DECLARE @logosSecondary nvarchar(4000)
DECLARE @logosEmail nvarchar(4000)
DECLARE @resourcesEmail nvarchar(4000)
DECLARE @resourcesSending nvarchar(4000)
DECLARE @resourcesSigning nvarchar(4000)
DECLARE @resourcesSigningCaptive nvarchar(4000)
DECLARE @j int
DECLARE @count_j int
DECLARE @linkType nvarchar(4000)
DECLARE @urlOrMailTo nvarchar(4000)
DECLARE @linkText nvarchar(4000)
DECLARE @showLink nvarchar(4000)
DECLARE @emailContentType nvarchar(4000)
DECLARE @content nvarchar(4000)
DECLARE @emailToLink nvarchar(4000)
DECLARE @recipientBrandIdDefault nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @recipientBrandIdDefault OUT, 'recipientBrandIdDefault'
DECLARE @senderBrandIdDefault nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @senderBrandIdDefault OUT, 'senderBrandIdDefault'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'brands'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @json, 'I', @i
EXEC sp_OAMethod @json, 'StringOf', @brandCompany OUT, 'brands[i].brandCompany'
EXEC sp_OAMethod @json, 'StringOf', @brandId OUT, 'brands[i].brandId'
EXEC sp_OAMethod @json, 'StringOf', @brandName OUT, 'brands[i].brandName'
EXEC sp_OAMethod @json, 'StringOf', @errorDetailsErrorCode OUT, 'brands[i].errorDetails.errorCode'
EXEC sp_OAMethod @json, 'StringOf', @errorDetailsMessage OUT, 'brands[i].errorDetails.message'
EXEC sp_OAMethod @json, 'StringOf', @isOverridingCompanyName OUT, 'brands[i].isOverridingCompanyName'
EXEC sp_OAMethod @json, 'StringOf', @isSendingDefault OUT, 'brands[i].isSendingDefault'
EXEC sp_OAMethod @json, 'StringOf', @isSigningDefault OUT, 'brands[i].isSigningDefault'
EXEC sp_OAMethod @json, 'StringOf', @logosPrimary OUT, 'brands[i].logos.primary'
EXEC sp_OAMethod @json, 'StringOf', @logosSecondary OUT, 'brands[i].logos.secondary'
EXEC sp_OAMethod @json, 'StringOf', @logosEmail OUT, 'brands[i].logos.email'
EXEC sp_OAMethod @json, 'StringOf', @resourcesEmail OUT, 'brands[i].resources.email'
EXEC sp_OAMethod @json, 'StringOf', @resourcesSending OUT, 'brands[i].resources.sending'
EXEC sp_OAMethod @json, 'StringOf', @resourcesSigning OUT, 'brands[i].resources.signing'
EXEC sp_OAMethod @json, 'StringOf', @resourcesSigningCaptive OUT, 'brands[i].resources.signingCaptive'
SELECT @j = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'brands[i].colors'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @json, 'J', @j
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'brands[i].landingPages'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @json, 'J', @j
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'brands[i].links'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @json, 'J', @j
EXEC sp_OAMethod @json, 'StringOf', @linkType OUT, 'brands[i].links[j].linkType'
EXEC sp_OAMethod @json, 'StringOf', @urlOrMailTo OUT, 'brands[i].links[j].urlOrMailTo'
EXEC sp_OAMethod @json, 'StringOf', @linkText OUT, 'brands[i].links[j].linkText'
EXEC sp_OAMethod @json, 'StringOf', @showLink OUT, 'brands[i].links[j].showLink'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'brands[i].emailContent'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @json, 'J', @j
EXEC sp_OAMethod @json, 'StringOf', @emailContentType OUT, 'brands[i].emailContent[j].emailContentType'
EXEC sp_OAMethod @json, 'StringOf', @content OUT, 'brands[i].emailContent[j].content'
EXEC sp_OAMethod @json, 'StringOf', @emailToLink OUT, 'brands[i].emailContent[j].emailToLink'
EXEC sp_OAMethod @json, 'StringOf', @linkText OUT, 'brands[i].emailContent[j].linkText'
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 @json
END
GO