You can sign up for a free developer sandbox.
Xcode 6.2 or later.
Create a podfile, run pod install, then use the .xcworkspace
project file moving forward. To use the clients in this manner, do the following:
-
At the command line run the following RubyGems command to install cocoapods (note: this might require sudo):
$ gem install cocoapods
-
Create a file in your root project directory called
Podfile
with the following content. Replace the two references to PROJECT below with your unique project name:
pod 'DocuSignESign', '~> 2.0.0'
- Run the following command in the same directory as your Podfile:
$ pod install
Once you are done installing, close Xcode and open the newly created .xcworkspace
project file. Make sure you use this work space going forward!
Copy the source files directly into your existing project’s source directories and add corresponding import statements.
- AFNetworking ~> 2.3
- JSONModel ~> 1.1
- ISO8601 ~> 0.3
To initialize the client and make the Login API Call:
#import <DocuSignESign/DSApiClient.h>
#import <DocuSignESign/DSAuthenticationApi.h>
#import <DocuSignESign/DSEnvelopesApi.h>
int main(int argc, char * argv[]) {
NSString *IntegratorKey = @"<#INTEGRATOR_KEY#>";
NSString *username = @"<#EMAIL#>";
NSString *password = @"<#PASSWORD#>";
NSString *host = @"https://demo.docusign.net/restapi";
// create authentication JSON string and header
NSString *const DS_AUTH = [NSMutableString stringWithFormat:@"{\"Username\":\"%@\",\"Password\":\"%@\",\"IntegratorKey\":\"%@\"}", username, password, IntegratorKey];
NSString *const DS_AUTH_HEADER = @"X-DocuSign-Authentication";
// instantiate api client, configure environment URL and assign auth data
DSApiClient* apiClient = [[DSApiClient alloc] initWithBaseURL:[[NSURL alloc] initWithString:host]];
DSAuthenticationApi *authApi = [[DSAuthenticationApi alloc] initWithApiClient:apiClient];
[authApi addHeader:DS_AUTH forKey:DS_AUTH_HEADER];
__block NSString *accountId = nil;
XCTestExpectation* expectation = [self expectationWithDescription:@"Sample Signature Request from Template"];
// Login to get the account for the user (if you have the accountId then skip this part)
[authApi loginWithCompletionBlock:^(DSLoginInformation *output, NSError *error) {
if (error) {
NSLog(@"got error %@", error);
}
if (!output) {
NSLog(@"response can't be nil");
}
DSLoginAccount *loginAccount = [output.loginAccounts objectAtIndex: 0];
accountId = loginAccount.accountId;
// Update ApiCLient with the new base url from login call
NSString *newHost = [[loginAccount.baseUrl componentsSeparatedByString:@"/v2"] objectAtIndex:0];
DSApiClient* apiClient = [[DSApiClient alloc] initWithBaseURL:[[NSURL alloc] initWithString:newHost]];
// instantiate a new envelope
DSEnvelopesApi *envelopesApi = [[DSEnvelopesApi alloc] initWithApiClient:apiClient];
[envelopesApi addHeader:DS_AUTH forKey:DS_AUTH_HEADER];
// create envelope with single document, single signer and one signature tab
DSEnvelopeDefinition* envelopeDefinition = [[DSEnvelopeDefinition alloc] init];
envelopeDefinition.emailSubject = @"[DocuSign ObjC SDK] - Sample Signature Request from Template";
// to use a template we must reference the correct template id
envelopeDefinition.templateId = @"<#TEMPLATE_ID#>";
// assign recipient to template role by setting name, email, and role name. Note that the
// template role name must match the placeholder role name saved in your account template.
DSTemplateRole* templateRole = [[DSTemplateRole alloc] init];
templateRole.email = @"<#RECIPIENT_EMAIL#>";
templateRole.name = @"<#RECIPIENT_NAME#>";
templateRole.roleName = @"<#ROLE_NAME#>";
// add the role to the envelope and assign valid templateId from your account
envelopeDefinition.templateRoles = [NSArray<DSTemplateRole> arrayWithObjects:templateRole, nil];;
// set envelope status to "sent" to immediately send signature request, otherwise it's saved as a draft
envelopeDefinition.status = @"sent";
DSEnvelopesApi_CreateEnvelopeOptions* createEnvelopeOptions = [[DSEnvelopesApi_CreateEnvelopeOptions alloc] init];
createEnvelopeOptions.cdseMode = @"false";
createEnvelopeOptions.mergeRolesOnDraft = @"false";
[envelopesApi createEnvelopeWithAccountId:accountId envelopeDefinition:envelopeDefinition options:createEnvelopeOptions completionHandler:^(DSEnvelopeSummary *output, NSError *error) {
if (output != nil && output.envelopeId != nil) {
XCTAssertNotNil(output.envelopeId);
} else if(error !=nil) {
XCTFail(@"%@", error);
} else {
XCTFail(@"Unknow error occured. Please try again later.");
}
}]; // end createEnvelopeWithAccountId
[expectation fulfill];
}]; // end login completion block
[self waitForExpectationsWithTimeout:2.0 handler:nil];
}
See SdkTestsTests.m for more examples.
(Legacy Header Authentication uses the X-DocuSign-Authentication header.)
- Use the Authentication: login method to retrieve the account number and the baseUrl for the account.
The url for the login method is www.docusign.net for production and demo.docusign.net for the developer sandbox.
The
baseUrl
field is part of theloginAccount
object. See the docs and the loginAccount object - The baseUrl for the selected account, in production, will start with na1, na2, na3, eu1, or something else. Use the baseUrl that is returned to create the basePath (see the next step.) Use the basePath for all of your subsequent API calls.
- As returned by login method, the baseUrl includes the API version and account id. Split the string to obtain the basePath, just the server name and api name. Eg, you will receive
https://na1.docusign.net/restapi/v2/accounts/123123123
. You want justhttps://na1.docusign.net/restapi
- Instantiate the SDK using the basePath. Eg
ApiClient apiClient = new ApiClient(basePath);
- Set the authentication header as shown in the examples by using
Configuration.Default.AddDefaultHeader
- After obtaining a Bearer token, call the OAuth: Userinfo method. Obtain the selected account's
base_uri
(server name) field. The url for the Userinfo method is account-d.docusign.com for the demo/developer environment, and account.docusign.com for the production environment. - Combine the base_uri with "/restapi" to create the basePath. The base_uri will start with na1, na2, na3, eu1, or something else. Use the basePath for your subsequent API calls.
- Instantiate the SDK using the basePath. Eg
ApiClient apiClient = new ApiClient(basePath);
- Create the
authentication_value
by combining thetoken_type
andaccess_token
fields you receive from either an Authorization Code Grant or Implicit Grant OAuth flow. - Set the authentication header by using
Configuration.Default.AddDefaultHeader('Authorization', authentication_value)
Unit tests are available here.
Feel free to log issues against this client through GitHub. We also have an active developer community on Stack Overflow, search the DocuSignAPI tag.
The DocuSign Objc Client is licensed under the following License.
This version of the client library does not implement all of the DocuSign REST API methods. The current client omits methods in the Accounts, Billing, Cloud Storage, Connect, Groups (Branding), and Templates (Bulk Recipients) categories. The client's methods support the core set of use cases that most integrations will encounter. For a complete list of omitted endpoints, see Omitted Endpoints.