API quickstart with the Ruby SDK

The Esignature API Ruby SDK is generated with openapi generator.

You can generate it yourself using the OpenAPI3 specification, or clone our pre-prepared version at Ruby SDK Github repo.

The package contains its own documentation (in docs/), but the examples below will show you how to get started.

Get your API Key
  1. Sign up for a trial account. Configure for API when prompted and email support to get an API Key. You need to show a level of understanding about using REST API. Include a summary of your programming/REST experience.

  2. Once issued, your API key will be available in the web app. You'll be in sandbox mode - use the form to enter emails for sending test documents.

  3. Your api key goes in the "Authorization" header, and takes the form: Apikey username:secret. Your username and secret will be clearly indicated in the web app.

Check out our Postman collection. It offers coding examples using curl, http_requests2 or pecl. Legalesign API on Postman.
Install
  1. Install Ruby.

  2. Clone the Ruby package.

  3. cd into the package, build the gem spec by typing: gem build openapi_client.gemspec

  4. Install the gem by typing: gem install ./openapi_client-1.0.0.gem (sudo maybe required)

Test a GET request

Start with a basic GET request to make sure your Auth is correct.


require 'openapi_client'

OpenapiClient.configure do |config|
  config.api_key['Authorization'] = 'ApiKey username:secret'
end

api_instance = OpenapiClient::GroupApi.new
group_id = 'group_id_example' # String |

begin
  result = api_instance.get_group(group_id)
  p result
rescue OpenapiClient::ApiError => e
  puts "Exception when calling GroupApi->get_group: #{e}"
end

All being well, JSON text just appeared with your group information. If you have any issues, double and triple check your Auth.

It's common to need your latest signing document, use getDocuments, or getStatuses from the DocumentApi


api_instance = OpenapiClient::DocumentApi.new
statuses = api_instance.get_statuses(opts)
docs = api_instance.get_documents(opts)
Test a POST request

In this example we will send HTML, but you can upload a PDF/Word document or refer to a template you already prepared.

While HTML appears to be more primitive than a PDF it is most popular since it gives you a fast and full freedom in the construction of each document you send.


require 'openapi_client'

OpenapiClient.configure do |config|
  config.api_key['Authorization'] = 'ApiKey username:secret'
end

signers_data = [{ 'firstname' => 'john', 'lastname' => 'smith',
 'email' => 'john.smith@example.com', 'order' => 0}]

raw_html = '"<h1>Test doc</h1><p>Test doc 
for testing, <span class=\"field\"   data-optional=\"false\" 
data name=\"Please add your ...\" data-signee=\"1\"  
data-type=\"signature\" data-options=\"\"> ....... </span>'

post_data  = {
    'name' => 'Test html doc',
    'group' => '/api/v1/group/my-group/',
    'text' => raw_html,
    'do_email'=> true,
    'signers'=> signers_data
}

api_instance = OpenapiClient::DocumentApi.new
document_post = OpenapiClient::DocumentPost.new(post_data)

begin
docresponse = api_instance.post_document_with_http_info(document_post)
status  = docresponse[1] # 201
doc_id = docresponse[2]['Location'] # "/api/v1/status/4f746e7a-a661-4c4d-a28a-fe2bd59c263e/"

rescue OpenapiClient::ApiError => e
  puts "Exception when calling DocumentApi->post_document: #{e}"
end

That's it. In this article you have gathered your API key, queried for your documents and sent a HTML based doc to be signed.

Be prepared to dive into the Ruby (OpenApi generator) docs for more complex situations, the docs are well laid out and you should have no trouble tracking down the code you need.


Search Articles