douluan5444 2018-10-03 12:43
浏览 38
已采纳

DocuSign - 无法在createEnvelope上设置“已发送”

I am using Docusign PHP Client and trying to create and envelope and send it as email. With the current SDK, I was getting an error:

INVALID_REQUEST_BODY The request body is missing or improperly formatted. Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'API_REST.Models.v2.document[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. ◀ To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive t ▶ Path 'documents.documentBase64', line 1, position 31.

So I had to edit EnvelopeApi.php (line 2876) json_encode($httpBody) to make it work.


Now that it's working, I receive a response like this, however I can't change status created to sent is my problem.

EnvelopeSummary {#460 ▼
  #container: array:4 [▼
    "envelope_id" => "6b9ef863-2ee0-4ea6-9f7e-20b7d4f59b22"
    "status" => "created"
    "status_date_time" => "2018-10-03T12:30:22.8600000Z"
    "uri" => "/envelopes/6b9ef863-2ee0-4ea6-9f7e-20b7d4f59b22"
  ]
}

My full code:

First, I authenticated and fetched my $accountId

And then creating Envelope:

$path = public_path('test.pdf');
$b64Doc = base64_encode(file_get_contents($path));

$document = new Document();
$document->setName("TEST.pdf");
$document->setFileExtension("pdf");
$document->setDocumentId(1);
$document->setDocumentBase64($b64Doc);

$sign_here = new SignHere();
$sign_here->setXPosition(25);
$sign_here->setYPosition(50);
$sign_here->setDocumentId(1);
$sign_here->setPageNumber(1);
$sign_here->setRecipientId(1);

$tabs = new Tabs();
$tabs->setSignHereTabs($sign_here);

$signers = new Signer();
$signers->setName('Test User');
$signers->setEmail('test@mailinator.com');
$signers->setRoleName('Signer');
$signers->setRecipientId(1);
$signers->setRoutingOrder(1);
$signers->setTabs($tabs);

$recipients = new Recipients();
$recipients->setSigners($signers);

$envelope_definition = new EnvelopeDefinition();
$envelope_definition->setEmailSubject('Signature Request');
$envelope_definition->setStatus("sent"); // ***
$envelope_definition->setDocuments($document);
$envelope_definition->setRecipients($recipients);

$options = new CreateEnvelopeOptions();
$options->setCdseMode(null);
$options->setMergeRolesOnDraft(null);

try {
   $envelopeSummary = $envelopeApi->createEnvelope($accountId, $envelope_definition, $options);
   dd($envelopeSummary);

   // Also tried this:
   // $envelopeApi->update($accountId, $envelopeSummary->getEnvelopeId(), json_encode(['status' => 'sent']);

 } catch (ApiException $e){
     dd($e->getResponseBody()->errorCode . " " . $e->getResponseBody()->message);
}

$envelope_definition->setStatus("sent"); this should trigger the email, right? But it doesn't for some reason. Also I can't see this created envelope in my Sandbox either.

  • 写回答

3条回答 默认 最新

  • duanlvji4780 2018-10-04 06:27
    关注

    You are not setting signers correctly. It must be an array of signer objects.

    Here is some untested code:

    # This code creates a signer, not signers
    $signer = new Signer();
    $signer->setName('Test User');
    $signer->setEmail('test@mailinator.com');
    $signer->setRoleName('Signer');
    $signer->setRecipientId(1);
    $signer->setRoutingOrder(1);
    $signer->setTabs($tabs);
    
    $recipients = new Recipients();
    # setSigners wants an array of signer objects.
    # in this case, we make an array with one element
    $recipients->setSigners(array($signer));
    

    Also, you are not creating the tabs right either. Again, it needs to be an array of the tab type.

    See this example for additional ideas.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?