# Python3 Quick start example: embedded signing ceremony.
# Copyright (c) 2018 by DocuSign, Inc.
# License: The MIT License -- https://opensource.org/licenses/MIT

import base64, os
from flask import Flask, request, redirect
from docusign_esign import ApiClient, EnvelopesApi, EnvelopeDefinition, Signer, SignHere, Tabs, Recipients, Document, RecipientViewRequest, ServerTemplate, InlineTemplate, CompositeTemplate

# Settings
# Fill in these constants
#
# Obtain an OAuth access token from https://developers.hqtest.tst/oauth-token-generator
access_token = os.environ["DOCUSIGN_OAUTH"]
# Obtain your accountId from demo.docusign.com -- the account id is shown in the drop down on the
# upper right corner of the screen by your picture or the default picture.
account_id = os.environ["DOCUSIGN_ACC_ID"]
# Recipient Information:
signer_name = 'Alice Chang'
signer_email = 'changvalice@gmail.com'
# The document you wish to send. Path is relative to the root directory of this repo.
file_name_path = 'World_Wide_Corp_lorem.pdf'
# The url of this web application
base_url = 'http://localhost:5000'
client_user_id = '123' # Used to indicate that the signer will use an embedded
                       # Signing Ceremony. Represents the signer's userId within
                       # your application.
authentication_method = 'None' # How is this application authenticating
                               # the signer? See the `authenticationMethod' definition
                               # https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeViews/createRecipient
template_ids = [id for id in os.environ["DOCUSIGN_TEMPLATE_IDS"].split(",")]

# The API base_path
base_path = 'https://demo.docusign.net/restapi'

# Constants
APP_PATH = os.path.dirname(os.path.abspath(__file__))

def embedded_signing_ceremony():
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """

    #
    # Step 1. The envelope definition is created.
    #         One signHere tab is added.
    #         The document path supplied is relative to the working directory
    #
    with open(os.path.join(APP_PATH, file_name_path), "rb") as file:
        content_bytes = file.read()
    base64_file_content = base64.b64encode(content_bytes).decode('ascii')

    # Create the document model
    document = Document( # create the DocuSign document object
        document_base64 = base64_file_content,
        name = 'Example document', # 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
    signer = Signer( # The signer
        email = signer_email, name = signer_name, recipient_id = "1", routing_order = "1",
        client_user_id = client_user_id, # Setting the client_user_id marks the signer as embedded
    )

    # Create a sign_here tab (field on the document)
    sign_here = SignHere( # DocuSign SignHere field/tab
        document_id = '1', page_number = '1', recipient_id = '1', tab_label = 'SignHereTab',
        x_position = '195', y_position = '147')

    # Add the tabs model (including the sign_here tab) to the signer
    signer.tabs = Tabs(sign_here_tabs = [sign_here]) # The Tabs object wants arrays of the different field/tab types

    # Next, create the top level envelope definition and populate it.
    envelope_definition = EnvelopeDefinition(
        email_subject = "Please sign this document sent from the Python SDK",
        documents = [document], # The order in the docs array determines the order in the envelope
        recipients = Recipients(signers = [signer]), # The Recipients object wants arrays for each recipient type
        status = "sent" # requests that the envelope be created and sent.
    )

    #
    #  Step 2. Create/send the envelope.
    #
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header("Authorization", "Bearer " + access_token)

    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=envelope_definition)

    #
    # Step 3. The envelope has been created.
    #         Request a Recipient View URL (the Signing Ceremony URL)
    #
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(
        authentication_method = authentication_method, client_user_id = client_user_id,
        recipient_id = '1', return_url = base_url + '/dsreturn',
        user_name = signer_name, email = signer_email
    )

    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request = recipient_view_request)

    #
    # Step 4. The Recipient View URL (the Signing Ceremony URL) has been received.
    #         Redirect the user's browser to it.
    #
    return results.url

def get_signing_redirect(template_num):
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """

    # Create the signer recipient model
    signer = Signer( # The signer
        email = signer_email, name = signer_name, recipient_id = "1",
        client_user_id = client_user_id, role_name = "doctor"# Setting the client_user_id marks the signer as embedded
    )

    # Create the server and inline templates for the envelope

    server_template1 = ServerTemplate(
        sequence = "1",
        template_id = template_ids[0]
    )

    server_template2 = ServerTemplate(
        sequence = "2",
        template_id = template_ids[1]
    )

    inline_template = InlineTemplate(
        sequence = "3",
        recipients = Recipients(signers = [signer])
    )

    # Create the composite template
    composite_template1 = CompositeTemplate(
        inline_templates = [inline_template],
        server_templates = [server_template1]
    )

    composite_template2 = CompositeTemplate(
        inline_templates = [inline_template],
        server_templates = [server_template2]
    )

    composite_templates = [composite_template1] if template_num == 0 else [composite_template2] if template_num == 1 else [composite_template1, composite_template2]

    # Next, create the top level envelope definition and populate it.
    envelope_definition = EnvelopeDefinition(
        email_subject = "Please sign this document sent from the Python SDK",
        composite_templates = composite_templates,
        status = "sent" # requests that the envelope be created and sent.
    )

    #
    #  Step 2. Create/send the envelope.
    #
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header("Authorization", "Bearer " + access_token)

    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=envelope_definition)

    #
    # Step 3. The envelope has been created.
    #         Request a Recipient View URL (the Signing Ceremony URL)
    #
    redirect_url = base_url + '/signing_complete' if template_num == 0 else base_url + '/report_complete'
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(
        authentication_method = authentication_method, client_user_id = client_user_id,
        recipient_id = '1', return_url = redirect_url,
        user_name = signer_name, email = signer_email
    )

    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request = recipient_view_request)

    #
    # Step 4. The Recipient View URL (the Signing Ceremony URL) has been received.
    #         Redirect the user's browser to it.
    #
    return results.url

c3beb73c9c5369eda480c5c925fcbc9049910cd4
<mask token>


def embedded_signing_ceremony():
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """
    with open(os.path.join(APP_PATH, file_name_path), 'rb') as file:
        content_bytes = file.read()
    base64_file_content = base64.b64encode(content_bytes).decode('ascii')
    document = Document(document_base64=base64_file_content, name=
        'Example document', file_extension='pdf', document_id=1)
    signer = Signer(email=signer_email, name=signer_name, recipient_id='1',
        routing_order='1', client_user_id=client_user_id)
    sign_here = SignHere(document_id='1', page_number='1', recipient_id='1',
        tab_label='SignHereTab', x_position='195', y_position='147')
    signer.tabs = Tabs(sign_here_tabs=[sign_here])
    envelope_definition = EnvelopeDefinition(email_subject=
        'Please sign this document sent from the Python SDK', documents=[
        document], recipients=Recipients(signers=[signer]), status='sent')
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header('Authorization', 'Bearer ' + access_token)
    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=
        envelope_definition)
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(authentication_method=
        authentication_method, client_user_id=client_user_id, recipient_id=
        '1', return_url=base_url + '/dsreturn', user_name=signer_name,
        email=signer_email)
    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request=recipient_view_request)
    return results.url


<mask token>

<mask token>


def embedded_signing_ceremony():
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """
    with open(os.path.join(APP_PATH, file_name_path), 'rb') as file:
        content_bytes = file.read()
    base64_file_content = base64.b64encode(content_bytes).decode('ascii')
    document = Document(document_base64=base64_file_content, name=
        'Example document', file_extension='pdf', document_id=1)
    signer = Signer(email=signer_email, name=signer_name, recipient_id='1',
        routing_order='1', client_user_id=client_user_id)
    sign_here = SignHere(document_id='1', page_number='1', recipient_id='1',
        tab_label='SignHereTab', x_position='195', y_position='147')
    signer.tabs = Tabs(sign_here_tabs=[sign_here])
    envelope_definition = EnvelopeDefinition(email_subject=
        'Please sign this document sent from the Python SDK', documents=[
        document], recipients=Recipients(signers=[signer]), status='sent')
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header('Authorization', 'Bearer ' + access_token)
    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=
        envelope_definition)
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(authentication_method=
        authentication_method, client_user_id=client_user_id, recipient_id=
        '1', return_url=base_url + '/dsreturn', user_name=signer_name,
        email=signer_email)
    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request=recipient_view_request)
    return results.url


def get_signing_redirect(template_num):
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """
    signer = Signer(email=signer_email, name=signer_name, recipient_id='1',
        client_user_id=client_user_id, role_name='doctor')
    server_template1 = ServerTemplate(sequence='1', template_id=template_ids[0]
        )
    server_template2 = ServerTemplate(sequence='2', template_id=template_ids[1]
        )
    inline_template = InlineTemplate(sequence='3', recipients=Recipients(
        signers=[signer]))
    composite_template1 = CompositeTemplate(inline_templates=[
        inline_template], server_templates=[server_template1])
    composite_template2 = CompositeTemplate(inline_templates=[
        inline_template], server_templates=[server_template2])
    composite_templates = [composite_template1] if template_num == 0 else [
        composite_template2] if template_num == 1 else [composite_template1,
        composite_template2]
    envelope_definition = EnvelopeDefinition(email_subject=
        'Please sign this document sent from the Python SDK',
        composite_templates=composite_templates, status='sent')
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header('Authorization', 'Bearer ' + access_token)
    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=
        envelope_definition)
    redirect_url = (base_url + '/signing_complete' if template_num == 0 else
        base_url + '/report_complete')
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(authentication_method=
        authentication_method, client_user_id=client_user_id, recipient_id=
        '1', return_url=redirect_url, user_name=signer_name, email=signer_email
        )
    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request=recipient_view_request)
    return results.url

<mask token>
access_token = os.environ['DOCUSIGN_OAUTH']
account_id = os.environ['DOCUSIGN_ACC_ID']
signer_name = 'Alice Chang'
signer_email = 'changvalice@gmail.com'
file_name_path = 'World_Wide_Corp_lorem.pdf'
base_url = 'http://localhost:5000'
client_user_id = '123'
authentication_method = 'None'
template_ids = [id for id in os.environ['DOCUSIGN_TEMPLATE_IDS'].split(',')]
base_path = 'https://demo.docusign.net/restapi'
APP_PATH = os.path.dirname(os.path.abspath(__file__))


def embedded_signing_ceremony():
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """
    with open(os.path.join(APP_PATH, file_name_path), 'rb') as file:
        content_bytes = file.read()
    base64_file_content = base64.b64encode(content_bytes).decode('ascii')
    document = Document(document_base64=base64_file_content, name=
        'Example document', file_extension='pdf', document_id=1)
    signer = Signer(email=signer_email, name=signer_name, recipient_id='1',
        routing_order='1', client_user_id=client_user_id)
    sign_here = SignHere(document_id='1', page_number='1', recipient_id='1',
        tab_label='SignHereTab', x_position='195', y_position='147')
    signer.tabs = Tabs(sign_here_tabs=[sign_here])
    envelope_definition = EnvelopeDefinition(email_subject=
        'Please sign this document sent from the Python SDK', documents=[
        document], recipients=Recipients(signers=[signer]), status='sent')
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header('Authorization', 'Bearer ' + access_token)
    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=
        envelope_definition)
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(authentication_method=
        authentication_method, client_user_id=client_user_id, recipient_id=
        '1', return_url=base_url + '/dsreturn', user_name=signer_name,
        email=signer_email)
    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request=recipient_view_request)
    return results.url


def get_signing_redirect(template_num):
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """
    signer = Signer(email=signer_email, name=signer_name, recipient_id='1',
        client_user_id=client_user_id, role_name='doctor')
    server_template1 = ServerTemplate(sequence='1', template_id=template_ids[0]
        )
    server_template2 = ServerTemplate(sequence='2', template_id=template_ids[1]
        )
    inline_template = InlineTemplate(sequence='3', recipients=Recipients(
        signers=[signer]))
    composite_template1 = CompositeTemplate(inline_templates=[
        inline_template], server_templates=[server_template1])
    composite_template2 = CompositeTemplate(inline_templates=[
        inline_template], server_templates=[server_template2])
    composite_templates = [composite_template1] if template_num == 0 else [
        composite_template2] if template_num == 1 else [composite_template1,
        composite_template2]
    envelope_definition = EnvelopeDefinition(email_subject=
        'Please sign this document sent from the Python SDK',
        composite_templates=composite_templates, status='sent')
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header('Authorization', 'Bearer ' + access_token)
    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=
        envelope_definition)
    redirect_url = (base_url + '/signing_complete' if template_num == 0 else
        base_url + '/report_complete')
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(authentication_method=
        authentication_method, client_user_id=client_user_id, recipient_id=
        '1', return_url=redirect_url, user_name=signer_name, email=signer_email
        )
    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request=recipient_view_request)
    return results.url

import base64, os
from flask import Flask, request, redirect
from docusign_esign import ApiClient, EnvelopesApi, EnvelopeDefinition, Signer, SignHere, Tabs, Recipients, Document, RecipientViewRequest, ServerTemplate, InlineTemplate, CompositeTemplate
access_token = os.environ['DOCUSIGN_OAUTH']
account_id = os.environ['DOCUSIGN_ACC_ID']
signer_name = 'Alice Chang'
signer_email = 'changvalice@gmail.com'
file_name_path = 'World_Wide_Corp_lorem.pdf'
base_url = 'http://localhost:5000'
client_user_id = '123'
authentication_method = 'None'
template_ids = [id for id in os.environ['DOCUSIGN_TEMPLATE_IDS'].split(',')]
base_path = 'https://demo.docusign.net/restapi'
APP_PATH = os.path.dirname(os.path.abspath(__file__))


def embedded_signing_ceremony():
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """
    with open(os.path.join(APP_PATH, file_name_path), 'rb') as file:
        content_bytes = file.read()
    base64_file_content = base64.b64encode(content_bytes).decode('ascii')
    document = Document(document_base64=base64_file_content, name=
        'Example document', file_extension='pdf', document_id=1)
    signer = Signer(email=signer_email, name=signer_name, recipient_id='1',
        routing_order='1', client_user_id=client_user_id)
    sign_here = SignHere(document_id='1', page_number='1', recipient_id='1',
        tab_label='SignHereTab', x_position='195', y_position='147')
    signer.tabs = Tabs(sign_here_tabs=[sign_here])
    envelope_definition = EnvelopeDefinition(email_subject=
        'Please sign this document sent from the Python SDK', documents=[
        document], recipients=Recipients(signers=[signer]), status='sent')
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header('Authorization', 'Bearer ' + access_token)
    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=
        envelope_definition)
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(authentication_method=
        authentication_method, client_user_id=client_user_id, recipient_id=
        '1', return_url=base_url + '/dsreturn', user_name=signer_name,
        email=signer_email)
    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request=recipient_view_request)
    return results.url


def get_signing_redirect(template_num):
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """
    signer = Signer(email=signer_email, name=signer_name, recipient_id='1',
        client_user_id=client_user_id, role_name='doctor')
    server_template1 = ServerTemplate(sequence='1', template_id=template_ids[0]
        )
    server_template2 = ServerTemplate(sequence='2', template_id=template_ids[1]
        )
    inline_template = InlineTemplate(sequence='3', recipients=Recipients(
        signers=[signer]))
    composite_template1 = CompositeTemplate(inline_templates=[
        inline_template], server_templates=[server_template1])
    composite_template2 = CompositeTemplate(inline_templates=[
        inline_template], server_templates=[server_template2])
    composite_templates = [composite_template1] if template_num == 0 else [
        composite_template2] if template_num == 1 else [composite_template1,
        composite_template2]
    envelope_definition = EnvelopeDefinition(email_subject=
        'Please sign this document sent from the Python SDK',
        composite_templates=composite_templates, status='sent')
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header('Authorization', 'Bearer ' + access_token)
    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=
        envelope_definition)
    redirect_url = (base_url + '/signing_complete' if template_num == 0 else
        base_url + '/report_complete')
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(authentication_method=
        authentication_method, client_user_id=client_user_id, recipient_id=
        '1', return_url=redirect_url, user_name=signer_name, email=signer_email
        )
    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request=recipient_view_request)
    return results.url

# Python3 Quick start example: embedded signing ceremony.
# Copyright (c) 2018 by DocuSign, Inc.
# License: The MIT License -- https://opensource.org/licenses/MIT

import base64, os
from flask import Flask, request, redirect
from docusign_esign import ApiClient, EnvelopesApi, EnvelopeDefinition, Signer, SignHere, Tabs, Recipients, Document, RecipientViewRequest, ServerTemplate, InlineTemplate, CompositeTemplate

# Settings
# Fill in these constants
#
# Obtain an OAuth access token from https://developers.hqtest.tst/oauth-token-generator
access_token = os.environ["DOCUSIGN_OAUTH"]
# Obtain your accountId from demo.docusign.com -- the account id is shown in the drop down on the
# upper right corner of the screen by your picture or the default picture.
account_id = os.environ["DOCUSIGN_ACC_ID"]
# Recipient Information:
signer_name = 'Alice Chang'
signer_email = 'changvalice@gmail.com'
# The document you wish to send. Path is relative to the root directory of this repo.
file_name_path = 'World_Wide_Corp_lorem.pdf'
# The url of this web application
base_url = 'http://localhost:5000'
client_user_id = '123' # Used to indicate that the signer will use an embedded
                       # Signing Ceremony. Represents the signer's userId within
                       # your application.
authentication_method = 'None' # How is this application authenticating
                               # the signer? See the `authenticationMethod' definition
                               # https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeViews/createRecipient
template_ids = [id for id in os.environ["DOCUSIGN_TEMPLATE_IDS"].split(",")]

# The API base_path
base_path = 'https://demo.docusign.net/restapi'

# Constants
APP_PATH = os.path.dirname(os.path.abspath(__file__))

def embedded_signing_ceremony():
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """

    #
    # Step 1. The envelope definition is created.
    #         One signHere tab is added.
    #         The document path supplied is relative to the working directory
    #
    with open(os.path.join(APP_PATH, file_name_path), "rb") as file:
        content_bytes = file.read()
    base64_file_content = base64.b64encode(content_bytes).decode('ascii')

    # Create the document model
    document = Document( # create the DocuSign document object
        document_base64 = base64_file_content,
        name = 'Example document', # 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
    signer = Signer( # The signer
        email = signer_email, name = signer_name, recipient_id = "1", routing_order = "1",
        client_user_id = client_user_id, # Setting the client_user_id marks the signer as embedded
    )

    # Create a sign_here tab (field on the document)
    sign_here = SignHere( # DocuSign SignHere field/tab
        document_id = '1', page_number = '1', recipient_id = '1', tab_label = 'SignHereTab',
        x_position = '195', y_position = '147')

    # Add the tabs model (including the sign_here tab) to the signer
    signer.tabs = Tabs(sign_here_tabs = [sign_here]) # The Tabs object wants arrays of the different field/tab types

    # Next, create the top level envelope definition and populate it.
    envelope_definition = EnvelopeDefinition(
        email_subject = "Please sign this document sent from the Python SDK",
        documents = [document], # The order in the docs array determines the order in the envelope
        recipients = Recipients(signers = [signer]), # The Recipients object wants arrays for each recipient type
        status = "sent" # requests that the envelope be created and sent.
    )

    #
    #  Step 2. Create/send the envelope.
    #
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header("Authorization", "Bearer " + access_token)

    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=envelope_definition)

    #
    # Step 3. The envelope has been created.
    #         Request a Recipient View URL (the Signing Ceremony URL)
    #
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(
        authentication_method = authentication_method, client_user_id = client_user_id,
        recipient_id = '1', return_url = base_url + '/dsreturn',
        user_name = signer_name, email = signer_email
    )

    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request = recipient_view_request)

    #
    # Step 4. The Recipient View URL (the Signing Ceremony URL) has been received.
    #         Redirect the user's browser to it.
    #
    return results.url

def get_signing_redirect(template_num):
    """
    The document <file_name> will be signed by <signer_name> via an
    embedded signing ceremony.
    """

    # Create the signer recipient model
    signer = Signer( # The signer
        email = signer_email, name = signer_name, recipient_id = "1",
        client_user_id = client_user_id, role_name = "doctor"# Setting the client_user_id marks the signer as embedded
    )

    # Create the server and inline templates for the envelope

    server_template1 = ServerTemplate(
        sequence = "1",
        template_id = template_ids[0]
    )

    server_template2 = ServerTemplate(
        sequence = "2",
        template_id = template_ids[1]
    )

    inline_template = InlineTemplate(
        sequence = "3",
        recipients = Recipients(signers = [signer])
    )

    # Create the composite template
    composite_template1 = CompositeTemplate(
        inline_templates = [inline_template],
        server_templates = [server_template1]
    )

    composite_template2 = CompositeTemplate(
        inline_templates = [inline_template],
        server_templates = [server_template2]
    )

    composite_templates = [composite_template1] if template_num == 0 else [composite_template2] if template_num == 1 else [composite_template1, composite_template2]

    # Next, create the top level envelope definition and populate it.
    envelope_definition = EnvelopeDefinition(
        email_subject = "Please sign this document sent from the Python SDK",
        composite_templates = composite_templates,
        status = "sent" # requests that the envelope be created and sent.
    )

    #
    #  Step 2. Create/send the envelope.
    #
    api_client = ApiClient()
    api_client.host = base_path
    api_client.set_default_header("Authorization", "Bearer " + access_token)

    envelope_api = EnvelopesApi(api_client)
    results = envelope_api.create_envelope(account_id, envelope_definition=envelope_definition)

    #
    # Step 3. The envelope has been created.
    #         Request a Recipient View URL (the Signing Ceremony URL)
    #
    redirect_url = base_url + '/signing_complete' if template_num == 0 else base_url + '/report_complete'
    envelope_id = results.envelope_id
    recipient_view_request = RecipientViewRequest(
        authentication_method = authentication_method, client_user_id = client_user_id,
        recipient_id = '1', return_url = redirect_url,
        user_name = signer_name, email = signer_email
    )

    results = envelope_api.create_recipient_view(account_id, envelope_id,
        recipient_view_request = recipient_view_request)

    #
    # Step 4. The Recipient View URL (the Signing Ceremony URL) has been received.
    #         Redirect the user's browser to it.
    #
    return results.url
