Chilkat Online Tools

Android / DocuSign Click API / 2. Create Envelope in Draft Stage

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    boolean success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "documents": [
    //     {
    //       "documentBase64": "{{documentBase64}}",
    //       "documentId": "123",
    //       "fileExtension": "pdf",
    //       "name": "document"
    //     }
    //   ],
    //   "emailSubject": "Simple Signing Example",
    //   "recipients": {
    //     "signers": [
    //       {
    //         "email": "{{email}}",
    //         "name": "{{name}}",
    //         "recipientId": "{{recipientId}}"
    //       }
    //     ]
    //   },
    //   "status": "created"
    // }

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("documents[0].documentBase64","{{documentBase64}}");
    json.UpdateString("documents[0].documentId","123");
    json.UpdateString("documents[0].fileExtension","pdf");
    json.UpdateString("documents[0].name","document");
    json.UpdateString("emailSubject","Simple Signing Example");
    json.UpdateString("recipients.signers[0].email","{{email}}");
    json.UpdateString("recipients.signers[0].name","{{name}}");
    json.UpdateString("recipients.signers[0].recipientId","{{recipientId}}");
    json.UpdateString("status","created");

    http.SetRequestHeader("Content-Type","application/json");
    // Adds the "Authorization: Bearer {{accessToken}}" header.
    http.put_AuthToken("{{accessToken}}");

    CkHttpResponse resp = http.PostJson3("https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, String.valueOf(resp.get_StatusCode()));
    Log.i(TAG, resp.bodyStr());


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Authorization: Bearer {{accessToken}}"
	-d '{
  "documents": [
    {
      "documentBase64": {{document}},
      "documentId": "123",
      "fileExtension": "pdf",
      "name": "document"
    }
  ],
  "emailSubject": "Simple Signing Example",
  "recipients": {
    "signers": [
      {
        "email": {{user1}},
        "name": {{user1_name}},
        "recipientId": "{{recipientId}}"
      }
    ]
  },
  "status": "created"
}'
https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes

Postman Collection Item JSON

{
  "name": "2. Create Envelope in Draft Stage",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{accessToken}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"documents\": [\n    {\n      \"documentBase64\": {{document}},\n      \"documentId\": \"123\",\n      \"fileExtension\": \"pdf\",\n      \"name\": \"document\"\n    }\n  ],\n  \"emailSubject\": \"Simple Signing Example\",\n  \"recipients\": {\n    \"signers\": [\n      {\n        \"email\": {{user1}},\n        \"name\": {{user1_name}},\n        \"recipientId\": \"{{recipientId}}\"\n      }\n    ]\n  },\n  \"status\": \"created\"\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/{{apiVersion}}/accounts/{{accountId}}/envelopes",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "{{apiVersion}}",
        "accounts",
        "{{accountId}}",
        "envelopes"
      ]
    },
    "description": "In this example, we are creating an envelope similar to the previous step. However, we are keeping it in `draft` stage so can continue to make changes to it. If the status was set to `sent` the envelope would be sent to users."
  },
  "response": [
  ]
}