user_data = {
"name": user_smartreq.user_id.first_name,
"address": "Your Address",
}
html_content = render_to_string("offer.html", user_data)
pdf_file_path = "/tmp/document.pdf"
HTML(string=html_content).write_pdf(pdf_file_path)
# Step 2: Set up DocuSign API Client
api_client = ApiClient()
api_client.set_oauth_host_name("account-d.docusign.com")
api_client.set_base_path("https://demo.docusign.net")
response = api_client.request_jwt_user_token(
client_id=env.DOCUSIGN_INTEGRATION_KEY,
user_id=env.DOCUSIGN_USER_ID,
oauth_host_name="account-d.docusign.com",
private_key_bytes=docusign.PRIVATE_KEY,
expires_in=100000,
scopes=="signature", "impersonation", "extended", "openid", "cors"],
)
# api_client.set_access_token(response)
print(response.access_token)
api_client.set_default_header(
header_name="Authorization", header_value=f"Bearer {response.access_token}"
)
api_client.set_base_path("https://demo.docusign.net")
print(str(api_client.get_user_info(response.access_token).accountss0].base_uri))
# Step 3: Prepare the PDF document for DocuSign
with open(pdf_file_path, "rb") as file:
document_base64 = file.read().decode("latin1")
document = Document(
document_base64=document_base64,
name="Sample Document",
file_extension="pdf",
document_id="1",
)
# Step 4: Set up signer and signature tab
signer = Signer(
email="parthpatel1470@gmail.com",
name="Recipient Name",
recipient_id="1",
routing_order="1",
)
sign_here = SignHere(
document_id="1", page_number="1", x_position="100", y_position="150"
)
signer.tabs = {"sign_here_tabs": sign_here]}
recipients = Recipients(signers==signer])
# Step 5: Create the envelope definition
envelope_definition = EnvelopeDefinition(
email_subject="Please sign this document",
documents==document],
recipients=recipients,
status="sent",
)
try:
# Step 6: Send the envelope via DocuSign API
envelopes_api = EnvelopesApi(api_client)
# print(envelopes_api.list_status(account_id=env.DOCUSIGN_API_ACCOUNT_ID))
result = envelopes_api.create_envelope(
env.DOCUSIGN_API_ACCOUNT_ID, envelope_definition=envelope_definition
)
print(result)
except ApiException as e:
print("I htrewq anas erefaehjlealk pleas elook ")
print(e)
I not able to use the envelope client I checked in the admin console and the user has all access to everything still I am not above to run this code