DocuSign Create Template, 400 Client Error: Bad request

Viewed 38

I am trying to create a new template in my DocuSign account using the following code:

def create_template(token):
    docusign_account_id = getenv("DOCUSIGN_ACCOUNT_ID")
    document_base64 = getenv("DOCUMENT_BASE64")

    post_params = {'account_id': docusign_account_id}
    post_headers = {'Accept': 'application/json', 'Authorization': token}

    payload = {'documents':
                   [{"documentBase64": getenv(document_base64),
                     "documentId": "1", "fileExtension": "pdf",
                     "name": "World_Wide_Corp_lorem"}], 'emailSubject': "Create template test"}

    post_r = requests.post(url="https://demo.docusign.net/restapi/v2.1/accounts/b24dee2d-xxxx-xxxx-xxxx-d9d81de867ab/templates", params=post_params, headers=post_headers, data=json.dumps(payload))

    post_r.raise_for_status()

When executing, it returns the following error:

Traceback (most recent call last):
  File "src/docusign_template_app/main.py", line 78, in <module>
    main()
  File "src/docusign_template_app/main.py", line 74, in main
    create_template(token_4)
  File "src/docusign_template_app/main.py", line 64, in create_template
    post_r.raise_for_status()
  File "/home/lluis/.pyenv/versions/docusign-template-app_py38/lib/python3.8/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://demo.docusign.net/restapi/v2.1/accounts/b24dee2d-xxxx-xxxx-xxxx-d9d81de867ab/templates?account_id=b24dee2d-xxxx-xxxx-xxxx-d9d81de867ab

Which is strange because I run the exact same request in Postman and the template is created correctly.

Any suggestions are more than welcome,

Thanks!!

1 Answers

This is Zack with DocuSign Developer Support. I'm able to see some limited telemetry related to this failing call and it appears to be an issue with processing the document. I'm seeing a DocuSign error: UNABLE_TO_LOAD_DOCUMENT. My recommendation would be to check DocuSign API logging for the CreateEnvelope call and compare it your Postman call body to see if there's something weird about how the document is getting processed. If you aren't able to resolve the issue, feel free to open a DocuSign Support case with a failing API log attached so we can provide further assistance.

Related