user1675630
user1675630

Reputation:

Docusign REST API Call - "Boundary Terminator was not Found"

I am trying to call Docusign REST API as is outlined in the "Step 3: Send signature request on behalf of User 2" Section in this link. I get the following error below. What is the boundary supposed set to? How do I correctly set it?

{ "errorCode": "INVALID_MULTI_PART_REQUEST", "message": "An error was found while parsing the multipart request. Boundary terminator '--BOUNDARY; charset=utf-8--' was not found in the request." }

public static string HttpRequest(string url, List<CELPHttpHeader> headerList, EnvelopeDefinition envelopeDefination)
{
    string responseString = string.Empty;

    HttpClient client = new HttpClient();
    client.DefaultRequestHeaders.Add("accept", "application/json");

    MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("multipart/form-data");   
    NameValueHeaderValue item = new NameValueHeaderValue("boundary", "BOUNDARY");
    mediaType.Parameters.Add(item);

    JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter();

    HttpRequestMessage requestMessage = new HttpRequestMessage();
    requestMessage.Method = HttpMethod.Post;
    requestMessage.Content = new ObjectContent<EnvelopeDefinition>(envelopeDefination, formatter, mediaType);

    foreach (CELPHttpHeader header in headerList)
    {
        client.DefaultRequestHeaders.Add(header.Name, header.Value);
    }

    try
    {
        Task<HttpResponseMessage> webTaskResult = client.PostAsync(url, requestMessage.Content);
        webTaskResult.Wait();
        HttpResponseMessage response = webTaskResult.Result;
    }
    catch (Exception ex)
    {

    }

    return (responseString);
}

Upvotes: 0

Views: 363

Answers (1)

Luis
Luis

Reputation: 2702

A snippet of what the API request should look like is below:

--BOUNDARY

Content-Type: application/json
Content-Disposition: form-data

{
   <JSON request here>
}

--BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="test1.pdf"; documentid=1
Content-Transfer-Encoding: base64

JVBERi0xLjUNJeLjz9MNCjMwMDIgMCBvYmoNPDwvTGluZWFyaXplZCAxL0wgMTM1
  <snipped>
V1sxIDMgMF0+PnN0cmVhbQ0KaN5iYhRZU8PEwCDsBCQY1wMJpicAAQYAHeIDMQ0K
ZW5kc3RyZWFtDWVuZG9iag1zdGFydHhyZWYNCjEzNjA0NjUNCiUlRU9GDQo=

--BOUNDARY--

Upvotes: 3

Related Questions