使用复合模板进行远程签名会出现 TEMPLATE_NOT_PROVIDED 错误
remote signing with composite templates gets TEMPLATE_NOT_PROVIDED error
我正在尝试创建一个远程签名信封,其中包含一个预定义模板和一个我即时生成的 pdf。为此,我使用了 2 个组合在一起的复合模板,如前所述 here。
出于某种原因,当我尝试发送信封时,我从 api:
收到错误消息
{"errorCode":"TEMPLATE_NOT_PROVIDED","message":"Template was not provided."}
尽管我在使用 ServerTemplate 的第一个 CompositeTemplate 中指定了 template_id。
这是我的 python 代码:
def create_composite_envelope(self, args, return_env=True)):
"""
Creates and returns an envelope definition
The envelope request object uses Composite Template to
include in the envelope:
1. A template stored on the DocuSign service
"""
signer1 = Signer(
email=args['signer_email'],
name=args['signer_name'],
role_name="Signer",
recipient_id="1",
routing_order="1",
tabs=args['tabs'],
# Adding clientUserId transforms the template recipient
# into an embedded recipient:
client_user_id=args['signer_client_id']
)
# Recipients object:
recipients_server_template = Recipients(signers=[signer1])
# 2. create a composite template for the Server template + roles
comp_template1 = CompositeTemplate(
composite_template_id="1",
server_templates=[
ServerTemplate(sequence="1", template_id=args['template_id'])
],
# Add the roles via an inlineTemplate
inline_templates=[
InlineTemplate(sequence="2",
recipients=recipients_server_template)
]
)
if not return_env:
return comp_template1
# 3. create the envelope definition with the composited templates
envelope_definition = EnvelopeDefinition(
status="sent",
composite_templates=[comp_template1]
)
return envelope_definition
def generate_documents_envelope(self, payload: dict, file_location: str, envelope_id=None):
# First we create the envelope definition that contains the template
comp_template1 = self.create_composite_envelope(payload)
# Now we need to create the envelope that holds the pdf we generated earlier.
# READING FILES
with open(path.join(file_location), "rb") as file:
doc_pdf_bytes = file.read()
doc_b64 = base64.b64encode(doc_pdf_bytes).decode("ascii")
# create the DocuSign document object
document = Document(
document_base64=doc_b64,
name="Application Form", # can be different from actual file name
file_extension="pdf", # many different document types are accepted
document_id="1" # a label used to reference the doc
)
# Create the signer recipient model
signer1 = Signer(
email=payload['signer_email'],
name=payload['signer_name'],
recipient_id="1",
routing_order="1",
role_name="Signer"
)
# Create signHere fields (also known as tabs) on the documents,
# We"re using anchor (autoPlace) positioning
sign_here1 = SignHere(
anchor_string="**signature**",
anchor_units="pixels",
anchor_y_offset="20",
anchor_x_offset="10",
width=130,
height=40
)
full_name = Text(
anchor_string="**name**",
anchor_units="pixels",
anchor_y_offset="0",
anchor_x_offset="0",
width=134,
height=34,
font="helvetica",
font_size="size12"
)
date = Date(
anchor_string="**date**",
anchor_units="pixels",
anchor_y_offset="10",
anchor_x_offset="20",
width=100,
height=28,
font="helvetica",
font_size="size12",
value=datetime.now().strftime("%d-%m-%Y"),
locked="true"
)
# Add the tabs model (including the sign_here tabs) to the signer
# The Tabs object wants arrays of the different field/tab types
signer1.tabs = Tabs(sign_here_tabs=[sign_here1], text_tabs=[full_name], date_tabs=[date])
recipients = Recipients(signers=[signer1])
comp_template2 = CompositeTemplate(
composite_template_id="2",
inline_templates=[
InlineTemplate(sequence="1", recipients=recipients)
],
document=document
)
# 7. create the envelope definition with the composited templates
envelope_definition = EnvelopeDefinition(
status="sent",
envelope_id=envelope_id,
composite_templates=[comp_template1, comp_template2]
)
return envelope_definition
以及创建和发送信封定义的最终方法:
def send_envelope(self, envelope_definition):
"""
Send the envelope attached
"""
# Send the envelope
api_client = ApiClient()
api_client.host = self.base_path
api_client.set_default_header("Authorization", "Bearer " + self.ds_access_token)
envelope_api = EnvelopesApi(api_client)
results = envelope_api.create_envelope(self.account_id, envelope_definition=envelope_definition)
return {'envelope_id': results.envelope_id}
第一个问题 - 您需要在 create_composite_envelope 方法中 return 复合对象本身,而不是信封定义。
第二个问题 - 如果您想要发送电子邮件,请不要设置用于 embedded signing 的 client_user_id 值。
我正在尝试创建一个远程签名信封,其中包含一个预定义模板和一个我即时生成的 pdf。为此,我使用了 2 个组合在一起的复合模板,如前所述 here。 出于某种原因,当我尝试发送信封时,我从 api:
收到错误消息{"errorCode":"TEMPLATE_NOT_PROVIDED","message":"Template was not provided."}
尽管我在使用 ServerTemplate 的第一个 CompositeTemplate 中指定了 template_id。
这是我的 python 代码:
def create_composite_envelope(self, args, return_env=True)):
"""
Creates and returns an envelope definition
The envelope request object uses Composite Template to
include in the envelope:
1. A template stored on the DocuSign service
"""
signer1 = Signer(
email=args['signer_email'],
name=args['signer_name'],
role_name="Signer",
recipient_id="1",
routing_order="1",
tabs=args['tabs'],
# Adding clientUserId transforms the template recipient
# into an embedded recipient:
client_user_id=args['signer_client_id']
)
# Recipients object:
recipients_server_template = Recipients(signers=[signer1])
# 2. create a composite template for the Server template + roles
comp_template1 = CompositeTemplate(
composite_template_id="1",
server_templates=[
ServerTemplate(sequence="1", template_id=args['template_id'])
],
# Add the roles via an inlineTemplate
inline_templates=[
InlineTemplate(sequence="2",
recipients=recipients_server_template)
]
)
if not return_env:
return comp_template1
# 3. create the envelope definition with the composited templates
envelope_definition = EnvelopeDefinition(
status="sent",
composite_templates=[comp_template1]
)
return envelope_definition
def generate_documents_envelope(self, payload: dict, file_location: str, envelope_id=None):
# First we create the envelope definition that contains the template
comp_template1 = self.create_composite_envelope(payload)
# Now we need to create the envelope that holds the pdf we generated earlier.
# READING FILES
with open(path.join(file_location), "rb") as file:
doc_pdf_bytes = file.read()
doc_b64 = base64.b64encode(doc_pdf_bytes).decode("ascii")
# create the DocuSign document object
document = Document(
document_base64=doc_b64,
name="Application Form", # can be different from actual file name
file_extension="pdf", # many different document types are accepted
document_id="1" # a label used to reference the doc
)
# Create the signer recipient model
signer1 = Signer(
email=payload['signer_email'],
name=payload['signer_name'],
recipient_id="1",
routing_order="1",
role_name="Signer"
)
# Create signHere fields (also known as tabs) on the documents,
# We"re using anchor (autoPlace) positioning
sign_here1 = SignHere(
anchor_string="**signature**",
anchor_units="pixels",
anchor_y_offset="20",
anchor_x_offset="10",
width=130,
height=40
)
full_name = Text(
anchor_string="**name**",
anchor_units="pixels",
anchor_y_offset="0",
anchor_x_offset="0",
width=134,
height=34,
font="helvetica",
font_size="size12"
)
date = Date(
anchor_string="**date**",
anchor_units="pixels",
anchor_y_offset="10",
anchor_x_offset="20",
width=100,
height=28,
font="helvetica",
font_size="size12",
value=datetime.now().strftime("%d-%m-%Y"),
locked="true"
)
# Add the tabs model (including the sign_here tabs) to the signer
# The Tabs object wants arrays of the different field/tab types
signer1.tabs = Tabs(sign_here_tabs=[sign_here1], text_tabs=[full_name], date_tabs=[date])
recipients = Recipients(signers=[signer1])
comp_template2 = CompositeTemplate(
composite_template_id="2",
inline_templates=[
InlineTemplate(sequence="1", recipients=recipients)
],
document=document
)
# 7. create the envelope definition with the composited templates
envelope_definition = EnvelopeDefinition(
status="sent",
envelope_id=envelope_id,
composite_templates=[comp_template1, comp_template2]
)
return envelope_definition
以及创建和发送信封定义的最终方法:
def send_envelope(self, envelope_definition):
"""
Send the envelope attached
"""
# Send the envelope
api_client = ApiClient()
api_client.host = self.base_path
api_client.set_default_header("Authorization", "Bearer " + self.ds_access_token)
envelope_api = EnvelopesApi(api_client)
results = envelope_api.create_envelope(self.account_id, envelope_definition=envelope_definition)
return {'envelope_id': results.envelope_id}
第一个问题 - 您需要在 create_composite_envelope 方法中 return 复合对象本身,而不是信封定义。
第二个问题 - 如果您想要发送电子邮件,请不要设置用于 embedded signing 的 client_user_id 值。