# Ruby
> Use this guide to migrate to the new Dropbox Sign Ruby SDK, which is powered by our OpenAPI specification. Contains concepts and examples to help you migrate successfully.
# Ruby Migration Guide
## Migrating the Ruby SDK from `hellosign-ruby-sdk` to `dropbox-sign`
## Architecture and Tooling
## Core Concepts and Patterns
This section contains the core concepts and patterns of the new SDK and highlights differences from the legacy SDK.
### Installation
-
Install the dropbox-sign gem:
```bash
gem install dropbox-sign
```
-
Add the following to your Gemfile:
```ruby
gem 'dropbox-sign', '~> 1.0.0'
```
-
Modify the version on your Gemfile to point to the New Ruby SDK package specified on Ruby gems. Or, if using the Gem locally, point to the version specified on our Github repo:
```ruby
gem 'dropbox-sign', '~> 1.0.0'
```
-
Run `bundle install`
### Importing the SDK
```ruby Legacy SDK - Importing
require "hello_sign"
```
```ruby New SDK - Importing
require "dropbox-sign"
```
### Authentication
The `api_key` parameter has been renamed to `username`, and it’s no longer possible to set the `client_id` on the configure block . The `client_id` must be set in each API call.
```ruby Legacy SDK - Config
require 'hello_sign'
HelloSign.configure do |config|
config.api_key = 'api_key'
end
```
```ruby New SDK - Config
require "dropbox-sign"
Dropbox::Sign.configure do |config|
# Configure HTTP basic authorization: api_key
config.username = "YOUR_API_KEY"
# or, configure Bearer authorization: oauth2
# config.access_token = "YOUR_ACCESS_TOKEN"
end
```
```ruby New SDK - Full Config + Adding Client ID
require "dropbox-sign"
Dropbox::Sign.configure do |config|
# Configure HTTP basic authorization: api_key
config.username = "YOUR_API_KEY"
# or, configure Bearer authorization: oauth2
# config.access_token = "YOUR_ACCESS_TOKEN"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signer_1 = Dropbox::Sign::SubSignatureRequestSigner.new
signer_1.email_address = "example@example.com"
signer_1.name = "Jack"
signer_1.order = 0
data = Dropbox::Sign::SignatureRequestCreateEmbeddedRequest.new
# Client ID added into the signature request here
data.client_id = "5435ebace29d38342cfc435da3c3b34e"
data.title = "NDA with Acme Co."
data.subject = "The NDA we talked about"
data.message = "Please sign this NDA and then we can discuss more"
data.signers = [signer_1]
data.files = [File.open(__dir__ + "/NDA.pdf")]
data.test_mode = true
begin
result = signature_request_api.signature_request_create_embedded(data)
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### Endpoints Grouped into Classes
The New Ruby SDK no longer uses the `Client` class. New classes have been introduced to execute specific endpoints and you will now need to instantiate a model specific client to access the methods needed to make your API calls.
| Class Name and Reference | API Reference |
| ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| [AccountApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/AccountApi.md) | [/account/\* Endpoints](/api/account) |
| [ApiAppApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/ApiAppApi.md) | [/api\_app/\* Endpoints](/api/api-app) |
| [BulkSendJobApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/BulkSendJobApi.md) | [/bulk\_send\_job/\* Endpoints](/api/bulk-send-job) |
| [EmbeddedApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/EmbeddedApi.md) | [/embedded/\* Endpoints](/api/embedded) |
| [OAuthApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/OAuthApi.md) | [/oauth/\* Endpoints](/docs/guides/o-auth/overview) |
| [ReportApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/ReportApi.md) | [/report/\* Endpoints](/api/report) |
| [SignatureRequestApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/SignatureRequestApi.md) | [/signature\_request/\* Endpoints](/api/signature-request) |
| [TeamApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/TeamApi.md) | [/team/\* Endpoints](/api/team) |
| [TemplateApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/TemplateApi.md) | [/template/\* Endpoints](/api/template) |
| [UnclaimedDraftApi](https://github.com/hellosign/dropbox-sign-ruby/blob/main/docs/UnclaimedDraftApi.md) | [/unclaimed\_draft/\* Endpoints](/api/unclaimed-draft) |
### Using Models to Pass Parameters
[Models](https://github.com/hellosign/dropbox-sign-ruby/blob/main/README.md#documentation-for-models) are used to define the structure and value of the parameters being passed. The fully assembled model is passed to the API endpoint method.
| Legacy Ruby SDK | New Ruby SDK |
| ---------------------------------------- | ---------------------------------------------------------- |
| Pass a hash of values directly to method | Pass an instance of the object related to that API request |
**New SDK Using Models to Pass Parameters**
```ruby
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signer_1 = Dropbox::Sign::SubSignatureRequestSigner.new
signer_1.email_address = "jack@dropboxsign.com"
signer_1.name = "Jack"
signer_1.order = 0
# Passing an instance of the object related to the request as data
obj = Dropbox::Sign::SignatureRequestSendRequest.new
obj.title = "NDA with Acme Co."
obj.subject = "The NDA we talked about"
obj.test_mode = true
obj.signers = [signer_1]
obj.files = [File.open(__dir__ + "/NDA.pdf")]
begin
result = signature_request_api.signature_request_send(obj)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### Path and Query Parameters
In the legacy SDK you would pass Path and Query parameters alongside any POST data to the API endpoint:
**Legacy SDK - Path and Query Parameters**
```ruby
signature_request = @client.remind_signature_request(
signature_request_id: '75cdf7dc8b323d43b347e4a3614d1f822bd09491',
:email_address: 'john@example.com'
)
```
The new SDK now requires POST data be an object when calling any API endpoint. Path and Query parameters must be passed individually to these methods.
**New SDK - Path and Query Parameters**
```ruby
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
data = Dropbox::Sign::SignatureRequestRemindRequest.new
data.email_address = "john@example.com"
signature_request_id = "2f9781e1a8e2045224d808c153c2e1d3df6f8f2f"
begin
result = signature_request_api.signature_request_remind(signature_request_id, data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### Error Handling and Warnings
The New SDK handles errors and warnings differently.
#### Error Handling
Errors are an instance of [Dropbox::Sign::ApiError](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/api_error.rb) with its `body` method returning an instance of [Dropbox::Sign::ErrorResponse](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/error_response.rb) class and should be handled using begin/rescue blocks.
**New SDK - Error Handling**
```ruby
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
account_api = Dropbox::Sign::AccountApi.new
begin
result = account_api.account_get({ email_address: "jack@example.com" })
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
#### Warnings
Warnings are a list of [Dropbox::Sign::WarningResponse](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/warning_response.rb).
**New SDK - Warnings**
```ruby
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
api = Dropbox::Sign::AccountApi.new
data = Dropbox::Sign::AccountCreateRequest.new
data.email_address = "newuser@dropboxsign.com"
begin
result = api.account_create(data)
p result
# warning loop
result.warnings.each do | warning |
puts "Warning Name: #{warning.warning_name}"
puts "Warning Message: #{warning.warning_msg}"
end
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### Instantiating Objects From Data
There are three ways to instantiate an object.
* You can instantiate a class directly and pass a hash of data
* You can use setter methods
* You can use the `init()` static method
```ruby New SDK - Using Constructor With Array of Data
signer_1 = Dropbox::Sign::SubSignatureRequestSigner.new({
:email_address => "jack@dropboxsign.com",
:name => "Jack",
:order => 0,
})
attachment1 = Dropbox::Sign::SubAttachment.new({
:name => "Attachment 1",
:instructions => "Please download this file",
:signer_index => 0,
:required => true,
})
```
```ruby New SDK - Using setter methods
signer_1 = Dropbox::Sign::SubSignatureRequestSigner.new
signer_1.email_address = "jack@dropboxsign.com"
signer_1.name = "Jack"
signer_1.order = 0
attachment1 = Dropbox::Sign::SubAttachment.new
attachment1.name = "Attachment 1"
attachment1.instructions = "Please download this file"
attachment1.signer_index = 0
attachment1.required = true
```
```ruby New SDK - Using init() Static Method
signer_1 = Dropbox::Sign::SubSignatureRequestSigner.init({
:email_address => "jack@dropboxsign.com",
:name => "Jack",
:order => 0,
})
attachment1 = Dropbox::Sign::SubAttachment.init({
:name => "Attachment 1",
:instructions => "Please download this file",
:signer_index => 0,
:required => true,
})
```
`init()` creates a full object using all the data you pass, including nested data to instantiate nested objects. Any parameters that you do not pass data for will be set to their default value (including `null`).
### Event Callback Helper
A callback helper class is included in the [New SDK repo](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/event_callback_helper.rb) to assist in verifying callbacks. The helper simplifies:
1. Checking event authenticity with built in event hash check
2. Displaying event types (account callback vs. app callback)
3. Displaying event messages
The `EventCallbackHelper` and `EventCallbackRequest` classes facilitate parsing of event data and assist in validating that a callback originated from Dropbox Sign.
We will send event callback payloads to you as a `multipart/form-data` request with a single `json` formfield that contains your event callback as a JSON string.
**Example Event Callback Request From US to YOU**
```bash
curl -X POST 'https://example.com/YOUR_EVENT_CALLBACK_URL' \
-F 'json={"event":{"event_type":"account_confirmed","event_time":"1669926463","event_hash":"ff8b03439122f9160500c3fb855bdee5a9ccba5fff27d3b258745d8f3074832f","event_metadata":{"related_signature_id":null,"reported_for_account_id":"6421d70b9bd45059fa207d03ab8d1b96515b472c","reported_for_app_id":null,"event_message":null}}}'
```
**Example JSON Payload**
```json
{
"event": {
"event_type": "account_confirmed",
"event_time": "1669926463",
"event_hash": "ff8b03439122f9160500c3fb855bdee5a9ccba5fff27d3b258745d8f3074832f",
"event_metadata": {
"related_signature_id": null,
"reported_for_account_id": "6421d70b9bd45059fa207d03ab8d1b96515b472c",
"reported_for_app_id": null,
"event_message": null
}
}
}
```
**How to use the EventCallbackHelper**
```ruby
require "dropbox-sign"
# use your API key
api_key = "324e3b0840f065eb51f3fd63231d0d33daa35d4ed10d27718839e81737065782"
# callback_data represents data we send to you
callback_data = JSON.parse(req.POST.json, :symbolize_names => true)
callback_event = Dropbox::Sign::EventCallbackRequest.init(callback_data)
# verify that a callback came from HelloSign.com
if Dropbox::Sign::EventCallbackHelper.is_valid(api_key, callback_event)
# one of "account_callback" or "api_app_callback"
callback_type = Dropbox::Sign::EventCallbackHelper.get_callback_type(callback_event)
# do your magic below!
end
```
## Differences from Legacy SDK
This section highlights larger changes to be aware of when migrating to the new SDK.
### Form Fields per Document
The Form Fields per Document parameter has changed from a two dimensional array, to a one dimensional array—allowing you to designate which file you to add the field to using `document_index`. You can learn more about this change here: [Form Fields per Document](/docs/sd-ks/open-api/form-fields-per-document).
```ruby Legacy SDK - Form Fields Per Document
form_fields_per_document: [
[
{
name: 'address',
type: 'text',
x: 160,
y: 80,
width: 206,
height: 32,
signer: 0
}
],
[
{
name: 'phone',
type: 'text',
x: 160,
y: 150,
width: 206,
height: 32,
signer: 1
}
]
]
```
```ruby New SDK - Form Fields per Document
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signer_1 = Dropbox::Sign::SubSignatureRequestSigner.init({
:email_address => "jack@dropboxsign.com",
:name => "Jack",
:order => 0,
})
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentText.init({
:document_index => 0,
:api_id => "134asdf",
:required => true,
:signer => 0,
:width => 100,
:height => 16,
:x => 112,
:y => 700,
:page => 1,
:placeholder => "Full Name",
:validation_type => "letters_only"
})
form_field_2 = Dropbox::Sign::SubFormFieldsPerDocumentTextMerge.init({
:document_index => 0,
:api_id => "5678yuio",
:name => "Address",
:required => true,
:signer => 0,
:width => 100,
:height => 16,
:x => 222,
:y => 700,
:page => 1,
})
form_field_3 = Dropbox::Sign::SubFormFieldsPerDocumentSignature.init({
:document_index => 0,
:api_id => "zxcvuip",
:required => true,
:signer => 1,
:width => 150,
:height => 30,
:x => 400,
:y => 715,
:page => 2,
})
data = Dropbox::Sign::SignatureRequestSendRequest.new
data.signers = [signer_1]
data.form_fields_per_document = [form_field_1, form_field_2, form_field_3]
begin
result = signature_request_api.signature_request_send(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
#### Instantiating the Correct Field Class
There are several different types of form fields you can define, identified by the value of the `type` field and a few ways to instantiate the correct object when making an API request.
The different classes for each type are:
| Field Type | Class |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| checkbox | [SubFormFieldsPerDocumentCheckbox](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_checkbox.rb) |
| checkbox-merge | [SubFormFieldsPerDocumentCheckboxMerge](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_checkbox_merge.rb) |
| date\_signed | [SubFormFieldsPerDocumentDateSigned](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_date_signed.rb) |
| dropdown | [SubFormFieldsPerDocumentDropdown](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_dropdown.rb) |
| hyperlink | [SubFormFieldsPerDocumentHyperlink](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_hyperlink.rb) |
| initials | [SubFormFieldsPerDocumentInitials](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_initials.rb) |
| radio | [SubFormFieldsPerDocumentRadio](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_radio.rb) |
| signature | [SubFormFieldsPerDocumentSignature](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_signature.rb) |
| text | [SubFormFieldsPerDocumentText](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_text.rb) |
| text-merge | [SubFormFieldsPerDocumentTextMerge](https://github.com/hellosign/dropbox-sign-ruby/blob/main/lib/dropbox-sign/models/sub_form_fields_per_document_text_merge.rb) |
**You can use `::init()` on the base request class**
```ruby
# instantiates a new `SignatureRequestSendRequest` object
data = Dropbox::Sign::SignatureRequestSendRequest.init({
title: "NDA with Acme Co.",
subject: "The NDA we talked about",
message: "Please sign this NDA and then we can discuss more.",
signers: [
{
email_address: "jack@dropboxsign.com",
name: "Jack",
order: 0,
},
],
files: [File.open(__dir__ + "/pdf-sample.pdf")],
form_fields_per_document: [
{
type: "signature",
document_index: 0,
api_id: "4688957689",
name: "signature1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
},
],
})
```
**You can use `::init()` on the field class**
```ruby
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentSignature.init({
type: "signature",
document_index: 0,
api_id: "4688957689",
name: "signature1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
})
```
**You can instantiate the class directly**
```ruby
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentSignature.new
form_field_1.type = "signature"
form_field_1.document_index = 0
form_field_1.api_id = "4688957689"
form_field_1.name = "signature1"
form_field_1.x = 5
form_field_1.y = 7
form_field_1.width = 60
form_field_1.height = 30
form_field_1.required = true
form_field_1.signer = 0
form_field_1.page = 1
```
**Form Fields per Document Examples using the new SDK:**
```ruby Signature
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentSignature.init({
type: "signature",
document_index: 0,
api_id: "4688957689",
name: "signature1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
})
```
```ruby Initials
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentInitials.init({
document_index: 0,
api_id: "4688957689",
name: "initials1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
})
```
```ruby Date Signed
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentDateSigned.init({
document_index: 0,
api_id: "4688957689",
name: "date_signed1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
})
```
```ruby Text
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentText.init({
document_index: 0,
api_id: "4688957689",
name: "text1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
})
```
```ruby Text Merge
first_name = Dropbox::Sign::SubCustomField.init({
name: "first_name",
value: "John"
})
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentTextMerge.init({
document_index: 0,
api_id: "4688957689",
name: "first_name",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
})
```
```ruby Checkbox
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentCheckbox.init({
document_index: 0,
api_id: "4688957689",
name: "checkbox1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
})
```
```ruby Checkbox Merge
is_registered = Dropbox::Sign::SubCustomField.init({
name: "is_registered",
value: "1"
})
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentCheckboxMerge.init({
document_index: 0,
api_id: "4688957689",
name: "is_registered",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
})
```
```ruby Dropdown
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentDropdown.init({
document_index: 0,
api_id: "4688957689",
name: "dropdown1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
options: ["Option 1","Option 2"],
content: "Option 2",
})
```
```ruby Hyperlink
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentHyperlink.init({
document_index: 0,
api_id: "4688957689",
name: "hyperlink1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: "me_now",
page: 1,
content: "Click me!",
content_url: "http://example.com",
})
```
```ruby Radio
form_field_1 = Dropbox::Sign::SubFormFieldsPerDocumentRadio.init({
document_index: 0,
api_id: "4688957689",
name: "radio1",
x: 5,
y: 7,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
group: "RadioItemGroup1",
is_checked: true,
})
form_field_2 = Dropbox::Sign::SubFormFieldsPerDocumentRadio.init({
document_index: 0,
api_id: "46876587",
name: "radio2",
x: 5,
y: 50,
width: 60,
height: 30,
required: true,
signer: 0,
page: 1,
group: "RadioItemGroup1",
is_checked: false,
})
form_field_group_1 = Dropbox::Sign::SubFormFieldGroup.init({
group_id: "RadioItemGroup1",
group_label: "Radio Item Group 1",
requirement: "require_0-1",
})
```
### "role" Value in `signers` Object
In the Legacy SDK when making a Signature Request using a Template the `signers` property was an object with the role name as the key. In the new SDK the role value has been moved into the signer object itself.
For example for the [/signature\_request/send\_with\_template](/api/signature-request/send-with-template) endpoint the `signers` property could be represented as:
```json Legacy SDK - signers with Roles
{
"signers": {
"Client": {
"name": "George",
"email_address": "george@example.com"
},
"Manager": {
"name": "Bob",
"email_address": "bob@example.com"
}
}
}
```
```json New SDK - signers with Roles
{
"signers": [
{
"role": "Client",
"name": "George",
"email_address": "george@example.com"
},
{
"role": "Manager",
"name": "Bob",
"email_address": "bob@example.com"
}
]
}
```
Using the new SDK you would now send this data as follows:
```ruby New SDK - signers with Roles Example #1
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
data = Dropbox::Sign::SignatureRequestSendWithTemplateRequest.init({
template_ids: ["c26b8a16784a872da37ea946b9ddec7c1e11dff6"],
subject: "Purchase Order",
message: "Glad we could come to an agreement.",
signers: [
{
role: "Client",
email_address: "george@example.com",
name: "George",
},
{
role: "Manager",
email_address: "bob@example.com",
name: "Bob",
}
],
})
begin
result = signature_request_api.signature_request_send_with_template(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
```ruby New SDK - signers with Roles Example #2
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signer_1 = Dropbox::Sign::SubSignatureRequestTemplateSigner.new
signer_1.role = "Client"
signer_1.email_address = "george@example.com"
signer_1.name = "George"
signer_2 = Dropbox::Sign::SubSignatureRequestTemplateSigner.new
signer_2.role = "Manager"
signer_2.email_address = "bob@example.com"
signer_2.name = "Bob"
data = Dropbox::Sign::SignatureRequestSendWithTemplateRequest.new
data.template_ids = ["c26b8a16784a872da37ea946b9ddec7c1e11dff6"]
data.subject = "Purchase Order"
data.message = "Glad we could come to an agreement."
data.signers = [signer_1, signer_2]
begin
result = signature_request_api.signature_request_send_with_template(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### "role" Value in `ccs` Property
In the Legacy SDK when making a Signature Request using a Template the `ccs` property was an object with the role name as the key. In the new SDK the role value has been moved into the cc object itself, alongside a new `email_address` property.
For example for the [/signature\_request/send\_with\_template](/api/signature-request/send-with-template) endpoint the `ccs` property could be represented as:
```json Legacy SDK - ccs
{
"ccs": {
"Client": "george@example.com",
"Manager": "bob@example.com"
}
}
```
```json New SDK - ccs
{
"ccs": [
{
"role": "Client",
"email_address": "george@example.com"
},
{
"role": "Manager",
"email_address": "bob@example.com"
}
]
}
```
Using the new SDK you would now send this data as follows:
```ruby New SDK - ccs Example #1
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
data = Dropbox::Sign::SignatureRequestSendWithTemplateRequest.init({
template_ids: ["c26b8a16784a872da37ea946b9ddec7c1e11dff6"],
subject: "Purchase Order",
message: "Glad we could come to an agreement.",
signers: [
{
role: "Client",
email_address: "george@example.com",
name: "George",
},
{
role: "Manager",
email_address: "bob@example.com",
name: "Bob",
}
],
ccs: [
{
role: "Client",
email_address: "george@example.com",
},
{
role: "Manager",
email_address: "bob@example.com",
}
]
})
begin
result = signature_request_api.signature_request_send_with_template(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
```ruby New SDK - ccs Example #2
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signer_1 = Dropbox::Sign::SubSignatureRequestTemplateSigner.new
signer_1.role = "Client"
signer_1.email_address = "george@example.com"
signer_1.name = "George"
signer_2 = Dropbox::Sign::SubSignatureRequestTemplateSigner.new
signer_2.role = "Manager"
signer_2.email_address = "bob@example.com"
signer_2.name = "Bob"
cc_1 = Dropbox::Sign::SubCC.new
cc_1.role = "Client"
cc_1.email_address = "george@example.com"
cc_2 = Dropbox::Sign::SubCC.new
cc_2.role = "Manager"
cc_2.email_address = "bob@example.com"
data = Dropbox::Sign::SignatureRequestSendWithTemplateRequest.new
data.template_ids = ["c26b8a16784a872da37ea946b9ddec7c1e11dff6"]
data.subject = "Purchase Order"
data.message = "Glad we could come to an agreement."
data.signers = [signer_1, signer_2]
data.ccs = [cc_1, cc_2]
begin
result = signature_request_api.signature_request_send_with_template(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### "name" Value in `custom_fields` Property
In the Legacy SDK when making a Signature Request with the `custom_fields` property it was an object with the name as the key. In the new SDK the name value has been moved into the custom\_field object itself.
For example for the [/signature\_request/send\_with\_template](/api/signature-request/send-with-template) endpoint the `custom_fields` property could be represented as:
```json Legacy SDK - custom_fields
{
"custom_fields": {
"company": {
"value": "ABC Corp",
"required": true
}
}
}
```
```json New SDK - custom_fields
{
"custom_fields": [
{
"name": "company",
"value": "ABC Corp",
"required": true
}
]
}
```
Using the new SDK you would now send this data as follows:
```ruby New SDK - custom_fields Example #1
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
data = Dropbox::Sign::SignatureRequestSendWithTemplateRequest.init({
template_ids: ["c26b8a16784a872da37ea946b9ddec7c1e11dff6"],
subject: "Purchase Order",
message: "Glad we could come to an agreement.",
signers: [
{
role: "Client",
email_address: "george@example.com",
name: "George",
},
{
role: "Manager",
email_address: "bob@example.com",
name: "Bob",
}
],
custom_fields: [
{
name: "company",
value: "ABC Corp",
required: true,
},
]
})
begin
result = signature_request_api.signature_request_send_with_template(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
```ruby New SDK - custom_fields Example #2
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signer_1 = Dropbox::Sign::SubSignatureRequestTemplateSigner.new
signer_1.role = "Client"
signer_1.email_address = "george@example.com"
signer_1.name = "George"
signer_2 = Dropbox::Sign::SubSignatureRequestTemplateSigner.new
signer_2.role = "Manager"
signer_2.email_address = "bob@example.com"
signer_2.name = "Bob"
custom_field_1 = Dropbox::Sign::SubCustomField.new
custom_field_1.name = "company"
custom_field_1.value = "ABC Corp"
custom_field_1.required = true
data = Dropbox::Sign::SignatureRequestSendWithTemplateRequest.new
data.template_ids = ["c26b8a16784a872da37ea946b9ddec7c1e11dff6"]
data.subject = "Purchase Order"
data.message = "Glad we could come to an agreement."
data.signers = [signer_1, signer_2]
data.custom_fields = [custom_field_1]
begin
result = signature_request_api.signature_request_send_with_template(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### `template_id` to `template_ids`
The `template_id` parameter has been removed. You must now use `template_ids`.
| Legacy SDK version | New SDK Version |
| --------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| Template ID (`template_id`) is passed as a singular string: template\_id : "1234567890"
| Template ID is passed as an array of strings (`template_ids`): template\_ids:\["1234567890"]
|
### `file` to `files`
The `file` parameter has been renamed to `files`. Usage remains the same.
Use `.files([...])`;
### `file_url` to `file_urls`
The `file_url` parameter has been renamed to `file_urls`. Usage remains the same.
Use `.file_urls([...])`;
### Interacting with Files
The new SDK version introduces some new patterns around uploading and downloading files. You can read about them more in depth here: [Interacting with Files](/docs/sd-ks/open-api/interacting-with-files).
#### Uploading Files
The file upload process changed with the newly-adopted OpenAPI-specification — it is no longer possible to pass file paths into file upload methods. You can learn more about this update here: [New Patterns: Interacting with Files](/docs/sd-ks/open-api/interacting-with-files).
-
Supports passing filepath as a string
-
Files needs to be instance of
File
-
Construct instance of
File
using either
File.open
or
File.new
```ruby Legacy SDK - File Upload
client.send_signature_request(
:test_mode => 1,
:title => 'NDA',
:files => ['/Users/NDA.pdf']
)
```
```ruby New SDK - File Upload
f1 = File.open(__dir__ + "/NDA.pdf")
f2 = File.open(__dir__ + "/Contract.pdf")
data = Dropbox::Sign::SignatureRequestSendRequest.new
data.title = "NDA with Acme Co."
data.signers = [signer_1]
data.files = [f1, f2]
```
#### Downloading Files
The file retrieval process changed with the newly-adopted OpenAPI-specification — one endpoint was branched off into three separate endpoints. You can learn more about this update here: [New Patterns: Interacting with Files](/docs/sd-ks/open-api/interacting-with-files).
-
Returns different file formats depending on parameters used from a single endpoint.
-
Original endpoint broken into 3 separate endpoints to return different file formats.
```ruby Legacy SDK - Download Files
client = HelloSign::Client.new :api_key => 'SIGN_IN_AND_CREATE_API_KEY_FIRST'
file_bin = client.signature_request_files :signature_request_id => 'fa5c8a0b0f492d768749333ad6fcc214c111e967', :file_type => 'pdf'
open("files.pdf", "pdf") do |file|
file.write(file_bin)
end
```
```ruby New SDK - Download Files
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signature_request_id = "fa5c8a0b0f492d768749333ad6fcc214c111e967"
begin
file_bin = signature_request_api.signature_request_files(signature_request_id)
FileUtils.cp(file_bin.path, "path/to/file.pdf")
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
```ruby New SDK - Download as Data Uri
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signature_request_id = "fa5c8a0b0f492d768749333ad6fcc214c111e967"
begin
result = signature_request_api.signature_request_files_as_data_uri(signature_request_id)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
```ruby New SDK - File File Url
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signature_request_id = "fa5c8a0b0f492d768749333ad6fcc214c111e967"
begin
result = signature_request_api.signature_request_files_as_file_url(signature_request_id)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
**Downloading Templates**
```ruby Legacy SDK - Get Template Files
client = HelloSign::Client.new :api_key => 'SIGN_IN_AND_CREATE_API_KEY_FIRST'
file_bin = client.get_template_files :template_id => 'fa5c8a0b0f492d768749333ad6fcc214c111e967', :file_type => 'pdf'
open("files.pdf", "pdf") do |file|
file.write(file_bin)
end
```
```ruby New SDK - Download Template Files
require "dropbox-sign"
Dropbox::Sign.configure do |config|
# Configure HTTP basic authorization: api_key
config.username = "YOUR_API_KEY"
# or, configure Bearer authorization: oauth2
# config.access_token = "YOUR_ACCESS_TOKEN"
end
template_api = Dropbox::Sign::TemplateApi.new
template_id = "5de8179668f2033afac48da1868d0093bf133266"
begin
file_bin = template_api.template_files(template_id)
FileUtils.cp(file_bin.path, "path/to/file.pdf")
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
```ruby New SDK - Template File as Data Uri
require "dropbox-sign"
Dropbox::Sign.configure do |config|
# Configure HTTP basic authorization: api_key
config.username = "YOUR_API_KEY"
# or, configure Bearer authorization: oauth2
# config.access_token = "YOUR_ACCESS_TOKEN"
end
template_api = Dropbox::Sign::TemplateApi.new
template_id = "5de8179668f2033afac48da1868d0093bf133266"
begin
result = template_api.template_files_as_data_uri(template_id)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
```ruby New SDK - Template File as File Url
require "dropbox-sign"
Dropbox::Sign.configure do |config|
# Configure HTTP basic authorization: api_key
config.username = "YOUR_API_KEY"
# or, configure Bearer authorization: oauth2
# config.access_token = "YOUR_ACCESS_TOKEN"
end
template_api = Dropbox::Sign::TemplateApi.new
template_id = "5de8179668f2033afac48da1868d0093bf133266"
begin
result = template_api.template_files_as_file_url(template_id)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
## Endpoint Mapping
This section shows you how endpoints in the legacy SDK map to the new SDK. It doesn't cover all endpoints, but gives you an idea of mapping implementations between the two SDKs. Please [reach out](https://faq.hellosign.com/hc/en-us/requests/new) if you think we're missing an important example.
* [Non-Embedded Signature Request](#non-embedded-signature-request)
* [Embedded Signature Request](#embedded-signature-request)
* [Send Signature Request with Template](#send-signature-request-with-template)
* [Get Signature Request](#get-signature-request)
* [List Signature Request](#list-signature-request)
* [Download Files](#download-files)
* [Get Account](#get-account)
### Non-Embedded Signature Request
```ruby Legacy SDK - Non-Embedded Sig Request
client = HelloSign::Client.new
client.send_signature_request(
:test_mode => 1,
:title => 'NDA',
:subject => 'Please sign this NDA',
:message => 'Please sign this NDA and then we can discuss more. Let me know if you have any
questions.',
:signers => [
{
:email_address => 'example@example.com',
:name => 'Jack',
:order => 0,
},
{
:email_address => 'example+1@example.com',
:name => 'Jack 2',
:order => 1,
}
],
:files => ['path_to_file']
)
end
```
```ruby New SDK - Non-Embedded Sig Request
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signer_1 = Dropbox::Sign::SubSignatureRequestSigner.new
signer_1.email_address = "example@example.com"
signer_1.name = "Jack"
signer_1.order = 0
signer_2 = Dropbox::Sign::SubSignatureRequestSigner.new
signer_2.email_address = "jack2@example.com"
signer_2.name = "Jack2"
signer_2.order = 0
data = Dropbox::Sign::SignatureRequestSendRequest.new
data.signers = [signer_1, signer_2]
data.files = [File.open(__dir__ + "/NDA.pdf")]
data.test_mode = 1
data.title = "NDA"
data.subject = "Please sign this NDA"
data.message = "Please sign this NDA and then we can discuss more"
begin
result = signature_request_api.signature_request_send(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### Embedded Signature Request
```ruby Legacy SDK - Embedded Sig Req
client.create_embedded_signature_request(
:test_mode => 1,
:client_id => 'b6b8e7deaf8f0b95c029dca049356d4a2cf9710a',
:title => 'NDA with Acme Co.',
:subject => 'The NDA we talked about',
:message => 'Please sign this NDA and then we can discuss more. Let me know if you have any
questions.',
:signers => [
{
:email_address => 'jack@example.com',
:name => 'Jack',
:order => 0,
},{
:email_address => 'jill@example.com',
:name => 'Jill',
:order => 1,
}
],
:files => ['NDA.pdf', 'AppendixA.pdf']
```
```ruby New SDK - Embedded Sig Req
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signer_1 = Dropbox::Sign::SubSignatureRequestSigner.new
signer_1.email_address = "example@example.com"
signer_1.name = "Jack"
signer_1.order = 0
data = Dropbox::Sign::SignatureRequestCreateEmbeddedRequest.new
data.client_id = "5435ebace29d38342cfc435da3c3b34e"
data.title = "NDA with Acme Co."
data.subject = "The NDA we talked about"
data.message = "Please sign this NDA and then we can discuss more"
data.signers = [signer_1]
data.files = [File.open(__dir__ + "/NDA.pdf")]
data.test_mode = true
begin
result = signature_request_api.signature_request_create_embedded(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### Send Signature Request with Template
```ruby Legacy SDK - Sig Req with Template
client = HelloSign::Client.new :api_key => 'SIGN_IN_AND_CREATE_API_KEY_FIRST'
client.send_signature_request_with_template(
:test_mode => 1,
:template_id => 'c26b8a16784a872da37ea946b9ddec7c1e11dff6',
:subject => 'Purchase Order',
:message => 'Glad we could come to an agreement.',
:signers => [
{
:email_address => 'george@example.com',
:name => 'George',
:role => 'Client'
}
],
:ccs => [
{
:email_address =>'accounting@example.com',
:role => "Accounting"
}
],
:custom_fields => [
{
:name => 'Cost',
:value => '$20,000'
}
]
)
```
```ruby New SDK - Sig Req with Template
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signer_1 = Dropbox::Sign::SubSignatureRequestTemplateSigner.new
signer_1.role = "Client"
signer_1.email_address = "dropboxsign@example.com"
signer_1.name = "George"
custom_field_1 = Dropbox::Sign::SubCustomField.new
custom_field_1.name = "Cost"
custom_field_1.value = "$20,000"
custom_field_1.editor = "Client"
custom_field_1.required = true
data = Dropbox::Sign::SignatureRequestSendWithTemplateRequest.new
data.template_ids = ["b7fee29dd746ebab9d8cdfcb7cdbdd0c5a2bc67a"]
data.subject = "Purchase Order"
data.message = "Glad we could come to an agreement."
data.signers = [signer_1]
data.custom_fields = [custom_field_1]
data.signing_options = signing_options
data.test_mode = true
begin
result = signature_request_api.signature_request_send_with_template(data)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### Get Signature Request
```ruby Legacy SDK - Get Sig Req
client.get_signature_request :signature_request_id => 'fa5c8a0b0f492d768749333ad6fcc214c111e967'
```
```ruby New SDK - Get Sig Req
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signature_request_id = "fa5c8a0b0f492d768749333ad6fcc214c111e967"
begin
result = signature_request_api.signature_request_get(signature_request_id)
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### List Signature Request
```ruby Legacy SDK - List Sig Req
client.get_signature_requests :page => 1
```
```ruby New SDK - List Sig Req
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
account_id = null
page = 1
begin
result = signature_request_api.signature_request_list({account_id: account_id, page: page})
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### Download Files
```ruby Legacy SDK - Download Files
client = HelloSign::Client.new :api_key => 'SIGN_IN_AND_CREATE_API_KEY_FIRST'
file_bin = client.signature_request_files :signature_request_id => 'fa5c8a0b0f492d768749333ad6fcc214c111e967', :file_type => 'pdf'
open("files.pdf", "pdf") do |file|
file.write(file_bin)
end
```
```ruby New SDK - Download Files
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
signature_request_api = Dropbox::Sign::SignatureRequestApi.new
signature_request_id = "c8239739332753028ee193cfde54b6e8141281f3"
begin
file_bin = signature_request_api.signature_request_files(signature_request_id)
FileUtils.cp(file_bin.path, "path/to/file.pdf")
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox Sign API: #{e}"
end
```
### Get Account
```ruby Legacy SDK - Get Account
client = HelloSign::Client.new :api_key => 'SIGN_IN_AND_CREATE_API_KEY_FIRST'
client.get_account
```
```ruby New SDK - Get Account
require "dropbox-sign"
Dropbox::Sign.configure do |config|
config.username = "YOUR_API_KEY"
end
account_api = Dropbox::Sign::AccountApi.new
begin
result = account_api.account_get
p result
rescue Dropbox::Sign::ApiError => e
puts "Exception when calling Dropbox API: #{e}"
end
```
## Supporting Legacy SDKs
## Feedback and Assistance