如何在DocuSign PowerForms/Templates上配置eventNotification

2024-09-30 20:29:25 发布

您现在位置:Python中文网/ 问答频道 /正文

问题

我希望通过一个DocuSign模板/PowerForm创建的所有文档都配置一个webhook,这样我就不需要continuously poll every 15 minutes来获得完整的文档。我读了很多书,想知道在docusignapi中这是否可行。在

背景

我有一个自助放弃文档:用户导航到一个URL,填写他们的联系信息(即定义一个接收者角色),并期望他们完成的放弃被链接的系统识别。在

我有一个正在PowerForm中使用的DocuSign template:用户导航到PowerForm的URL,PowerForm将允许他们从相关联的模板创建一个新的信封。在

我希望通过标准的webhook,此安装程序创建的文档在完成时自动通知HTTPS端点。在

尝试解决方案

^{}方法(POST /v2/accounts/{accountId}/envelopes)接受可用于配置webhook的eventNotification参数。webhook recipe很好地涵盖了这个端点的用法。这将解决我的问题,如果我是通过一个API请求创建每个信封,但我喜欢PowerForm附带的一个可复制的可传递URL的简单性。在

虽然没有文档记录,但是^{}PUT /v2/accounts/{accountId}/envelopes/{envelopeId})可能支持在已经创建的信封上配置通知。我可以重复使用query the most current envelopes作为模板,更新正在处理的信封上的通知并处理已完成的通知,但这并不比轮询更好。在

我浏览了REST API,特别是Templates和{a11}类别,但是我没有看到任何明显的方法来配置这两个资源以在创建的信封上设置eventNotification。在

下面是我所做的一些API探索的快速代码转储:

#!/usr/bin/env python3
import requests


username = 'user@example.com'
password = 'some-sensitive-password'
integrator_key = 'abcdef01-2345-6789-0abcdef0123456789'


# Authenticate to the DocuSign API, get the base URL for subsequent requests
authenticate_str = (
    "<DocuSignCredentials>"
    "<Username>" + username + "</Username>"
    "<Password>" + password + "</Password>"
    "<IntegratorKey>" + integrator_key + "</IntegratorKey>"
    "</DocuSignCredentials>"
)
headers = {'X-DocuSign-Authentication': authenticate_str,
           'Accept': 'application/json'}
api_base = 'https://demo.docusign.net/restapi/v2/'
resp = requests.get(api_base + 'login_information', headers=headers)
base_url = resp.json()['loginAccounts'][0]['baseUrl']

# Identify all templates in my account
resp = requests.get(base_url + '/templates', headers=headers)
all_templates = resp.json()['envelopeTemplates']

# (Find my template, explore ways I could modify it with PUT, etc.)
template_id = find_desired_template(all_templates)
resp = requests.get(base_url + '/templates/{}'.format(template_id), headers=headers)

# Find just status changed envelopes from some recent date/datetime
resp = requests.get(base_url + '/envelopes',
                    params={'from_date': '2018-01-26'}, headers=headers)

# Configure just a single envelope to have push notifications
envelope_id = resp.json()['envelopes'][0]['envelopeId']

# Configure this _one_ envelope to notify us when completed.
# WARNING: This isn't repeatable: The next auto-created envelope won't work
event_notification = {
    "url": "https://my-own-api.example.com/some/endpoint",
    "loggingEnabled": "true",
    "requireAcknowledgment": "true",
    "useSoapInterface": "false",
    "includeCertificateWithSoap": "false",
    "signMessageWithX509Cert": "false",
    "includeDocuments": "true",
    "includeEnvelopeVoidReason": "true",
    "includeTimeZone": "true",
    "includeSenderAccountAsCustomField": "true",
    "includeDocumentFields": "true",
    "includeCertificateOfCompletion": "true",

    # Only notify on completion
    "envelopeEvents": [
        {"envelopeEventStatusCode": "completed"}
    ],
    "recipientEvents": [
        {"recipientEventStatusCode": "Completed"},
    ],
}

requests.put(base_url + '/envelopes/{}'.format(envelope_id),
             headers=headers,
             json={'eventNotification': event_notification})

约束

我的帐户没有配置为具有DocuSign Connect,这将允许我在帐户中的文档每完成一次时通知HTTPS端点。我使用的是共享帐户(使用其他不相关的信封/模板),所以这不是一个理想的解决方案。在


Tags: 文档jsontrueurlbasegettemplaterequests
1条回答
网友
1楼 · 发布于 2024-09-30 20:29:25

出于业务原因,如果购买了帐户级别的Connect选项,Connect webhook只能与所有信封(或模板/powerform中的所有信封)关联。它可以作为许多帐户类型的附加组件提供。在

在这种情况下,正如您所提到的,您的webhook侦听器将收到它不感兴趣的信封事件通知。对于这些通知消息,响应200(已接收),然后丢弃该信息。在

相关问题 更多 >