Implementing YouSign in a Web Application with NodeJS or Ruby on Rails

AlamedaDev
AlamedaDev
Published in
5 min readFeb 13, 2023
PDF signature with YouSign, Ruby Implementation — Alameda Dev

Your business might need a document signature feature for several reasons, including:

  1. Legal compliance: Certain agreements and contracts require a legally binding signature, which can be achieved through digital signatures.
  2. Streamlining processes: By having a document signature, a business can streamline its processes and reduce the time and cost associated with printing, signing, and mailing paper documents.
  3. Improving customer experience: Improve the customer experience by making it easier for them to sign agreements and contracts, without having to leave their homes or offices.
  4. Enhancing security: Digital signatures provide a secure and verifiable way to sign documents, reducing the risk of fraud or tampering.
  5. Facilitating remote work: With the rise of remote work, having a document signature feature can enable a startup’s employees and customers to sign and process documents from anywhere, at any time.

Overall, a document signature feature can help a business to become more efficient, secure, and customer-friendly, while also complying with legal requirements.

YouSign is a digital signature solution that enables individuals and businesses to sign and send documents electronically. With YouSign, you can upload a document, add signature fields, and then invite others to sign the document online. The signed document can then be saved and downloaded for future reference, providing a secure and efficient way to sign and manage electronic documents.

Here are the four steps to create your first Signature Request:

1. Initiate the Signature Request.
2. Upload the document to sign.
3. Add a signer.
4. Activate the Signature Request.

To integrate YouSign into a Node or Ruby on Rails application, you’ll need to sign up for an API key on the YouSign website.

First, sign up for an API key: To use the YouSign API, you will need to sign up for an API key on the YouSign website.

Initiate the Signature Request

A Signature Request represents the object you send to recipients for signing. A Signature Request can have one or multiple Documents and one or multiple Signers attached. There are three different levels of electronic signatures (eSignature) offered by YouSign:

  • Simple eSignature for everyday work
  • Advanced eSignature for secure signatures on sensitive documents
  • Qualified eSignature, which is legally equivalent to a handwritten signature.

Here’s a code sample to create a Signature Request using the YouSign API:

require "uri"
require "net/http"
require 'json'


base_url = "https://api-sandbox.yousign.app/v3"
api_key = "YOUR API KEY"


## Create a Signature Request:

url = URI(sprintf("%s/signature_requests", base_url))
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url, 'Content-Type' => 'application/json')
request["Authorization"] = sprintf("Bearer %s", api_key)
request.body = {name: 'The name of your Signature Request', delivery_mode: 'email', timezone: 'Europe/Madrid'}.to_json

response = https.request(request)
signature_request = JSON(response.body)
signature_request_id = signature_request["id"]

Upload the document to sign

Documents added to a Signature Request must be in PDF format. They can either be signable documents, which are meant to be signed by Signers, or attachments, which are added to the request but not meant to be signed.

To place the visual signature field on the document, you’ll need to use manual field positions and specify the absolute coordinates of the signature field on the page. You can use the YouSign tool to find the coordinates.

Here’s a code sample to add a Document to the Signature Request:

## Add a Document to the Signature Request:

url = URI(sprintf("%s/signature_requests/%s/documents", base_url, signature_request_id))

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = sprintf("Bearer %s", api_key)

form_data = [['file', File.open('./public/assets/document.pdf'), content_type: 'application/pdf'],['nature', 'signable_document'],['parse_anchors', 'true']]

request.set_form form_data, 'multipart/form-data'
response = https.request(request)
document = JSON(response.body)
document_id = document["id"]

Add a signer

You have to add a Signer’s to your Signature Request. Signers are the individuals you request a signature from on Documents of nature `signable_document`.

A Signer must have at least one Signature Field. The signature Field represents the place on the document where the Signer will apply his signature.

## Add a Signer to the Signature Request:

url = URI(sprintf("%s/signature_requests/%s/signers", base_url, signature_request_id))
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url, 'Content-Type' => 'application/json')
request["Authorization"] = sprintf("Bearer %s", api_key)
request.body = {
"info": {
"first_name": "John",
"last_name": "Doe",
"email": "osledy@alamedadev.com",
"phone_number": "+33700000000",
"locale": "en"
},
"signature_authentication_mode": "no_otp",
"signature_level": "electronic_signature",
"fields": [{
"document_id": document_id,
"type": "signature",
"page": 1,
"width": 146,
"height": 52,
"x": 224,
"y": 733
}]
}.to_json

https.request(request)

Activate the Signature Request

The last step is to activate the Signature Request. Activating the Signature Request sends an email invitation to the Signers to sign the document.

## Activate the Signature Request:

url = URI(sprintf("%s/signature_requests/%s/activate", base_url, signature_request_id))
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url, 'Content-Type' => 'application/json')
request["Authorization"] = sprintf("Bearer %s", api_key)
response = https.request(request)

puts response.body

The Signer will receive an email requesting to sign.

PDF signature with YouSign, Ruby Implementation — Alameda Dev

Custom Experiences

Apart from the base service, you can customize the look and feel of your signing experience with Custom Experience.

To personalize the signature process and adapt it to your brand identity, it is possible to:

  • Customize the signature experience appearance (colors, start screen, left panel).
  • Personalize the user’s journey with the redirect success and redirect error link.
  • Manage email notifications triggered when an event occurs on the Signature Request (ie. “Request is -approved”, “Request is rejected”).
  • Manage emails settings (ie. show the due date or your logo)

More details about Custom Experiences can be found here.

With these steps, you can integrate YouSign into your Node or Ruby on Rails application and start sending electronic signature requests.

Note that the above code is just a sample, and you may need to modify it to meet your specific requirements and integration needs.

Implementing a digital signature solution can be complex, but it doesn’t have to be. Fortunately, there are many solutions available to make the process easier. If you’re interested in adding digital signatures to your business processes, for more contact us: www.alamedadev.com/contact. Our team of experts will be happy to help you develop custom software for your specific needs.

AlamedaDev is a full life cycle software solutions company. We provide Modern Software Development and #AI integrations.

Founded in #barcelona

Website: www.alamedadev.com

--

--

AlamedaDev
AlamedaDev

AlamedaDev provides full-service end-to-end software. Experts in modern software development and AI solutions