以下是一个示例解决方法,使用Docusign的REST API来创建一个可选签名的签名请求。这个示例使用Python编程语言。
import requests
import base64
import json
# 设置Docusign账户信息
base_url = 'https://demo.docusign.net/restapi/v2/accounts/{account_id}'
username = 'your_username'
password = 'your_password'
integrator_key = 'your_integrator_key'
# 构建请求头
auth_header = {
'Authorization': 'Basic ' + base64.b64encode((username + ':' + password).encode()).decode(),
'X-DocuSign-Authentication': json.dumps({
'Username': username,
'Password': password,
'IntegratorKey': integrator_key
})
}
# 构建请求体
data = {
'status': 'sent',
'emailSubject': '请签署文档',
'documents': [{
'documentId': '1',
'name': 'document.pdf',
'documentBase64': base64.b64encode(open('document.pdf', 'rb').read()).decode()
}],
'recipients': {
'signers': [{
'email': 'recipient@example.com',
'name': 'Recipient',
'recipientId': '1',
'routingOrder': '1',
'tabs': {
'signHereTabs': [{
'documentId': '1',
'pageNumber': '1',
'xPosition': '100',
'yPosition': '200',
'optional': 'true' # 设置签名为可选
}]
}
}]
}
}
# 发送请求
response = requests.post(base_url + '/envelopes', headers=auth_header, json=data)
# 处理响应
if response.status_code == 201:
envelope_id = response.json()['envelopeId']
print(f'签名请求已创建,envelope ID: {envelope_id}')
else:
print('创建签名请求失败')
print(response.content.decode())
请确保替换示例代码中的{account_id}
、your_username
、your_password
和your_integrator_key
为您自己的Docusign账户信息。此外,您还需要将document.pdf
替换为您要发送的文档的路径。
这个示例中,optional
字段被设置为true
,以将签名设置为可选项。如果不想下载文档,您可以将documentBase64
字段设置为文档的Base64编码字符串,而不是文件路径。