Create template, DocuSign - docusignapi

I am trying to create a template 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 = {'documentBase64': document_base64, 'emailSubject': "Create template test", 'name': "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()
By executing this code, I am creating a new template in my docusign account. But the document I have attached in base64 is nowhere to be found.
Any suggestions are more than welcome,
Thanks!

DocuSign is expecting an array of documents (can be one or more) like so:
payload = {'documents':
[{"documentBase64": document_base64,
"documentId": "1", "fileExtension": "pdf",
"name": "Lorem Ipsum"}], 'emailSubject': "Create template test",
'name':"Test"}

Related

Adding to a database creates a new database within page in notion

Here's my current code:
import json
import requests
def createPage(database_id, page_id, headers, url):
newPageData = {
"parent": {
"database_id": database_id,
"page_id": page_id,
},
"properties": {
"Name": {"title": {"text": "HI THERE"}},
},
}
data = json.dumps(newPageData)
res = requests.request("POST", url, headers=headers, data=data)
print(res.status_code)
print(res.text)
database_id = "ea28de8e9cca4f62b4c4da3522869d03"
page_id = "697fd88570b3420aaa928fa28d0bf230"
url = "https://api.notion.com/v1/databases/"
key = "KEY"
payload = {}
headers = {
"Authorization": f"Bearer {key}",
"accept": "application/json",
"Notion-Version": "2021-05-11",
"content-type": "application/json",
}
createPage(database_id, page_id, headers, url)
But everytime I run this, it appears like I keep getting new databases within the page. This is before running the script:
This is after running the script:
I would like it to be like this after running the script:
How can that be achieved?
It looks as you're calling the API URL that creates a new Database, and not the one that creates a new page.
This URL: https://api.notion.com/v1/databases/ is for creating new databases, and not for creating pages.
In order to create a new page within a database, use the following URL:
https://api.notion.com/v1/pages
Where you'll need to provide the previously created database id, among other identifiers
More detailed documentation can be found here
https://developers.notion.com/reference/post-page

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

Trying to access Microsoft Power Automate API via python msal library

The following code:
import requests
import json
import msal
config = {
"authority": "https://login.microsoftonline.com/<My tenant ID>",
"client_id": "<My client ID>",
"client_secret": "<My secret>",
"scope": ["https://graph.microsoft.com/.default"],
}
app = msal.ConfidentialClientApplication(
config["client_id"],
authority=config["authority"],
client_credential=config["client_secret"] )
result = app.acquire_token_silent(config["scope"], account=None)
if not result:
result = app.acquire_token_for_client(scopes=config["scope"])
bearerToken = result['access_token']
url = "https://<My org ID>.<My org region>.dynamics.com/api/data/v9.1/workflows"
headers = {
"Accept": "application/json",
"Content-type": "application/json",
"Authorization": "Bearer "+bearerToken,
}
response = requests.request("GET", url, headers = headers)
response
Is producing the following output:
<Response [401]>
The expected output is like this:
{
"#odata.context": "https://org00000000.crm0.dynamics.com/api/data/v9.1/$metadata#workflows",
"value": [{
"#odata.etag": "W/\"12116760\"",
"category": 5,
"statecode": 0,
"workflowidunique": "00000000-0000-0000-0000-000000000001",
"workflowid" : "00000000-0000-0000-0000-000000000002",
"createdon": "2018-11-15T19:45:51Z",
"_ownerid_value": "00000000-0000-0000-0000-000000000003",
"modifiedon": "2018-11-15T19:45:51Z",
"ismanaged": false,
"name": "Sample flow",
"_modifiedby_value": "00000000-0000-0000-0000-000000000003",
"_createdby_value": "00000000-0000-0000-0000-000000000003",
"type": 1,
"description": "This flow updates some data in Common Data Service.",
"clientdata": "{\"properties\":{\"connectionReferences\":{\"shared_commondataservice\":{\"source\":\"NotSpecified\",\"id\":\"/providers/Microsoft.PowerApps/apis/shared_commondataservice\",\"tier\":\"NotSpecified\"}},\"definition\":{...}},\"schemaVersion\":\"1.0.0.0\"}"
}]
}
...as shown in the Microsoft documentation that appears here: https://learn.microsoft.com/en-us/power-automate/web-api
Previously I:
Registered the app in Azure and generated secret key, as is indicated in the procedure shown in this link: https://learn.microsoft.com/en-us/powerapps/developer/data-platform/walkthrough-register-app-azure-active-directory#create-an-application-registration
Created app role as described here: https://learn.microsoft.com/en-us/power-platform/admin/database-security#minimum-privileges-to-run-an-app
Created a Dataverse app user, linked to the app created in 1. and the role created in 2., as described here: https://learn.microsoft.com/en-us/powerapps/developer/data-platform/authenticate-oauth#manually-create-a-dataverse-application-user
Why is this not working?
Finally got a solution thanks to #microsoft support team.
It was the scope, whose correct content is:
"scope": ["https://<My org ID>.<My org region>.dynamics.com/.default"],

Can you add DocumentFields when using a Template?

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}

Resend DocuSign Emails

Is there an API endpoint which allows me to retrigger emails to recipients? Sometimes users may not get or lose the DocuSign emails which contain their signing link. I'd like to be able to send those emails again on demand.
You can use the "modify recipient(s)" request to trigger a re-send of the email notification to specific recipient(s).
PUT /accounts/{accountId}/envelopes/{envelopeId}/recipients?resend_envelope=true
Be sure to include the querystring parameter/value resend_envelope=true in the URL (as shown above).
For example, if a GET Recipients response shows that an Envelope contains the following recipients:
{
"signers": [
{
"name": "Jane Doe",
"email": "janesemail#outlook.com",
"recipientId": "3",
"recipientIdGuid": "13e30b8d-3dd6-48e8-ad12-15237611a463",
"requireIdLookup": "false",
"userId": "2c9e06eb-f2c5-4bef-957a-5a3dbd6edd25",
"routingOrder": "1",
"status": "sent"
},
{
"name": "John Doe",
"email": "johnsemail#outlook.com",
"recipientId": "1",
"recipientIdGuid": "c2273f0f-1430-484a-886c-45ce2fb5e8a8",
"requireIdLookup": "false",
"userId": "03c8a856-c0ae-41bf-943d-ac6e92db66a8",
"routingOrder": "1",
"note": "",
"roleName": "Signer1",
"status": "sent",
"templateLocked": "false",
"templateRequired": "false"
}
],
"agents": [],
"editors": [],
"intermediaries": [],
"carbonCopies": [],
"certifiedDeliveries": [],
"inPersonSigners": [],
"recipientCount": "2",
"currentRoutingOrder": "1"
}
Then, I could trigger a re-send of the Signing Invitation Email to the incomplete recipient ("Jane Doe") by using the following request:
PUT https://{{env}}.docusign.net/restapi/{{version}}/accounts/{{acctId}}/envelopes/{{envelopeId}}/recipients?resend_envelope=true
{
"signers": [
{
"recipientId": "3",
"name": "Jane Doe",
"email": "janesemail#outlook.com"
}
]
}
Notice that I'm sending the same (original) values for name and email -- so it's not going to actually modify the recipient -- it'll just re-send the email to Jane, since I included ?resend_envelope=true in the URL.
API Documentation
If you want to re-send the email notification to all pending recipients (i.e., anyone who's next in the routing order and hasn't yet completed the envelope), you can do so with the following request:
PUT https://demo.docusign.net/restapi/v2/accounts/<accountID>/envelopes/<envelopeID>?resend_envelope=true
{}
You can use docusign's latest API using nuget package manager "DocuSign.eSign.Api".
I did it using C#:
//Very first prepare Recepients:
Recipients recpnts = new Recipients
{
//CurrentRoutingOrder = "1", // Optional.
Signers = new List<Signer>()
{
new Signer
{
RecipientId = "1",
RoleName = "Prospect",
Email = "ert#gmail.com",
Name = "Shyam",
},
}
};
// Call Envelopes API class which has UpdateRecepient Method
EnvelopesApi epi = new EnvelopesApi();
var envelopeId ="62501f05-4669-4452-ba14-c837a7696e04";
var accountId = GetAccountId();
// The following Line is responsible for Resend Envelopes.
RecipientsUpdateSummary recSummary = epi.UpdateRecipients(accountId, envelopeId , recpnts);
// Get Status or Error Details.
var summary = recSummary.RecipientUpdateResults.ToList();
var errors = summary.Select(rs => rs.ErrorDetails).ToList();
// Method to get your Docusign Account Details and Authorize it.
private static string GetAccountId()
{
string username = "Account Email Address";
string password = "Account Password;
string integratorKey = "Your Account Integrator Key";
// your account Integrator Key (found on Preferences -> API page)
ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
Configuration.Default.ApiClient = apiClient;
// configure 'X-DocuSign-Authentication' header
string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
// we will retrieve this from the login API call
string accountId = null;
/////////////////////////////////////////////////////////////////
// STEP 1: LOGIN API
/////////////////////////////////////////////////////////////////
// login call is available in the authentication api
AuthenticationApi authApi = new AuthenticationApi();
LoginInformation loginInfo = authApi.Login();
accountId = loginInfo.LoginAccounts[0].AccountId;
return accountId;
}
I'm not sure if a separate api call exists just to resend the envelope (notification), however you might be able to get away with it by using the Modify or Correct and Resend Recipient Info api call.
That call is normally used to correct information about your recipients- for instance, if you created an envelope with an incorrect email address or perhaps have the wrong name for someone you could use this call to modify the email address and resend the envelope. And when you make the call there is an optional query parameter called
?resend_envelope={true or false}
Try making this call but instead of altering any recipient information, simple append the URL parameter and that might resend the envelope.
Documentation
I know this is extremely old but I wanted to post how I did it using the latest SDK (DocuSign.eSign.dll 5.12.0).
var account = ...;
var accessToken = ...;
var apiClient = new ApiClient($"{account.BasePath}/restapi");
apiClient.Configuration.DefaultHeader.Add("Authorization", $"Bearer {accessToken}");
var envelopesApi = new EnvelopesApi(apiClient);
var envelope = new Envelope
{
EnvelopeId = envelopeId
};
await envelopesApi.UpdateAsync(account.Id, envelopeId, envelope, new EnvelopesApi.UpdateOptions { resendEnvelope = "true" });
Here it is for SOAP without changing the recipients info:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.docusign.net/API/3.0">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>[integratorKey]UserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ns:CorrectAndResendEnvelope>
<ns:Correction>
<ns:EnvelopeID>1234</ns:EnvelopeID>
<ns:RecipientCorrections>
<ns:RecipientCorrection>
<ns:PreviousUserName>userName</ns:PreviousUserName>
<ns:PreviousEmail>user#email.com</ns:PreviousEmail>
<ns:PreviousRoutingOrder>1</ns:PreviousRoutingOrder>
<ns:Resend>true</ns:Resend>
</ns:RecipientCorrection>
</ns:RecipientCorrections>
</ns:Correction>
</ns:CorrectAndResendEnvelope>
</soapenv:Body>
</soapenv:Envelope>
To replicate the behavior of the "Resend" button in the UI
pick the next person in the order, and send them an email of what to do
you can use API Explorer to just filling out the account ID, envelope ID, and Oauth Token, then setting resend-envelope to true
Like this curl:
curl --request PUT \
--url 'https://demo.docusign.net/restapi/v2/accounts/{accountId}/envelopes/{envelopeId}?resend_envelope=true' \
--header 'accept: application/json' \
--header 'accept-encoding: gzip,deflate,sdch' \
--header 'accept-language: en-US,en;q=0.8,fa;q=0.6,sv;q=0.4' \
--header 'authorization: {bearerToken}' \
--header 'cache-control: no-cache' \
--header 'content-type: application/json' \
--data '{}'
note: this in the body is required, or it will 400 you
{}
These days, if you're having problems with signers not noticing the DocuSign signing request email in their overloaded in-boxes, I recommend send the message via email + SMS.
Here's a live API Request Builder example that sends via email and SMS.
You can also send SMS only if you wish. Live example

Resources