Can you add DocumentFields when using a Template? - docusignapi

Preface: It's my understanding that DocumentFields are metadata on a document that are not specifically tied to a recipient (and will thus not be shown as Form Data and can be retrieved on the document level). If this is incorrect, let me know.
Is there anyway to define DocumentFields when using a template? The templates I am using will only ever contain one document. I'm currently creating the DocuSign requests using a combination of templates and uploaded documents. Here is a piece of code that shows the creation of a request using a template:
var compositeTemplate = new CompositeTemplate()
{
ServerTemplates = new List<ServerTemplate>(),
InlineTemplates = new List<InlineTemplate>()
};
var signer = new Signer()
{
RecipientId = primaryRecipient.ID.ToString(),
Name = "Full Name Here",
RoleName = "Role 1", // Matches role on template
Email = "Fakeemail#fakeemail.com",
};
InlineTemplate inlineTemplate = new InlineTemplate()
{
Sequence = "1",
Recipients = new Recipients()
{
Signers = new List<Signer>(),
CarbonCopies = envelopeCarbonCopies // Set but not included here
}
};
ServerTemplate serverTemplate = new ServerTemplate()
{
Sequence = "1",
TemplateId = documentConfigurations[i].TemplateId
};
compositeTemplate.ServerTemplates.Add(serverTemplate);
inlineTemplate.Recipients.Signers.Add(signer);
compositeTemplate.InlineTemplates.Add(inlineTemplate);
The request works and the template is used. However, ServerTemplate object doesn't allow me to specify DocumentFields, and I can't use the Documents property of the inline template since I'm using a template defined in DocuSign.
If I cannot specify DocumentFields on a template through the API, can you do this using the UI?

If the document field you want to set in the server Template are static, then you can follow below steps to add these static documentfields to Server Template and, when Envelope will be created using this Server Template then it will be available in the Envelope as well.
a. Using DS Web App, download the Server Template, it will download as JSON
b. Open the JSON in the text editor (like Notepad++), and go to
documents node in the JSON, and add documentFields as shown below.
"documents": [{
"documentId": "1",
"uri": "/envelopes/40365a36-ddba-4132-a553-40b4d087935b/documents/1",
"name": "Test.pdf",
"order": "1",
"pages": "1",
"documentBase64": "<PDFBytes>",
"display": "inline",
"includeInDownload": "true",
"signerMustAcknowledge": "no_interaction",
"templateLocked": "false",
"templateRequired": "false",
"documentGroup": "content",
"documentFields": [{
"name": "s_businessDocType",
"value": "TL"
}]
}]
c. Save this JSON and re-upload it on WEBApp, it will generate new templateId.
When you will use this Server Template in the envelope, then envelope will have the documentFields present in the serverTemplate.
UPDATE:
If documentFields are dynamic, then follow below steps:
a. Create Envelope in a draft status.
b. Call below endpoint to add documentFields to the document
POST /v2/accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}/fields
c. Once you have added the documentFields then change the envelope status to sent using below endpoint
PUT /v2/accounts/{accountId}/envelopes/{envelopeId}

Related

DocuSign: how to attach custom properties to an envelope

Hello we are looking to attach an application number to Docusign request (an envelope) with the API.
How can we attach custom properties to an envelope, to pass some reference to a particular transaction, so it is part of the payload sent back in the webhook when signing is complete?.
What we have tried is below:
let recipients = docusign.Recipients.constructFromObject({
signers: [signer1],
carbonCopies: [cc1],
applicationNo: app.id,
})
env.recipients = recipients
env.applicationNo = "someApplicationNumber"
env.status = args.status
From your code example, it looks like you want to attach metadata at the envelope (transaction) level. To do that, use EnvelopeCustomFields
You can create use either strings or enumerated string values.
You can include them in the envelope definition. See here or you can use separate API calls for them
You can have them included in the certificate of completion document if you want.
Example using the Node.js SDK for an EnvelopeCustomField named applicationNo:
let textCustomField1 = docusign.TextCustomField.constructFromObject({
name: "applicationNo",
show: "true", // show the field in the certificate of completion
value: "12345"
});
let textCustomFields1 = [textCustomField1];
let customFields1 = docusign.CustomFields.constructFromObject({
textCustomFields: textCustomFields1
});
...
let envelopeDefinition = docusign.EnvelopeDefinition.constructFromObject({
customFields: customFields1,
documents: documents1,
emailSubject: "Please sign the attached document",
recipients: recipients1,
status: "sent"
});
Same example in JSON:
"envelopeDefinition": {
"emailSubject": "Please sign the attached document",
"status": "sent",
"customFields": {
"textCustomFields": [
{
"name": "applicationNo",
"show": "true",
"value": "12345"
}
]
},
"documents": ....
The certificate of completion.
Notice the applicationNo data

POSTMan sample - creating envelope from a template is not populating the user tags

I created a DocuSign template that contains two roles: Provider and Recipient. I did this via the DocuSign Sandbox UI.
In my template, I have one document, with four tabs on it:
1. ProviderName
2. ProviderAddress1
3. RecipientName
4. RecipientAddress
Should I be using CustomFields vs. Tabs?
What's the API call(s) that I should be making to do the following, given a template with a document in it:
create an envelope for specific users
update the text within the document in the template for the specific users
send it out?
In the POSTMan sample, I tried using this URL, doing a POST:
{{baseUrl}}/envelopes
passing in a templateId, and the following JSON below in the POST body:
JSON:
{
"templateRoles": [{
"email": "{{signer1Email}}",
"name": "The Provider",
"roleName": "Provider",
"tabs": {
"textTabs": [{
"tabLabel": "ProviderName",
"value": "This is the provider!"
},
{
"tabLabel": "ProviderAddress1",
"value": "10 Provider Street, Baltimore, MD 21212"
}]
}
},
{
"email": "{{otherEmail}}",
"name": "Test Recipient",
"roleName": "Recipient",
"tabs": {
"textTabs": [{
"tabLabel": "RecipientName",
"value": "This is the recipient!"
},
{
"tabLabel": "RecipientAddress",
"value": "10 Main Street, Baltimore, MD 21212"
}]
}
}],
"emailSubject": "DocuSign API - Signature Request on Document Call",
"templateId": "<<template ID>>",
"status": "sent"
}
This does return an Envelope Id in the response, and I do receive the email with the DocuSign document to sign.
However, the tabs are NOT populated, they're blank.
Are the roles in the Template empty placeholders? If a name/email is defined on the template, the API call won't populate them as you might expect.
Try to add the documentId and pageNumber properties to your tabs. Also, ensure the label matches what is in the original template.
Lastly, you may need to add recipientId as well to each of the recipients to match what is in the template (this one may not be required since you have the roleName but just in case)

Embedded Signing - Signing from My App

I'm working on get the signing process on an iFrame to Embedded docusign on my app.
I have trying to work on this based on this tutorials:
Docusign Embedded Signing using template
https://developers.docusign.com/esign-rest-api/guides/features/embedding
Based on what I understood, if you want to embedded you have to create the "create the envelope on the fly". So you don't specify the templateId correct?
So what I don't fully get is, how I get the documentBase64 string value? I have to get it manually? Or docusing api has an endpoint that will return that?
Also I want to know, what happen to the custom fields I added to the template? I can't use them?
Right now this is the json I'm sending:
{{baseUrl}}/envelopes
{
"emailSubject":"This is a custom email subjet, look at the doc.",
"status":"sent",
"templateId":"a0847413-35ac-48ed-9ed6-9b7f96019eda",
"templateRoles":[
{
"email":"mauriciotaranto#email.com",
"name":"Mauricio T",
"clientUserId": "1234",
"roleName":"Test",
"routingOrder":"1",
"tabs": {
"textTabs": [
{
"tabLabel": "Custom",
"value": "This is a custom value"
},
{
"tabLabel": "NewCustom",
"value": "Another custom value added using API"
},
{
"tabLabel": "NewCustom1",
"value": "Last custom value added using API"
}
]
}
}
],
}
And then I go to the recipient view to get the URL:
{{baseUrl}}/envelopes/{{envelopeId}}/views/recipient
{
"returnUrl": "https://www.google.com.uy",
"authenticationMethod": "None",
"email": "mauriciotaranto#email.com",
"userName": "Mauricio T",
"clientUserId": "1234"
}
As far as I understood this way will not allow the user to sing the document.
Need to do it with the document instead.
Can you explain to me how this should work?
Thanks!
UPDATE:
Im manually parsing the bytes of the document to base64. and send this json:
"status":"sent",
"emailSubject":"Envelope with Embedded Signer",
"documents":[
{
"documentId":"1",
"name":"contract.pdf",
"documentBase64":bytes
}
],
"recipients":{
"signers":[
{
"email":"mauriciotaranto#hotmail.com",
"name":"Mauricio T",
"recipientId":"1",
"clientUserId":"1234"
}
]
}
}
I change the headers, add the accept: application/json and content-type: multipart/from-data
And this is the response I get:
{
"errorCode": "ENVELOPE_IS_INCOMPLETE",
"message": "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line. Content-Type does not contain boundary parameter."
}
You can create envelopes in any way, either by using Templates or by passing base64 of document or both as well using Composite Template. When you send templates, then you already have added signers tabs on the document in the templates so you just need to populate the signer details like name and email in creating an envelope and/or pre-populate the DS Tabs value. But when you send document as base64, then you need to tell DocuSign how to add DS Tabs on the document, either by using
X and Y position of the tabs
AnchorString
PDF Field Transformation
Embedded Signing is a type of signing, to implement that you need to just add clientUserId in the signers details. This can be done in both ways either by using template or by passing document as base64 or both as well using Composite Template. Once you have an embedded signer by adding clientUserId then you need to generate signing URL as explained in your qs, by using Recipient View URL, as soon as URL is generated then you will open this URL in IFrame or on new tab.
In the link which you shared is having very small code snippet and it does not have complete example, check Complete Example, and you will see that they are adding DS Tabs on the document using X/Y position.

DocuSign Status Code TAB_REFERS_TO_DOCUMENT_NO_TABS_ALLOWED?

I am currently using the REST api to create an envelope containing a document and a template which I have already set up in Docusign. I get the following error on the web request and can't find this error on the status code/error list provided by DocuSign to try debug the issue. Their support person suggests I ask here..
TAB_REFERS_TO_DOCUMENT_NO_TABS_ALLOWED -- The Tab refers to a document that does not allow tabs.
Has anyone experienced this?
Edit:
The issue appears to be related to the document section.
{
"emailBlurb":"Test Email Body",
"emailSubject": "Test Email Subject",
"status" : "sent",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence" : 1,
"templateId": "b1eccee3-9c00-4cb2-8d30-0400d51dcfe0"
}],
"inlineTemplates": [
{
"sequence" : 2,
"recipients": {
"signers" : [{
"email": "usera#bah.com",
"name": "usera",
"recipientId": "1",
"roleName": "Producer"
}]
}
}],
"document": {
"documentId": 1,
"name": "Test.docx",
"documentBase64":"[bytesremoved]",
"fileExtension":"docx"
}
}]
}
So you have a template on the server, with a document as part of the template?
But you want the envelope to use a different document with the template, yes?
It is my understanding that the documentId in the document section of the composite template must match the documentId used in the template if you want the document to be substituted for the template's document.
So check the definition of the template. Did you create the template programmatically or did you use the web browser DocuSign app? If the latter, then note that the first document in a template is not always given an id of 1.

Docusign: Dynamically Populate Fields In Document

I am using docusign to send off vendor agreements. The agreements are all the same wording, except for vendor name and address. Is there a way I can pass information to the envelope creation script (PHP) to dynamically populate name and address fields on a template document?
Yes you can definitely populate tabs in an embedded signing view. This is all controlled through the
tabLabel
property of each tab in your request body. For instance, if you login to the DocuSign Console and add two data fields (textTabs) to your envelope where one has the label "email" and the other has a label of "address" then the following JSON body prefills those tabs based on the value passed.
"tabs": {
"textTabs": [
{
"tabLabel": "address",
"value": "123 Main St. SF, CA"
},
{
"tabLabel": "email",
"value": "sample#email.com"
}
]
}
}
],
"status": "sent"
}

Resources