Skip to navigation

How to make a direct API call

View as Markdown

This topic demonstrates how you can make a direct API call to the eSignature REST API from the Docusign iOS SDK module if there is no existing SDK method; in this case, to retrieve a user’s signature ID.

Required data

Running the code in this how-to requires this data:

Data elementDescription
{API_ACCOUNT_ID}A GUID value that identifies your account. This value is automatically generated by Docusign for any account you create. Copy the value from the API Account ID field on the Apps and Keys page.
{BASE_PATH}A string value that forms the root of the URL required to make API calls. The base path value in the example code is set to target the developer environment at
https://<domain>/restapi
Where <domain> is demo.docusign.net for the developer environment.
{IMPERSONATION_USER_GUID}A GUID value that identifies the user. This value is automatically generated by Docusign. Copy the value from the User ID field on the Apps and Keys page.

Step 1. Log in to Docusign

To make the API calls shown in this how-to, you must be logged in to Docusign.

See How to log in to Docusign from your app for details.

Step 2. Construct your API headers

Use the DSMAccountInfo object that is returned from the log in function in the previous step to retrieve the account information needed to initialize the API client and set API headers.

NSString *accessToken = accountInfo.accessToken;
NSURL *basePath = accountInfo.host;
NSString *accountId = accountInfo.accountId;
NSString *userId = accountInfo.userId;
NSString * token = [[NSString alloc] initWithFormat:@"Bearer %@", accessToken];
// Initializing the API client with the access token and base url
(void)[[DSClientAPI alloc] initWithBasePath:basePath.absoluteString customHeaders:@{@"Authorization": token}];

Step 3. Call the eSignature REST API to get the user signature ID

Next, use the account information you retrieved in step 2 to make the API call via the userSignaturesGetUserSignature method.

[UsersAPI userSignaturesGetUserSignaturesWithAccountId:accountId userId:userId stampType:NULL completion:^(DSAPIUserSignaturesInformation* data, NSError * error) {
if (error) {
NSString *errorDescription = [NSString stringWithFormat:@"[sample-app]-\nUnable to make direct API call-\n%@.", error.localizedDescription];
NSLog(@"%@", errorDescription);
self->_results.text = errorDescription;
return;
} else {
NSString *resultsText = [NSString stringWithFormat:@"User Signature ID: \n%@", data.userSignatures[0].signatureId];
self->_results.text = resultsText;
NSLog(@"%@", data.userSignatures[0].signatureId);
}
}];

Expected response

You should receive your user’s signature ID.

Signature Id: 7faf2365-xxxx-xxxx-xxxx-1cbd9e6dff30

Next steps