新 DocuSign 信封中的损坏文档
Corrupt Documents in new DocuSign envelope
我正在做一个 POC 来演示 DocuSign 以编程方式创建和路由包含一个简单文档的信封。我正在使用 PowerShell 和 JSON API。登录和创建信封工作毫无怨言,但发送给我签名的结果 Word 文档包含乱码。我相信我有正确的 base64 编码和 headers。关于我做错了什么的想法?
下面粘贴了整个POC。我刚刚删除了 ID、密码、集成商密钥等。谢谢!
function boundry {
[System.Guid]::NewGuid().ToString()
}
###this is the corrected code###
function encodeFile {
param ([string]$fileName)
[System.Convert]::ToBase64String([IO.File]::ReadAllBytes((Resolve-Path $fileName).ProviderPath))
}
function logonParams {
[string] $userName = 'DocuSign user name'
[string] $password = 'DocuSign password'
[string] $integratorKey = 'DocuSign Integrator Key'
@"
{
"Username" : "$userName",
"Password" : "$password",
"IntegratorKey" : "$integratorKey"
}
"@
}
function logon {
[string] $loginURL = 'https://demo.docusign.net/restapi/v2/login_information'
$headers =
@{
"X-DocuSign-Authentication"=$(logonParams);
"accept"="application/json";
"content-type"="application/json";
}
$r = Invoke-WebRequest -uri $loginURL -headers $headers -method GET
$responseInfo = $r.content | ConvertFrom-Json
$baseURL = $responseInfo.loginAccounts.baseURL
#return the base URL for the next call
$baseURL
}
function createEnvelope {
param ([string]$file1,
[string]$baseURL
)
[string]$boundry = boundry
$headers =
@{
"X-DocuSign-Authentication"=$(logonParams);
"accept"="application/json";
"content-type"="multipart/form-data; boundary=$boundry";
}
[string]$formData = @"
--$boundry
Content-Type: application/json
{
"status":"sent",
"emailBlurb":"Please sign.",
"emailSubject": "Contract $(date)",
"documents": [{
"name": "$file1",
"documentId":"1",
"order":"1"
}],
"recipients": {
"signers" : [{
"email": "recipient@somecompany.com",
"name": "Recipient Name",
"recipientId":"1",
}]
}
}
--$boundry
Content-Type: application/msword
Content-Transfer-Encoding: base64
Content-Disposition: file; filename="$file1";documentid=1
$(encodeFile $file1)
--$boundry--
"@
$envelopeURL = "$baseURL/envelopes"
Invoke-WebRequest -uri $envelopeURL -headers $headers -body $formData -method POST
}
$baseURL = logon
createEnvelope "test.doc" $baseURL
尝试更改您的 Content-Type header 值。我不确定 application/msword
在这里是否有效,我认为 .docx 的正确 mime-type 是
application/vnd.openxmlformats-officedocument.wordprocessingml.document
查看之前的 SO post 以获得更完整的 mime-type 列表:
我在 DocuSign 支持团队的帮助下解决了这个问题。您可以在 DocuSign 中启用服务器端日志记录,这非常有用。从旧 UI(自 15 年 6 月起在新 UI 中不可用)从 ID/photo 旁边的下拉列表中选择首选项。然后select左边会员选项下的权限。检查 "Enable API Request Logging." 在您 运行 测试之后,下载 API 请求日志按钮变为活动状态。
从日志中可以很清楚地看出我的编码有误。这是正确的版本:
function encodeFile {
param ([string]$fileName)
[System.Convert]::ToBase64String([IO.File]::ReadAllBytes((Resolve-Path $fileName).ProviderPath))
}
我已经用问题更新了原始代码中的这个,所以请随意使用它。
我正在做一个 POC 来演示 DocuSign 以编程方式创建和路由包含一个简单文档的信封。我正在使用 PowerShell 和 JSON API。登录和创建信封工作毫无怨言,但发送给我签名的结果 Word 文档包含乱码。我相信我有正确的 base64 编码和 headers。关于我做错了什么的想法?
下面粘贴了整个POC。我刚刚删除了 ID、密码、集成商密钥等。谢谢!
function boundry {
[System.Guid]::NewGuid().ToString()
}
###this is the corrected code###
function encodeFile {
param ([string]$fileName)
[System.Convert]::ToBase64String([IO.File]::ReadAllBytes((Resolve-Path $fileName).ProviderPath))
}
function logonParams {
[string] $userName = 'DocuSign user name'
[string] $password = 'DocuSign password'
[string] $integratorKey = 'DocuSign Integrator Key'
@"
{
"Username" : "$userName",
"Password" : "$password",
"IntegratorKey" : "$integratorKey"
}
"@
}
function logon {
[string] $loginURL = 'https://demo.docusign.net/restapi/v2/login_information'
$headers =
@{
"X-DocuSign-Authentication"=$(logonParams);
"accept"="application/json";
"content-type"="application/json";
}
$r = Invoke-WebRequest -uri $loginURL -headers $headers -method GET
$responseInfo = $r.content | ConvertFrom-Json
$baseURL = $responseInfo.loginAccounts.baseURL
#return the base URL for the next call
$baseURL
}
function createEnvelope {
param ([string]$file1,
[string]$baseURL
)
[string]$boundry = boundry
$headers =
@{
"X-DocuSign-Authentication"=$(logonParams);
"accept"="application/json";
"content-type"="multipart/form-data; boundary=$boundry";
}
[string]$formData = @"
--$boundry
Content-Type: application/json
{
"status":"sent",
"emailBlurb":"Please sign.",
"emailSubject": "Contract $(date)",
"documents": [{
"name": "$file1",
"documentId":"1",
"order":"1"
}],
"recipients": {
"signers" : [{
"email": "recipient@somecompany.com",
"name": "Recipient Name",
"recipientId":"1",
}]
}
}
--$boundry
Content-Type: application/msword
Content-Transfer-Encoding: base64
Content-Disposition: file; filename="$file1";documentid=1
$(encodeFile $file1)
--$boundry--
"@
$envelopeURL = "$baseURL/envelopes"
Invoke-WebRequest -uri $envelopeURL -headers $headers -body $formData -method POST
}
$baseURL = logon
createEnvelope "test.doc" $baseURL
尝试更改您的 Content-Type header 值。我不确定 application/msword
在这里是否有效,我认为 .docx 的正确 mime-type 是
application/vnd.openxmlformats-officedocument.wordprocessingml.document
查看之前的 SO post 以获得更完整的 mime-type 列表:
我在 DocuSign 支持团队的帮助下解决了这个问题。您可以在 DocuSign 中启用服务器端日志记录,这非常有用。从旧 UI(自 15 年 6 月起在新 UI 中不可用)从 ID/photo 旁边的下拉列表中选择首选项。然后select左边会员选项下的权限。检查 "Enable API Request Logging." 在您 运行 测试之后,下载 API 请求日志按钮变为活动状态。
从日志中可以很清楚地看出我的编码有误。这是正确的版本:
function encodeFile {
param ([string]$fileName)
[System.Convert]::ToBase64String([IO.File]::ReadAllBytes((Resolve-Path $fileName).ProviderPath))
}
我已经用问题更新了原始代码中的这个,所以请随意使用它。