fix(verify): look up actual template role names before sending envelope
Hardcoded "Signer" roleName caused envelopes to send without tags. Now fetches template recipients first and assigns test recipient to every role, falling back to "Signer" only if the template fetch fails. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5cf415d38a
commit
374d1d10d0
|
|
@ -42,28 +42,43 @@ async def send_test_envelope(body: SendRequest, request: Request):
|
||||||
if err:
|
if err:
|
||||||
return err
|
return err
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {session['docusign_access_token']}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
base = f"{settings.docusign_base_url}/v2.1/accounts/{settings.docusign_account_id}"
|
||||||
|
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
# Fetch template to discover actual role names
|
||||||
|
tpl_resp = await client.get(f"{base}/templates/{body.template_id}", headers=headers)
|
||||||
|
role_names = []
|
||||||
|
if tpl_resp.is_success:
|
||||||
|
tpl = tpl_resp.json()
|
||||||
|
recipients = tpl.get("recipients", {})
|
||||||
|
for group in recipients.values():
|
||||||
|
if isinstance(group, list):
|
||||||
|
for r in group:
|
||||||
|
rn = r.get("roleName")
|
||||||
|
if rn and rn not in role_names:
|
||||||
|
role_names.append(rn)
|
||||||
|
|
||||||
|
# Fall back to generic role name if template fetch failed
|
||||||
|
if not role_names:
|
||||||
|
role_names = ["Signer"]
|
||||||
|
|
||||||
|
template_roles = [
|
||||||
|
{"email": body.recipient_email, "name": body.recipient_name, "roleName": rn}
|
||||||
|
for rn in role_names
|
||||||
|
]
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"templateId": body.template_id,
|
"templateId": body.template_id,
|
||||||
"status": "sent",
|
"status": "sent",
|
||||||
"templateRoles": [
|
"templateRoles": template_roles,
|
||||||
{
|
"emailSubject": "[Verification Test] Please sign this document",
|
||||||
"email": body.recipient_email,
|
|
||||||
"name": body.recipient_name,
|
|
||||||
"roleName": "Signer",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"emailSubject": f"[Verification Test] Please sign this document",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
resp = await client.post(f"{base}/envelopes", headers=headers, json=payload)
|
||||||
resp = await client.post(
|
|
||||||
f"{settings.docusign_base_url}/v2.1/accounts/{settings.docusign_account_id}/envelopes",
|
|
||||||
headers={
|
|
||||||
"Authorization": f"Bearer {session['docusign_access_token']}",
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
json=payload,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not resp.is_success:
|
if not resp.is_success:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
|
@ -72,7 +87,7 @@ async def send_test_envelope(body: SendRequest, request: Request):
|
||||||
)
|
)
|
||||||
|
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
return {"envelope_id": data.get("envelopeId")}
|
return {"envelope_id": data.get("envelopeId"), "roles": role_names}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/status/{envelope_id}")
|
@router.get("/status/{envelope_id}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue