"The validation of the PDF file failed." 尝试通过电子邮件发送签名请求时 - docusign

"The validation of the PDF file failed." when trying to send signing request via email - docusign

****编辑:感谢这些链接,@Hackerman。我能够在 Postman 中使用它,然后使用 Docusign 邮递员示例在 Powershell 中使用它。但是我无法让它与我自己的 PDF 文档一起使用。我怀疑这是因为我没有正确地将我的 PDF 转换为 Base64。有人知道如何通过 Powershell 完成此操作吗?****

EDIT2:能够使用这个简单的 1-liner 通过 powershell 将我的 PDF 编码为 Base64 $docEncodedBase64 = [Convert]::ToBase64String((Get-Content $PDFPath -Encoding Byte))

我们正在尝试使用 Powershell 5.0(和 invoke-restmethod cmdlet)向 docusign REST API 发出请求,以便通过电子邮件发送签名请求。

在我的测试中,我一直遵循这个指南:https://docs.docusign.com/esign/guide/usage/request_a_signature.html#prepare-the-document-to-send-through-docusign 但是当我发送 POST 请求时出现错误

我们正在走正常请求的路线(即,不是多部分请求),因此以 base64 编码格式的字节形式提供 PDF 文档作为 documentBase64 属性 的值。

这是我将 PDF 转换为 base64 字节的代码:

# PDF document
$docContent = Get-Content 'Mutual_NDA.pdf'

# PDF as bytes
$docBytes = [System.Text.Encoding]::Unicode.GetBytes($docContent)

# PDF as Base-64 Encoded bytes
$docEncoded = [System.Convert]::ToBase64String($docBytes)

然后我定义我的 JSON 负载,它将作为 POST 请求中的正文发送。在这里,我将 'documentBase64' 属性 设置为我刚刚在上面转换的 base64 编码字符串。

# JSON payload
$jsonPayload = @"
{
    "documents": [
        {
            **"documentBase64": "$docEncoded"**,
            "documentId": "1",
            "fileExtension": "pdf",
            "name": "Mutual_NDA.pdf"        
        }
     ],
     "emailSubject": "Please sign the NDA",
     "recipients": {
         "signers": [
            {
                "email": "the_nda_signer@mailinator.com",
                "name": "Tester test",
                "recipientId": "1",
                "routingOrder": "1",
                "tabs": {
                    "dateSignedTabs": [
                        {
                            "anchorString": "signer1date",
                            "anchorYOffset": "-6",
                            "fontSize": "Size12",
                            "name": "Date Signed",
                            "recipientId": "1",
                            "tabLabel": "date_signed"
                        }
                    ],
                    "fullNameTabs": [
                        {
                            "anchorString": "signer1name",
                            "anchorYOffset": "-6",
                            "fontSize": "Size12",
                            "name": "Full Name",
                            "recipientId": "1",
                            "tabLabel": "Full Name"    
                        }
                    ],
                    "signHereTabs": [
                        {
                            "anchorString": "signer1sig",
                            "anchorUnits": "mms",
                            "anchorXOffset": "0",
                            "anchorYOffset": "0",
                            "name": "Please sign here",
                            "optional": "false",
                            "recipientId": "1",
                            "scaleValue": 1,
                            "tabLabel": "signer1sig" 
                        }
                    ]
                } 
            }
        ]
     },
     "status": "sent"                
}
"@

最后,HTTP 请求:

$Envelope = Invoke-RestMethod -uri ($BaseURL + '/envelopes') -Method Post -Body $jsonPayload -ContentType 'application/json' -Headers @{"X-Docusign-Authentication" = $XMLHeader} 

有人有这方面的经验吗?也许我将 PDF 编码为 base64 不正确?我真的被困住了。任何帮助表示赞赏! 谢谢,

埃里克

我的 PDF 没有正确转换为 Base64。在 Powershell 中使用这行代码,我能够成功地创建并发送一个信封

$docEncodedBase64 = [Convert]::ToBase64String((Get-Content $PDFPath -Encoding Byte))

感谢@Hackerman 引用 Postman!