Ruby
This Ruby snippet describes the sequence of API calls needed to create and activate a Signature Request.
require "uri"
require "net/http"
require 'json'
base_url = "https://api-sandbox.yousign.app/v3"
api_key = "REPLACE_WITH_YOUR_API_KEY"
## 1 - 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: 'none', timezone: 'Europe/Paris'}.to_json
response = https.request(request)
signature_request = JSON(response.body)
signature_request_id = signature_request["id"]
## 2 - 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('test.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"]
## 3 - 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": "[email protected]",
"phone_number": "+33600000000",
"locale": "fr"
},
"signature_authentication_mode": "no_otp",
"signature_level": "electronic_signature",
"fields": [
{
"document_id": document_id,
"type": "signature",
"height": 37,
"width": 85,
"page": 1,
"x": 0,
"y": 0
}
]
}.to_json
https.request(request)
## 4 - 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
Updated 7 months ago