0
votes

I wanted to use my own logic for requesting signature but after the signature is complete, I want to send the Signed Image (as png) to DocuSign Envelope. I looked at the "Set Signature Image for Accountless Signer" flow and it seemed to be working fine, but the signature image is not embedded in my envelope.

This is what I am doing

  1. Get the Account Information
  2. Create Envelope from a Template as "Created(Draft)" status
  3. Add a recipient
  4. Add a Signature Tab
  5. Update the Envelope Status from "Created" to "Sent"
  6. Set the Signature Image for Recipient.

Everything seems to be working fine without any errors. But I dont see the image. Please let me know if I am doing anything wrong or if you have any examples of Sending Signature Image to Envelopes.

1
Question - what is it that you are trying to do? Are you trying to do the signing on your own and then just upload the completed envelope to DocuSign or do you just want to feed DocuSign the image from your system as the selected eSignature? - mikebz
I am trying to build an app for in-person signature on iPad. I wanted to build my own UI for person signing(basically allowing him to draw his sign) and then send that signature image to Docusign to attach it to envelope. - user2608913
Send me a message with your email. I don't know if doing this is a simple answer and stack overflow doesn't lend itself to a back and fourth and discovery. - mikebz

1 Answers

0
votes

Feel free to contact us for a more creative solution, however the easiest way to get a signature on an iPad is to delegate the signature image collection to DocuSign altogether. here is a way to get a signature on a template (you can also do it with document byte stream). This is taken from the GitHub gist: https://gist.github.com/Ergin008/5645812.

The view for signing can be displayed in a webview in your iOS app.

//
//  API Walkthrough 8 - Launch the signing (recipient) view of an envelope in an embedded session
//
//  To run this sample:
//      1.  Copy the below code into your iOS project
//      2.  Enter your email, password, integrator key, name, templateId, and roleName and save
//      3.  Run the code
//

- (void)embeddedSigning
{
    // Enter your info:
    NSString *email = @"<#email#>";
    NSString *password = @"<#password#>";
    NSString *integratorKey = @"<#integratorKey#>";
    NSString *name = @"<#name#>";

    // use same name as template role you saved through the Console UI
    NSString *roleName = @"<#roleName#>";

    // need to login to the console and copy a valid templateId into this string
    NSString *templateId = @"<#templateId#>";

    ///////////////////////////////////////////////////////////////////////////////////////
    // STEP 1 - Login (retrieves accountId and baseUrl)
    ///////////////////////////////////////////////////////////////////////////////////////

    NSString *loginURL = @"https://demo.docusign.net/restapi/v2/login_information";

    NSMutableURLRequest *loginRequest = [[NSMutableURLRequest alloc] init];
    [loginRequest setHTTPMethod:@"GET"];
    [loginRequest setURL:[NSURL URLWithString:loginURL]];

    // set JSON formatted X-DocuSign-Authentication header (XML format also accepted)
    NSDictionary *authenticationHeader = @{ @"Username": email, @"Password" : password, @"IntegratorKey" : integratorKey };

    // jsonStringFromObject() function defined below...
    [loginRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];

    // also set the Content-Type header (other accepted type is application/xml)
    [loginRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    //*** make an asynchronous web request
    [NSURLConnection sendAsynchronousRequest:loginRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *loginResponse, NSData *loginData, NSError *loginError) {

        if (loginError) {   // succesful GET returns status 200
            NSLog(@"Error sending request %@. Got Response %@ Error is: %@", loginRequest, loginResponse, loginError);
            return;
        }

        // we use NSJSONSerialization to parse the JSON formatted response
        NSError *jsonError = nil;
        NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:loginData options:kNilOptions error:&jsonError];
        NSArray *loginArray = responseDictionary[@"loginAccounts"];

        // parse the accountId and baseUrl from the response and use in the next request
        NSString *accountId = loginArray[0][@"accountId"];
        NSString *baseUrl = loginArray[0][@"baseUrl"];

        //--- display results
        NSLog(@"\naccountId = %@\nbaseUrl = %@\n", accountId, baseUrl);

        ///////////////////////////////////////////////////////////////////////////////////////
        // STEP 2 - Create Envelope via Template and send the envelope
        ///////////////////////////////////////////////////////////////////////////////////////

        // append "/envelopes" URI to your baseUrl and use as endpoint for signature request call
        NSString *envelopesURL = [NSString stringWithFormat:@"%@/envelopes",baseUrl];

        NSMutableURLRequest *signatureRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:envelopesURL]];

        [signatureRequest setHTTPMethod:@"POST"];
        [signatureRequest setURL:[NSURL URLWithString:envelopesURL]];

        // construct a JSON formatted signature request body (multi-line for readability)
        NSDictionary *signatureRequestData = @{@"accountId": accountId,
                                               @"emailSubject" : @"Embedded Sending API call",
                                               @"emailBlurb" : @"email body goes here",
                                               @"templateId" : templateId,
                                               @"templateRoles" : [NSArray arrayWithObjects: @{@"email":email, @"name": name, @"roleName": roleName, @"clientUserId": @"1001" }, nil ],
                                               @"status" : @"sent"
                                               };

        // convert request body into an NSData object
        NSData* data = [[self jsonStringFromObject:signatureRequestData] dataUsingEncoding:NSUTF8StringEncoding];

        // attach body to the request
        [signatureRequest setHTTPBody:data];

        // authentication and content-type headers
        [signatureRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];
        [signatureRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

        // Send the signature request...
        [NSURLConnection sendAsynchronousRequest:signatureRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *envelopeResponse, NSData *envelopeData, NSError *envelopeError) {

            NSError *jsonError = nil;
            NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:envelopeData options:kNilOptions error:&jsonError];
            NSLog(@"Signature request sent, envelope info is: \n%@\n", responseDictionary);

            // parse envelopeId from resposne as it will be used in next request
            NSString *envelopeId = responseDictionary[@"envelopeId"];

            ///////////////////////////////////////////////////////////////////////////////////////
            // STEP 3 - Get the Embedded Signing View (aka recipient view) of the envelope
            ///////////////////////////////////////////////////////////////////////////////////////

            // append /envelopes/{envelopeId}/views/recipient to baseUrl and use in request
            NSString *embeddedURL = [NSString stringWithFormat:@"%@/envelopes/%@/views/recipient", baseUrl, envelopeId];

            NSMutableURLRequest *embeddedRequest = [[NSMutableURLRequest alloc] init];
            [embeddedRequest setHTTPMethod:@"POST"];
            [embeddedRequest setURL:[NSURL URLWithString:embeddedURL]];

            // simply set the returnUrl in the request body (user is directed here after signing)
            NSDictionary *embeddedRequestData = @{@"returnUrl": @"http://www.docusign.com/devcenter",
                                                  @"authenticationMethod" : @"none",
                                                  @"email" : email,
                                                  @"userName" : name,
                                                  @"clientUserId" : @"1001" // must match clientUserId set is step 2
                                                  };

            // convert request body into an NSData object
            NSData* data = [[self jsonStringFromObject:embeddedRequestData] dataUsingEncoding:NSUTF8StringEncoding];

            // attach body to the request
            [embeddedRequest setHTTPBody:data];

            // set JSON formatted X-DocuSign-Authentication header (XML format also accepted)
            NSDictionary *authenticationHeader = @{ @"Username": email, @"Password" : password, @"IntegratorKey" : integratorKey };

            // jsonStringFromObject() function defined below...
            [embeddedRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];

            // also set the Content-Type header (other accepted type is application/xml)
            [embeddedRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

            //*** make an asynchronous web request
            [NSURLConnection sendAsynchronousRequest:embeddedRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *embeddedResponse, NSData *embeddedData, NSError *embeddedError) {

                if (embeddedError) {   // succesful POST returns status 201
                    NSLog(@"Error sending request %@. Got Response %@ Error is: %@", embeddedRequest, embeddedResponse, embeddedError);
                    return;
                }

                // we use NSJSONSerialization to parse the JSON formatted response
                NSError *jsonError = nil;
                NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:embeddedData options:kNilOptions error:&jsonError];
                NSString *embeddedURLToken = responseDictionary[@"url"];

                //--- display results
                NSLog(@"URL token created - please navigate to the following URL to start the embedded signing workflow:\n\n%@\n\n", embeddedURLToken);
            }];
        }];
    }];
}

- (NSString *)jsonStringFromObject:(id)object {
    NSString *string = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:object options:0 error:nil] encoding:NSUTF8StringEncoding];
    return string;
}