-->

DocuSign API Replace template document but keep fi

2019-06-04 10:31发布

问题:

I want to use the existing fields from a server template over another document.

At first I tried attaching the document at the same level as inline/server. If I have the signer defined it gives me a 400 error, if I leave it off (did by accident) it completely wipes out the fields and shows the attached document.

Second I tried attaching the document to the inline template but that results in the attached document not appearing, it just operates like normal.

update

After adding additional debugging and research I now know that attaching it to the inline template was incorrect. After adding debug to read the 400 response I am getting this error:

"The DocumentId specified in the tab element does not refer to a document in this envelope. Tab refers to DocumentId 32475214 which is not present."

DocumentId is being set to 1 which is apparently wrong.

Which led me to this question on SO. In which a comment mentions that the ID kicked back from the 400 should be used. After I hard coded this ID I see the replacement operation is a success!

However I now need to find a way find and to plug that value in programatically.

Detail

I am using the DocuSign php sdk to help me build the data structure and access the api.

回答1:

Use the listTemplateDocuments API to retrieve the documentId for the template.

The documentId retrieved in the above step should be used in the CompositeTemplate of CreateEnvelope request

{
  "emailSubject": "Tabs should remain from the Server Template",
  "status": "sent",
  "compositeTemplates": [
    {
      "document": {
            "documentId": "<document Id>", //Use the documentId retrieved using the listTemplateDocuments api
            "name": "Replaced Document",
            "fileExtension": "txt",
            "documentBase64": "RG9jIFRXTyBUV08gVFdP"
        },
        "serverTemplates": [
            {
                "sequence": "1",
                "templateId": "<Server Template Id Here>"
            }
        ]
    }
  ]
}