DocuSign Bulk Send场景下,如何批量下载指定批次已完成PDF文件?
解决方案
Docusign确实没有直接批量下载特定Bulk Send批次已完成PDF的单一API,但可以通过两步API调用实现需求:
步骤1:获取目标批次的已完成信封ID列表
调用Bulk Send批次的信封列表接口,筛选出状态为completed的信封:
GET /v2.1/accounts/{accountId}/bulk_send/batches/{batchId}/envelopes?status=completed
如果批次内信封数量较多,接口会返回分页结果,需要通过响应中的nextUri参数遍历所有分页数据,收集所有符合条件的envelopeId。
步骤2:批量下载每个已完成信封的合并PDF
对步骤1收集到的每个envelopeId,调用信封合并文档下载接口:
GET /v2.1/accounts/{accountId}/envelopes/{envelopeId}/documents/combined
你可以写个简单的脚本自动化这个过程,比如Python示例:
import requests account_id = "你的账户ID" batch_id = "目标批次ID" access_token = "你的API令牌" base_url = "https://demo.docusign.net/restapi" # 生产环境替换为https://www.docusign.net/restapi # 步骤1:获取已完成信封ID envelope_ids = [] next_uri = f"/v2.1/accounts/{account_id}/bulk_send/batches/{batch_id}/envelopes?status=completed" while next_uri: response = requests.get( base_url + next_uri, headers={"Authorization": f"Bearer {access_token}"} ) response_data = response.json() envelope_ids.extend([env["envelopeId"] for env in response_data["envelopes"]]) next_uri = response_data.get("nextUri") # 步骤2:批量下载PDF for env_id in envelope_ids: pdf_response = requests.get( f"{base_url}/v2.1/accounts/{account_id}/envelopes/{env_id}/documents/combined", headers={"Authorization": f"Bearer {access_token}"} ) with open(f"completed_envelope_{env_id}.pdf", "wb") as f: f.write(pdf_response.content)
注意事项
- 确保你的API令牌有信封读取和文档下载的权限,管理员权限通常满足要求。
- 生产环境和沙箱环境的API base URL不同,注意替换。
- 可以根据需求修改文件命名规则,比如加入收件人姓名或邮件,方便区分。
内容的提问来源于stack exchange,提问作者Chirantan Kar
相关产品推荐
相关产品推荐

