Last active
December 10, 2015 00:18
-
-
Save Ergin008/4349883 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# API WALKTHROUGH #1 in Perl - Request Signature from Template | |
# | |
use strict; | |
use LWP 6.00; | |
use JSON; | |
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; | |
# Enter your info: | |
my $username = "***"; | |
my $password = "***"; | |
my $integratorKey = "***"; | |
my $templateId = "***"; | |
my $authHeader = '<DocuSignCredentials><Username>' . $username . '</Username>' . | |
'<Password>' . $password . '</Password>' . | |
'<IntegratorKey>' . $integratorKey . '</IntegratorKey></DocuSignCredentials>'; | |
###################################################################### | |
# STEP 1 - Login | |
###################################################################### | |
my $url = 'https://demo.docusign.net/restapi/v2/login_information'; | |
my $browser = LWP::UserAgent->new; | |
my @requestHeaders = ( | |
'X-DocuSign-Authentication' => $authHeader, | |
'Content-Type' => 'application/json', | |
'Accept' => 'application/json'); | |
my $response = $browser->get( $url, @requestHeaders ); | |
die "Error encountered during login request -- ", $response->status_line . "\n" | |
unless $response->is_success; | |
my $decoded_json = decode_json( $response->content ); | |
my $baseUrl = $decoded_json->{"loginAccounts"}[0]->{"baseUrl"}; | |
my $accountId = $decoded_json->{"loginAccounts"}[0]->{"accountId"}; | |
#-- display results | |
print "\nLogin successful...\nbaseUrl = " . $baseUrl . "\naccountId = " . $accountId . "\n"; | |
###################################################################### | |
# STEP 2 - Request Signature from Template | |
###################################################################### | |
#append "/envelopes" to $baseUrl and use in the next request | |
$url = $baseUrl . "/envelopes"; | |
my %jsonBody = ( | |
'accountId' => $accountId, | |
'emailSubject' => 'Signature Request from Template', | |
'emailBlurb' => 'This comes from Perl', | |
'templateId' => $templateId, | |
'templateRoles' => {'email' => $username, | |
'name' => 'John Doe', | |
'roleName' => 'Signer1'}, | |
'status' => 'sent' | |
); | |
my $jsonEncoded = encode_json \%jsonBody; | |
@requestHeaders = ( | |
'X-DocuSign-Authentication' => $authHeader, | |
'Content-Type' => 'application/json', | |
'Accept' => 'application/json'); | |
my $req = HTTP::Request->new(POST => $url); | |
$req->header( @requestHeaders ); | |
$req->content($jsonEncoded); | |
$response = $browser->request( $req ); | |
die "Error encountered during login request -- ", $response->status_line | |
unless $response->is_success; | |
$decoded_json = decode_json( $response->content ); | |
my $envelopeId = $decoded_json->{"envelopeId"}; | |
#-- display results | |
print "\nDocument sent! EnvelopeId = $envelopeId\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment