Docusign无法使用Docusign Api发布模板

时间:2016-02-01 09:44:57

标签: docusignapi

我试图在docusign api上发布模板,但唯一的反应是错误的请求,这里是我如何发布数据和文件(php和guzzle 5)

$data = [
        'emailsubject' => 'Agreement for ' . $config['deal_name'],
        'documents' => [
          [
            'name' => $config['deal_name'],
            'documentId' => $config['deal_id']
          ]
        ],
        'recipients' => [
            'signers' =>
            [
              [
                'roleName' => Config::get('templateRoleName')
              ]
            ]
        ],
        'envelopeTemplateDefinition' => [
            'name' => $config['deal_name'],
        ],
        new \GuzzleHttp\Post\PostFile($config['deal_name'], Flysystem::readStream($config['doc_path'])),
    ];

    $res = $this->client->createRequest('POST',"$this->baseUrl/templates", [
        'headers' => [
            'Content-Type' => 'multipart/form-data',
            'X-DocuSign-Authentication' => json_encode([
                'Username' => Config::get('docusign.email'),
                'Password' => Config::get('docusign.password'),
                'IntegratorKey' => Config::get('docusign.integratorKey')
            ]),
        ],
        'body' => [
          'emailsubject' => 'Agreement for ' . $config['deal_name'],
          'documents' => [
            [
              'name' => $config['deal_name'],
              'documentId' => $config['deal_id']
            ]
          ],
          'recipients' => [
              'signers' =>
              [
                [
                  'roleName' => Config::get('templateRoleName')
                ]
              ]
          ],
          'envelopeTemplateDefinition' => [
              'name' => $config['deal_name'],
              'shared' => false
          ],
          new \GuzzleHttp\Post\PostFile($config['deal_name'], Flysystem::readStream($config['doc_path'])),
        ]
    ]);


    $response = $this->client->send($res);

我认为该请求与https://www.docusign.com/p/RESTAPIGuide/RESTAPIGuide.htm#REST API参考/帖子模板中的请求相同。%3FTocPath%3DREST%2520API%2520References%7C _____ 130

我已经实现了登录,从信封ID发送签名请求,但卡在帖子模板上(上传数据和PDF格式),我错过了什么? 这是错误回复

Client error response [url] https://demo.docusign.net/restapi/v2/accounts/asdfaccountId/templates [status code] 400 [reason phrase] Bad Request

此处发布到docusign api的数据(文件部分已截断)

POST /restapi/v2/accounts/blablaAccountId/templates HTTP/1.1 Host: demo.docusign.net Content-Type: application/json X-DocuSign-Authentication: {"Username":"blabla@blabla.com","Password":"blabla","IntegratorKey":"blabla"} User-Agent: Guzzle/5.3.0 curl/7.35.0 PHP/5.6.17-3+deb.sury.org~trusty+1 --56af2bf9b3fb2 Content-Disposition: form-data; name="emailsubject" Agreement for asdf --56af2bf9b3fb2 Content-Disposition: form-data; name="documents[0][name]" asdf --56af2bf9b3fb2 Content-Disposition: form-data; name="documents[0][documentId]" asdf --56af2bf9b3fb2 Content-Disposition: form-data; name="envelopeTemplateDefinition[name]" asdf --56af2bf9b3fb2 Content-Disposition: form-data; name="envelopeTemplateDefinition[shared]" --56af2bf9b3fb2 Content-Disposition: form-data; name="asdf"; filename="f2EQySRYpYyGngxuw0bM" 

1 个答案:

答案 0 :(得分:0)

最后,我想通了。我错过了错误消息。当用于创建模板的发布字段数据时,需要recipientId

        'recipients' => [
            'signers' =>
            [
              [
                'roleName' => Config::get('templateRoleName'),
                  //it will not work if recipient id is not set
                'recipientId' => 1,
              ]
            ]
        ],

然而另一件有趣的事情发生了,我们还需要提供表格边界,

因为我无法通过guzzle设置它,所以我硬编码请求体。 这是我的代码,希望它可以帮助某人。

https://gist.github.com/nsulistiyawan/9ffcc04bc54aa93b574a