Reputation: 85
I need to create an Envelope using Rest API in Docusign, but I'm getting the response as
The URL provided does not resolve to a resource.
Tried the below code
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(config.Value.BaseUrl);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
var requestContent = new MultipartFormDataContent();
var filePath = System.IO.Path.Combine("Sample.pdf");
byte[] pdfBytes = System.IO.File.ReadAllBytes(filePath);
// Add PDF document
//byte[] pdfBytes = System.IO.File.ReadAllBytes(pdfFilePath);
requestContent.Add(new ByteArrayContent(pdfBytes), "file", "Sample.pdf");
// Add recipient information
var recipient = new
{
email = recipientEmail,
name = recipientName,
recipientId = "1",
clientUserId = "123" // Unique identifier for the recipient in your system
};
var recipients = new { signers = new[] { recipient } };
requestContent.Add(new StringContent(JsonConvert.SerializeObject(recipients), Encoding.UTF8, "application/json"), "recipients");
HttpResponseMessage response = await httpClient.PostAsync("envelopes", requestContent);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"Failed to create envelope: {response.ReasonPhrase}");
}
string responseContent = await response.Content.ReadAsStringAsync();
dynamic responseData = JsonConvert.DeserializeObject(responseContent);
return responseData.envelopeId;
}
Upvotes: 0
Views: 61
Reputation: 14005
I would suggest you add the nuget package https://www.nuget.org/packages/DocuSign.eSign.dll/7.0.0-rc1
This makes things a lot easier for you. The C# code would then be found in this GitHub repo - https://github.com/docusign/code-examples-csharp
If you don't want to do that, you need to ensure the correct URL was used here.
The URL you should have starts with {{baseUrl}}/v2.1/accounts/{{accountId}}/envelopes
So it will be https://demo.docusign.net/restapi/v2.1/accounts/{Your GUID}/envelopes
httpClient.BaseAddress = new Uri(config.Value.BaseUrl);
baseURL
will not be the URL you use to make API call, and I'm not sure what it is. It's most likely wrong.
Upvotes: 0