使用 C# 在 Docusign 中创建信封

问题描述 投票:0回答:1

我需要在 Docusign 中使用 Rest API 创建一个信封,但我得到的响应为

提供的 URL 无法解析为资源。

尝试了以下代码

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;
}
c# docusignapi envelope docusignconnect
1个回答
0
投票

我建议您添加 nuget 包 https://www.nuget.org/packages/DocuSign.eSign.dll/7.0.0-rc1

这会让你的事情变得更容易。然后可以在此 GitHub 存储库中找到 C# 代码 - https://github.com/docusign/code-examples-csharp

如果您不想这样做,则需要确保此处使用了正确的 URL。

httpClient.BaseAddress = new Uri(config.Value.BaseUrl);

baseURL
不会是您用于进行 API 调用的 URL,我不确定它是什么。这很可能是错误的。

© www.soinside.com 2019 - 2024. All rights reserved.