DocuSign ListRecipients() not working, but other calls OK - c#

I am using the Docusign eSign API for an integration. My integration key works fine with building and sending envelopes, and with checking envelope status (using GetEnvelope()). But ListRecipients() doesn't work. I have been following the documentation from here: https://developers.docusign.com/docs/esign-rest-api/how-to/get-envelope-recipients/.
My recipient-checking code is:
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + authToken.access_token.ToString()); // I am suspicious of this line
var envelopesApi = new EnvelopesApi(apiClient);
foreach (var envelope in envelopes)
{
List<SignerModel> listSigners = new List<SignerModel>();
Recipients results = envelopesApi.ListRecipients(_apiAccountId, envelope.envelopeId.ToString());
// Do something with it...
}
When I run this with the suspicious line in place (un-commented) I get this error message at that line:
GetSigners error: Object reference not set to an instance of an object.
When I comment it out I get the same error message at the ListRecipients() call.
This is how I am getting my access token:
List<string> docusignScopes = new List<string> { "impersonation", "signature" };
apiClient = new ApiClient(_restBasePath);
authToken = apiClient.RequestJWTUserToken(
_clientId,
_impersonatedUserId,
_authServer,
privateKeyBytes, 1, docusignScopes);
Why is the listRecipients call not working?

I tested this code and it works just fine. Make sure to put your envelopeID in there. Try this basic code and let me know:
var apiClient = new ApiClient(basePath);
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
var rec = envelopesApi.ListRecipients(accountId, "4f925c10-xxxxxx-xxx-xxxx-xxxxxx");

Related

CreateEnvelope() throws exception. No message

I am trying to create and send an envelope on the demo environment using the docusign C# API. I am using JWT as my OAuth2 flow. I am able to properly grab the access code needed to authorized my embedded signing.
The function CreateEnvelope fails and throws an exception. The exception shows no information other than that the function failed.
Image of Exception
Has anyone encountered a similar situation before? I have provided a snippet of the code below. Is there anything clearly wrong with how I may be trying to create the envelope?
public static void DocusignFormatter()
{
EnvelopeDefinition envDef = new EnvelopeDefinition();
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(pdfFileInfo.fileBytes);
doc.Name = pdfFileInfo.DocName;
doc.DocumentId = "1";
envDef.Documents = new List<Document>();
envDef.Documents.Add(doc);
envDef.Recipients = new Recipients();
envDef.Recipients.Signers = new List<Signer>();
for (int i = 0; i < signatureFields.Count; i++)
{
Signer signer = new Signer();
signer.Email = docRegistrant.Email;
signer.Name = docApplicants[i].FirstName + " " + docApplicants[i].LastName;
signer.RecipientId = $"{i+1}";
signer.Tabs = new Tabs();
signer.Tabs.SignHereTabs = new List<SignHere>();
List<MyPdfSignatureField> fields;
signatureFields.TryGetValue(i, out fields);
foreach (MyPdfSignatureField field in fields)
{
SignHere signHere = new SignHere();
signHere.DocumentId = "1";
signHere.PageNumber = field.PageNum.ToString();
signHere.RecipientId = i.ToString();
signHere.XPosition = field.XLocation.ToString();
signHere.YPosition = field.YLocation.ToString();
signer.Tabs.SignHereTabs.Add(signHere);
}
envDef.Recipients.Signers.Add(signer);
}
envDef.Status = "created";
ApiClient apiClient = new ApiClient(DocusignHelpers.OAuthBasePath);
Configuration cfi = new Configuration(apiClient);
cfi.AddDefaultHeader("Authorization", "Bearer " + DocusignHelpers.AccessToken);
cfi.AccessToken = DocusignHelpers.AccessToken;
cfi.Password = DocusignHelpers.Password;
EnvelopesApi envelopesApi = new EnvelopesApi(cfi);
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(DocusignHelpers.AccountId, envDef);
Caught Exception values
you are missing this line:
envDef.EmailSubject = "Test, please sign.";
But that's not the reason for the exception, since you created it as "created" (draft) mode, but it would be the issue once you try to send it.
You may want to confirm the values of all your recipients and ensure you're not sending something that's not an email (for example) in an email field etc.
I solved this friends.
My api url was incorrect.
My key confusion was that the auth endpoints have a separate base url than the rest of the RESTful API.
Authorization url for the demo was: https://account-d.docusign.com
The API client object actually has static fields that contain the urls for the different platforms demo, prod, staging.
I ended up using
ApiClient.Demo_REST_BasePath = "https://demo.docusign.net/restapi"
Thank you all for the replies and help

INVALID_REQUEST_BODY Error calling ListStatusAsync using C# DocuSign SDK

I am using C# DocuSign SDK. I am simply trying to retrieve Envelopes, so using EnvelopesApi.ListStatusAsync. Like this:
EnvelopesApi envelopeApi = new EnvelopesApi(ApiClient.Configuration);
var options = new ListStatusOptions();
var date = DateTime.Now.AddDays(-30);
options.fromDate = date.ToString("yyyy/MM/dd");
var envelopesList = envelopeApi.ListStatusAsync(AccountId, null, options);
Response:
Error calling ListStatus:
{
"errorCode": "INVALID_REQUEST_BODY",
"message": "The request body is missing or improperly formatted."
}
Fiddler shows a 400. I can see Access Token is included in the request (Bearer Authorization Header), so no issues there. Fiddler shows PUT request:
https://demo.docusign.net/restapi/v2.1/accounts/[Account_ID_Guid]/envelopes/status?from_date=2019%2f12%2f14
Basically, this is code retrieved from: https://github.com/docusign/qs-csharp. Only difference is using ListStatusAsync instead of ListStatus. Am I missing something related to Body?
Your code doesn't quite match what the QuickStart example does. In the QS, the method used is ListStatusChanges, not ListStatus.
Try this to get a list of envelopes from the past 30 days:
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);
var options = new EnvelopesApi.ListStatusChangesOptions();
var date = DateTime.Now.AddDays(-30);
options.fromDate = date.ToString("yyyy/MM/dd");
var envelopesList = envelopesApi.ListStatusChanges(accountId, options);
var envelopesListFromAsync = envelopesApi.ListStatusChangesAsync(accountId, options);

SendGrid V3 api with C#. email not sending

is there something wrong with this code? I already put my email in my code but I don't get any email.
I have a hint that is it not working because I am using API key ID instead of API key because I can't see my API key because of its only show just once. if is that the reason why is this code not working. Is there no way to view your API key again?
public string SendEmailMain()
{
SendEmail().Wait();
}
static async Task SendEmail()
{
common com = new common();
var apiKey = com.sendGridAPI;
var client = new SendGridClient(apiKey);
var from = new EmailAddress("testmail#gmail.com", "test user");
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress("testemai#gmail.com", "teset user");
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);
}
the code is working pretty well. The thing is i'm using the API key ID because instead of the API key that generated by sendgrid.
Please refer to this thread for more info

Consume WSDL that requires action level authorization in C#

I'm attempting to consume a 3rd party WSDL. I have added it as a service reference. I initalize the client and query paramaters like this:
var ltRequest = new SearchEmailAddressStatus
{
EmailAddress = emailAddressList.ToArray()
};
var ltClient = new CommunicationPreferenceServiceClient
{
ClientCredentials =
{
UserName =
{
UserName = ltProperties.CompanyCredential.UserName,
Password = ltProperties.CompanyCredential.Password
}
}
};
var ltResponse = ltClient.searchEmailAddressStatusWS(ltRequest);
After watching the packets in Fiddler, I've noticed the Auth header is never sent to the server. Is there any way to manually insert an authorization header in my request?
Okay, after a lot of digging I found the answer. After declaring the client, I used the following code:
using (var scope = new OperationContextScope(ltClient.InnerChannel))
{
var reqProperty = new HttpRequestMessageProperty();
reqProperty.Headers[HttpRequestHeader.Authorization] = "Basic "
+ Convert.ToBase64String(Encoding.ASCII.GetBytes(
ltClient.ClientCredentials.UserName.UserName + ":" +
ltClient.ClientCredentials.UserName.Password));
OperationContext.Current
.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = reqProperty;
var ltResponse = ltClient.searchEmailAddressStatusWS(ltRequest);
}
I believe this is the least-dirty means of getting a customized header inside wsdl request. If someone has a better method, I'd love to hear it.

Error 401 in C#

I'm working on my first app for Windows 8 but I have a problem, when I'm launch my app, I've got the error "Response status code does not indicate success:
401 (Authorization Required)
So yes, I need to include username and password but I don't know where in my code:
var fond = new HttpClient();
var reponse = await fond.GetStreamAsync("http://example.com/search/mario%20kart" + TitleNewsGrid.Text);
So where I'm include the username and password in the code?
There should be a Credentials property in the TransportSettings e.g.
using (var client = new HttpClient())
{
client.TransportSettings.Credentials = new System.Net.NetworkCredential("username", "pwd");
...
}
If you don't have access to the TransportSettings property, you will need to use HttpClientHandler instead. No point in duplicating code, there is already a good example here.
try this
client.TransportSettings.Credentials = new System.Net.NetworkCredential("username", "password");
for more info
http://msdn.microsoft.com/en-us/library/system.net.http.httpclient%28v=vs.110%29.aspx

Categories