docusignapi error calling UpdateNotificationSettings: { User Lacks Permission to resource - docusignapi

Using an demo account and my accountID, I am trying to change the Notification settings on an envelope I am creating using the REST API. I get the error below. Is this a settings issue with my account, or a problem with the way I am creating the envelope?
Error calling UpdateNotificationSettings: {
"errorCode": "USER_LACKS_PERMISSIONS",
"message": "This user lacks sufficient permissions to access this resource."
}
Code:
Recipients recipients = new Recipients { Signers = new List<Signer>(signers) };
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition
{
EmailSubject = "Review and sign the document",
Documents = new List<Document>(documents),
Recipients = recipients,
Status = "sent"
};
ApiClient apiClient = new ApiClient(basePath);
apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelopeDefinition);
Expirations exp = new Expirations("14", "true", "2");
EnvelopeNotificationRequest enr = new EnvelopeNotificationRequest(exp, null, null);
string envelopeId = results.EnvelopeId;
envelopesApi.UpdateNotificationSettings(accountId, envelopeId, enr);

It looks like you're sending the envelope and then trying to change the expiration settings while it's live.
You might have better results adding that expirations to the envelope definition prior to the CreateEnvelope() call. Try this instead:
Recipients recipients = new Recipients { Signers = new List<Signer>(signers) };
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition
{
EmailSubject = "Review and sign the document",
Documents = new List<Document>(documents),
Recipients = recipients,
Status = "sent"
};
Expirations exp = new Expirations("14", "true", "2");
envelopeDefinition.Notification = new Notification(expirations)
ApiClient apiClient = new ApiClient(basePath);
apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelopeDefinition);

Related

Insert data to fields in document inside template or load document from template into envelope

Looking for paths to try, drawing blanks.
Is there a way to either send a template (and all its document) field data or to send a document from a template inside a new envelope?
I've found ways to do this if the file is local, but I'm desperate to have this be something they can still admin from the template portal and I can just pass known data values.
Solved
...
ApiClient apiClient = new ApiClient(basePath);
apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "stack test";
envDef.TemplateId = mytemplateid
List<TemplateRole> templateRolesList = new List<TemplateRole>();
TemplateRole tRole = new TemplateRole();
Tabs tabs = new Tabs();
List<TemplateRole> rolesList = new List<TemplateRole>();
List<Text> textTabs = new List<Text>();
tRole.RoleName = "Sales Counselor";
Text texttab1 = new Text();
texttab1.TabLabel = "Buyer Name";
texttab1.Value = "name goes here";
Text texttab2 = new Text();
texttab2.TabLabel = "Elevation";
texttab2.Value = "AB";
textTabs.Add(texttab1);
textTabs.Add(texttab2);
tabs.TextTabs = textTabs;
tRole.Tabs = tabs;
tRole.Name="Sales Counselor";
tRole.Email="me#gmail.com";
templateRolesList.Add(tRole);
envDef.TemplateRoles = templateRolesList;
envDef.Status = "sent";
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envDef);
...

Implementing sign a document option without send notification email to signer

I am trying to implement sign a document option in my application.
It is working perfectly but during the process it sends email to signer to review document (which doesn't happen when created via DocuSign UI). How I can stop this review document email from sending to signer.
Here what I am doing in my code
Creating envelope
try
{
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = selectedFileList[0].subject;
envDef.Documents = new List<Document>();
foreach (var file in selectedFileList)
{
envDef.Documents.Add(getDocument(file.localPath, file.fullFileName, file.extension, file.number.ToString(), file.version.ToString(), file.databaseName));
}
Signer signer = new Signer();
signer.Email = signerEmail;
signer.Name = signerName;
signer.RecipientId = "1";
envDef.Recipients = new Recipients();
envDef.Recipients.Signers = new List<Signer>();
envDef.Recipients.Signers.Add(signer);
envDef.Status = "sent";
EnvelopesApi envelopesApi = new EnvelopesApi(config);
var response = await Task.Run(() => { return envelopesApi.CreateEnvelopeWithHttpInfo(accountId, envDef); });
EnvelopeSummary envelopeSummary = response.Data;
responseHeaders = response.Headers;
}
catch (Exception ex)
{
throw ex;
}
Creating receipent view
EnvelopesApi envelopesApi = new EnvelopesApi(apiConfig);
RecipientViewRequest viewRequest = new RecipientViewRequest();
viewRequest.UserName = signerName;
viewRequest.Email = signerEmail;
viewRequest.RecipientId = "1";
viewRequest.AuthenticationMethod = "email";
viewRequest.ReturnUrl = returnUrl;
//viewRequest.ClientUserId = apiConfig;
var view = envelopesApi.CreateRecipientView(accountId, envelopeId, viewRequest);
var url = view.Url;
Try to add this code in your app:
var textCustomFields = new List<TextCustomField>();
var textCustomField = new TextCustomField { Name = "AppName", Value = "DocuSignIt" };
textCustomFields.Add(textCustomField);
envDef.CustomFields.TextCustomFields = textCustomFields;
This should tell DocuSign not to send the email.
Setting the ClientUserId attribute value for a recipient also marks the recipient to not receive the email invitation to sign.
Setting ClientUserId is the recommended approach for embedded signing.
The value of the ClientUserId attribute also acts as a connection between the authentication that your application has done and the signing ceremony which enables the person to sign the documents.

Populate Dropdown options using c# code in a docusign template before creating envelope

I have create a template in my Admin Account Panel, and I am using the template to create new envelopes and send to different receivers.
But in my template I have a dropdown whose value changes on some condition,
like for State A it will have different values, for State B it will have different values.
How do I handle it programmatically.
Here is how I create an envelope from a template.
string recipientEmail = "a#a.com";
string recipientName = "John Doe";
string templateRoleName = "Customer";
string TemplateId = "xxxxxxxx-c87454e95429";
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";
// assign recipient to template role by setting name, email, and role name. Note that the
// template role name must match the placeholder role name saved in your account template.
TemplateRole tRole = new TemplateRole();
tRole.Email = recipientEmail;
tRole.Name = recipientName;
tRole.RoleName = templateRoleName;
List<TemplateRole> rolesList = new List<TemplateRole>() { tRole };
// add the role to the envelope and assign valid templateId from your account
envDef.TemplateRoles = rolesList;
envDef.TemplateId = TemplateId;
// set envelope status to "sent" to immediately send the signature request
envDef.Status = "sent";
// |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
EnvelopesApi envelopesApi = new EnvelopesApi(cfi);
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);
To populate tabs in a template you must match the name of the tab using the tabLabel property and set its value to the data you want to populate it with
Documentation here
string recipientEmail = "a#a.com";
string recipientName = "John Doe";
string templateRoleName = "Customer";
string TemplateId = "xxxxxxxx-c87454e95429";
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";
// assign recipient to template role by setting name, email, and role name. Note that the
// template role name must match the placeholder role name saved in your account template.
var tRole = new TemplateRole();
tRole.Email = recipientEmail;
tRole.Name = recipientName;
tRole.RoleName = templateRoleName;
var dropdownItems = new List<ListItem>();
if (stateA)
{
dropdownItems.Add(new ListItem()
{
Text = "Yellow", Value = "Y", Selected = "true"
});
dropdownItems.Add(new ListItem()
{
Text = "Green",Value = "G"
});
}
else
{
dropdownItems.Add(new ListItem()
{
Text = "Red", Value = "R", Selected = "true"
});
dropdownItems.Add(new ListItem()
{
Text = "Blue", Value = "B"
});
dropdownItems.Add(new ListItem()
{
Text = "Orange", Value = "O"
});
}
tRole.Tabs = new Tabs()
{
ListTabs = new List<List>()
{
new List(){
TabLabel = "ColorDropdown",
ListItems = dropdownItems
}
}
};
var rolesList = new List<TemplateRole>() { tRole };
// add the role to the envelope and assign valid templateId from your account
envDef.TemplateRoles = rolesList;
envDef.TemplateId = TemplateId;
// set envelope status to "sent" to immediately send the signature request
envDef.Status = "sent";
// |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
EnvelopesApi envelopesApi = new EnvelopesApi();
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);

Docusign ViewUrl: UNKNOWN_ENVELOPE_RECIPIENT error

I'm trying out a simple example to get a pdf signed in docuSign, but I'm running into the UNKNOWN_ENVELOPE_RECIPIENT error when trying to get the ViewUrl to redirect the user.
Here is the code I'm using to to create the envelope with the pdf doc.
string recipientName = "Tester";
string recipientEmail = "test#me.com";
string accountId = AuthenticateDocuSign();
byte[] fileBytes = File.ReadAllBytes(#"C:\temp\test.pdf");
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";
// Add a document to the envelope
DocuSign.eSign.Model.Document doc = new DocuSign.eSign.Model.Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = "TestFile.pdf";
doc.DocumentId = "1";
envDef.Documents = new List<DocuSign.eSign.Model.Document>();
envDef.Documents.Add(doc);
// Add a recipient to sign the documeent
Signer signer = new Signer();
signer.Email = recipientEmail;
signer.Name = recipientName;
signer.RecipientId = "1";
// Create a |SignHere| tab somewhere on the document for the recipient to sign
signer.Tabs = new Tabs();
signer.Tabs.SignHereTabs = new List<SignHere>();
SignHere signHere = new SignHere();
signHere.DocumentId = "1";
signHere.PageNumber = "1";
signHere.RecipientId = "1";
signHere.XPosition = "100";
signHere.YPosition = "100";
signer.Tabs.SignHereTabs.Add(signHere);
envDef.Recipients = new Recipients();
envDef.Recipients.Signers = new List<Signer>();
envDef.Recipients.Signers.Add(signer);
// set envelope status to "sent" to immediately send the signature request
envDef.Status = "sent";
// |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
EnvelopesApi envelopesApi = new EnvelopesApi();
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
RecipientViewRequest viewOptions = new RecipientViewRequest()
{
ReturnUrl = returnURL,
ClientUserId = "1000", // must match clientUserId set in step #2!
AuthenticationMethod = "email",
UserName = recipientName,
Email = recipientEmail,
};
ViewUrl recipientView = envelopesApi.CreateRecipientView(accountId, envelopeSummary.EnvelopeId, viewOptions); // EXCEPTION!
Complete error:
DocuSign.eSign.Client.ApiException was unhandled by user code
ErrorCode=400 HResult=-2146233088 Message=Error calling
CreateRecipientView: { "errorCode": "UNKNOWN_ENVELOPE_RECIPIENT",
"message": "The recipient you have identified is not a valid recipient
of the specified envelope." }
As Luis indicates in the comment above, you must specify the clientUserId property for the signer in the Create Envelope request, if you want to be able to subsequently retrieve the "View" URL for that Recipient:
signer.clientUserId = 1000;
You can set the clientUserId property to any value you choose -- I used 1000 in this example because that's the value that your code is using in the Post Recipient View request.
ClientUserId = "1000", // must match clientUserId set in step #2!
(The clientUserId, name, and email property values that you specify in the Post Recipient View request must exactly match the values that you specified for the Recipient in the Create Envelope request.)

GetRecipientView: REST API Error ACCOUNT_NOT_AUTHORIZED_FOR_ENVELOPE

I am trying to get recipient url but getting "GetRecipientView REST Error ACCOUNT_NOT_AUTHORIZED_FOR_ENVELOPE #44".
First I am creating the envelope to get sender url. And then I calling GetRecipientView() to get recipient view url. Below is the code I am using
public string EmbeddedSenderView(string docId)
{
Account account = InitializeDocSign();
Envelope envelope = new Envelope();
envelope.Login = account;
envelope.EmailSubject = "Please sign document";
envelope.Recipients = new Recipients()
{
signers = new Signer[]
{
new Signer()
{
email = "xxxx#gmail.com",
name = "AV Gmail 1",
routingOrder = "1",
recipientId = "1",
roleName="Signer",
clientUserId="101"
},
},
};
envelope.Create("\FAQ_NMS.pdf");
bool result = envelope.GetSenderView("my domain");
/*Saving document details into Database*/
if (result)
{
ObjDocumentSignRequest obj = new ObjDocumentSignRequest();
obj.DocumentId = docId;
obj.EnvelopeId = envelope.EnvelopeId;
obj.SenderViewUrl = envelope.SenderViewUrl;
eSignUtilities.SaveSignRequest(obj);
}
return envelope.SenderViewUrl;
}
public void EmbeddedRecepientView(string docId)
{
Account account = InitializeDocSign();
Envelope envelope = new Envelope();
envelope.Login = account;
envelope.EmailSubject = "Please sign document";
envelope.Recipients = new Recipients()
{
signers = new Signer[]
{
new Signer()
{
email = "xxxx#gmail.com",
name = "AV Gmail 1",
routingOrder = "1",
recipientId = "1",
roleName="Signer",
clientUserId="101"
},
},
};
envelope.EnvelopeId = "xxxxxxxxxxx";
envelope.UpdateStatus();
bool result = envelope.GetRecipientView("my domain");
Any help?
Thanks
AV
You need to send the envelope before you can request the signing URL (aka recipient view). It looks like you are creating the envelope, generating the embedded sending URL, then trying to generate the embedded signing URL right after that.
I see before you call GetRecipientView() that you are calling
envelope.UpdateStatus();
However, I don't see you set
envelope.Status = "sent";
...anywhere before that, which means you are requesting an embedded signing URL on an envelope which is in the draft state, which will generate an error.
It resolved by using "GetEmbeddedSignerView" method
Account account = InitializeDocSign();
Envelope envelope = new Envelope();
envelope.Login = account;
// assign the envelope id that was passed in
envelope.EnvelopeId = "xxxxx-xxx-xxx-xx-xxxxxxx";
var signer = new Signer
{
email = "xxxxx#gmail.com",
name = "AV xxxx 1",
clientUserId = "101",
recipientId = "1"
};
// generate the recipient view token
string signingUrl = envelope.GetEmbeddedSignerView("http://www.google.com", signer);

Resources