Sample code for 30+ languages & platforms
SQL Server

Yousign: Making your first API call

See more Yousign Examples

Demonstrates making the simplest of calls to test your API key. This example tests using the sandbox URLs.

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 --location --request GET 'https://staging-api.yousign.com/users' \
    -- --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/users', @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 @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, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        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)

    -- {
    --   "id": "/users/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    --   "firstname": "John",
    --   "lastname": "Doe",
    --   "email": "john.doe@yousign.fr",
    --   "title": "Developer",
    --   "phone": "+33612345678",
    --   "status": "activated",
    --   "organization": "/organizations/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    --   "workspaces": [
    --     {
    --       "id": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    --       "name": "Acme"
    --     }
    --   ],
    --   "permission": "ROLE_ADMIN",
    --   "group": {
    --     "id": "/user_groups/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    --     "name": "Administrateur",
    --     "permissions": [
    --       "procedure_write",
    --       "procedure_template_write",
    --       "procedure_create_from_template",
    --       "contact",
    --       "sign",
    --       "organization",
    --       "user",
    --       "api_key",
    --       "procedure_custom_field",
    --       "signature_ui",
    --       "certificate",
    --       "archive"
    --     ]
    --   },
    --   "createdAt": "2018-12-01T09:42:25+01:00",
    --   "updatedAt": "2018-12-01T09:42:25+01:00",
    --   "deleted": false,
    --   "deletedAt": null,
    --   "config": [
    --   ],
    --   "inweboUserRequest": null,
    --   "samlNameId": null,
    --   "defaultSignImage": null,
    --   "notifications": {
    --     "procedure": true
    --   },
    --   "fastSign": false,
    --   "fullName": "John Doe"
    -- }

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

    DECLARE @strVal nvarchar(4000)

    DECLARE @id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'id'
    DECLARE @firstname nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @firstname OUT, 'firstname'
    DECLARE @lastname nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @lastname OUT, 'lastname'
    DECLARE @email nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'email'
    DECLARE @title nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @title OUT, 'title'
    DECLARE @phone nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @phone OUT, 'phone'
    DECLARE @status nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status'
    DECLARE @organization nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @organization OUT, 'organization'
    DECLARE @permission nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @permission OUT, 'permission'
    DECLARE @groupId nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @groupId OUT, 'group.id'
    DECLARE @groupName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @groupName OUT, 'group.name'
    DECLARE @createdAt nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @createdAt OUT, 'createdAt'
    DECLARE @updatedAt nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @updatedAt OUT, 'updatedAt'
    DECLARE @deleted int
    EXEC sp_OAMethod @jResp, 'BoolOf', @deleted OUT, 'deleted'
    DECLARE @deletedAt nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @deletedAt OUT, 'deletedAt'
    DECLARE @inweboUserRequest nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @inweboUserRequest OUT, 'inweboUserRequest'
    DECLARE @samlNameId nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @samlNameId OUT, 'samlNameId'
    DECLARE @defaultSignImage nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @defaultSignImage OUT, 'defaultSignImage'
    DECLARE @notificationsProcedure int
    EXEC sp_OAMethod @jResp, 'BoolOf', @notificationsProcedure OUT, 'notifications.procedure'
    DECLARE @fastSign int
    EXEC sp_OAMethod @jResp, 'BoolOf', @fastSign OUT, 'fastSign'
    DECLARE @fullName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @fullName OUT, 'fullName'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'workspaces'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'workspaces[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'workspaces[i].name'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'group.permissions'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'group.permissions[i]'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'config'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO