How to Create a Package
The first part of the package JSON string is the roles object. Inside this, you can set items like the id, company, first name, last name, email, and name to customize your signer roles. Some of the other notable settings would be email, message, title, and delivery.
{ "roles":[ { "id":"Role1", "signers":[ { "email":"signer1@example.com", "firstName":"1.firstname", "lastName":"1.lastname", "company":"Conga Sign" } ] },
The next section of the package JSON string is the documents object. Inside this, you will set items like the name and the approvals (signature blocks).
"documents":[ { "approvals":[ { "role":"Role1", "fields":[ { "page":0, "top":100, "subtype":"FULLNAME", "height":50, "left":100, "width":200, "type":"SIGNATURE" } ] },
In the approvals, the main items to set would be the type, subtype, role, page, and location settings. These will define the signatures required in each document.
jsonString += "\"documents\":[{\"approvals\":[{\"role\":\"Role1\",\"fields\":[{\"page\":0,\"top\":100,\"subtype\":\"FULLNAME\",\"height\":50,\"left\":100,\"width\":200,\"type\":\"SIGNATURE\"}]},{\"role\":\"Role2\",\"fields\":[{\"page\":0,\"top\":300,\"subtype\":\"FULLNAME\",\"height\":50,\"left\":100,\"width\":200,\"type\":\"SIGNATURE\"}]}],\"name\":\"Test Document\"}],";
Finally, the last few settings of the package JSON string that you will want to note are the name, type, status, emailMessage, and autoComplete. In this example, status is set to SENT. This will send the package and notify the signers. If you want to save this package as a draft, make the value DRAFT, instead.
jsonString += "\"name\":\"Example Package\",\"type\":\"PACKAGE\",\"language\":\"en\",\"emailMessage\":\"\",\"description\":\"New Package\",\"autocomplete\":true,\"status\":\"SENT\""; jsonString += "}";
The next line of the code will take your JSON string and make the StringContent object that you will pass as the payload in your REST API command.
StringContent jsonContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
These next lines read your PDF file and use that to create the file ByteArrayContent object for your REST call. Be sure to change the placeholder to your filepath.
byte[] fileByteArray = File.ReadAllBytes("PATH_TO_YOUR_PDF.pdf"); ByteArrayContent content = new ByteArrayContent(fileByteArray);
The next section defines the content-disposition header of the PDF file content object.
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); content.Headers.ContentDisposition.Name = "\"file\""; content.Headers.ContentDisposition.FileName = "\"NAME_OF_YOUR_FILE.pdf\""; content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
The next block is where you create your multipart form and add your content objects created above to pass with your REST call. Be sure to set the File name.
MultipartFormDataContent form = new MultipartFormDataContent(); form.Add(content, "\"file\"", "\"NAME_OF_YOUR_FILE.pdf\""); form.Add(jsonContent, "\"payload\"");
Next, create the HttpClient that you will use to make your POST request and set the appropriate header authorization and accept values.
HttpClient myClient = new HttpClient(); myClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", apiKey); myClient.DefaultRequestHeaders.Add("Accept", "application/json");
Finally, you will make the PST call and pass your form to Conga Sign, creating your document package. The Debug line will display the result to the debug output console.
var response = myClient.PostAsync(new Uri(url) + "/packages/", form).Result; Debug.WriteLine(response.Content.ReadAsStringAsync().Result);