aparna

Getting Authorization Error

0 votes
Hi, I am using APEX SDK. While using create Package , i am getting below error: ESignLiveRESTAPIHelper.ESignLiveRestAPIHelperException: Error creating eSignLive package: 401 - Unauthorized - {"entity":null,"messageKey":"error.unauthorised.noSession","technical":null,"packageId":null,"code":401,"message":"Failed to retrieve Session","name":"Unauthorized"}

Reply to: Getting Authorization Error

0 votes
Hi aparna, Did you add esignlive in the remote site settings? Have a look at the Troubleshooting section at the very bottom of this page: https://github.com/KadenceCollective/esignlive-apex-sdk/wiki/SDK-Documentation
Haris Haidary OneSpan Technical Consultant

Reply to: Getting Authorization Error

0 votes
Yes. I have given URL in remote setting, I ave attached screenshot of the remote settings and complete code. I am calling function as below: ESignLiveExamples e = new ESignLiveExamples(); Datetime GMTDate = Datetime.newInstanceGmt(2018,6,1,12,1,5); ESignLiveExamples.createPackageWithDocumentsExample('TestSample', false, 'SamplepackageDescription', GMTDate, 'Test Email Message');

Attachments

Reply to: Getting Authorization Error

0 votes
Here is the complete code: /** * Class Name: ESignLiveExamples.cls * * Class containing examples for using the SDK */ public with sharing class ESignLiveExamples { public ESignLiveExamples(){} /** * Example method for creating a package without any documents */ public static String createPackageExample() { ESignLiveSDK sdk = new ESignLiveSDK(); // Set up the example package ESignLiveAPIObjects.Package_x pkg = new ESignLiveAPIObjects.Package_x(); pkg.name = 'Test Package Name'; pkg.autocomplete = true; pkg.description = 'Sample Description'; pkg.due = System.now().addDays(7); pkg.emailMessage = 'Sample email message'; // Call the SDK method and get the packageId which is returned from the SDK method String packageId = sdk.createPackage(pkg); // Print the packageId to console System.debug('=> Response from createPackageExample: ' + packageId); return packageId; } /** * Example method for creating a package with a document */ public static void createPackageWithDocumentsExample(String packageName, Boolean autocomplete, String packageDescription, DateTime packageDue, String emailMessage) { ESignLiveSDK sdk = new ESignLiveSDK(); // Set up the example package and Document data ESignLiveAPIObjects.Package_x pkg = new ESignLiveAPIObjects.Package_x(); Map blobMap = new Map(); Blob b1 = Blob.valueOf('testDocumentOne'); BLob b2 = Blob.valueOf('test'); blobMap.put('testDocumentOne', b1); blobMap.put('testDocumentTwo', b2); pkg.name = packageName; pkg.autocomplete = autocomplete; pkg.description = packageDescription; ESignLiveAPIObjects.ExtractAnchor ea = new ESignLiveAPIObjects.ExtractAnchor(); ea.text = 'testDocumentOne'; ea.index = 0; ea.width = 150; ea.height = 40; ea.anchorPoint = ESignLiveAPIObjects.AnchorPoint.TOPRIGHT; ea.characterIndex = 12; ea.leftOffset = -20; ea.topOffset = -60; ESignLiveAPIObjects.Field f1 = new ESignLiveAPIObjects.Field(); f1.type = 'SIGNATURE'; f1.page = 0; f1.extract = false; f1.left = 0; f1.subtype = 'FULLNAME'; f1.top = 0; f1.extractAnchor = ea; ESignLiveAPIObjects.ExtractAnchor ea1 = new ESignLiveAPIObjects.ExtractAnchor(); ea1.text = 'testDocumentOne'; ea1.index = 0; ea1.width = 150; ea1.height = 40; ea1.anchorPoint = ESignLiveAPIObjects.AnchorPoint.BOTTOMRIGHT; ea1.characterIndex = 12; ea1.leftOffset = -40; ea1.topOffset = 0; ESignLiveAPIObjects.Field f2 = new ESignLiveAPIObjects.Field(); f2.type = 'INPUT'; f2.page = 0; f2.extract = false; f2.left = 0; f2.subtype = 'LABEL'; f2.binding = '{approval.signed}'; f2.top = 0; f2.extractAnchor = ea1; // Create request List challenges = new List(); ESignLiveAPIObjects.Delivery delivery = new ESignLiveAPIObjects.Delivery(); delivery.email = true; delivery.provider = true; ESignLiveAPIObjects.Auth auth = new ESignLiveAPIObjects.Auth(); auth.challenges = challenges; auth.scheme = ESignLiveAPIObjects.AuthScheme.NONE; ESignLiveAPIObjects.Signer signer = new ESignLiveAPIObjects.Signer(); signer.auth = auth; signer.delivery = delivery; signer.firstName = 'firstName'; signer.lastName = 'lastName'; signer.email = '[email protected]'; signer.name = 'firstNamelastName'; List signers = new List(); signers.add(signer); ESignLiveAPIObjects.Role role = new ESignLiveAPIObjects.Role(); role.signers = signers; role.reassign = true; role.name = 'firstNamelastName'; role.id = 'firstNamelastName'; role.type = 'SIGNER'; ESignLiveAPIObjects.Approval approval1 = new ESignLiveAPIObjects.Approval(); approval1.role = 'firstNamelastName'; approval1.fields = new List {f1,f2}; ESignLiveAPIObjects.Document doc1 = new ESignLiveAPIObjects.Document(); doc1.name = 'testDocumentOne'; doc1.approvals = new List {approval1}; ESignLiveAPIObjects.Document doc2 = new ESignLiveAPIObjects.Document(); doc2.name = 'testDocumentTwo'; pkg.documents = new List {doc1,doc2}; pkg.roles = new List {role}; // Call the SDK method and get the packageId which is returned from the SDK method String response = sdk.createPackage(pkg,blobMap); // Print the packageId to console System.debug('=> Response from createPackageWithDocumentsExample: ' + response); if (response != null && response != '') { signDocuments(response); } } private static void signDocuments(String response) { HttpRequest request = new HttpRequest(); request.setEndpoint('https://sandbox.esignlive.com/api/packages/' + response + '/documents/signed_documents'); request.setBody('{"documents": [{"id": "testDocumentOneid","name": "testDocumentOne"}]}'); request.setMethod('POST'); request.setHeader('Authorization', 'Basic ' + 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=='); request.setHeader('Content-type', 'application/json'); request.setHeader('Accept', 'application/json'); HttpResponse res = (new Http()).send(request); system.debug('3=== ' + res.getbody()); } }

Reply to: Getting Authorization Error

0 votes
Yes. I have added API Key and URL in the Custom settings. Name : Main Endpoint : https://sandbox.e-signlive.com/api API Key :- I have taken from my EsignLive Sandbox. My Account -> Admin->Integration->API Key. I have taken API key from and added in salesforce. But in Esiglive Sandbox Callback URL is not given. It is empty.

Reply to: Getting Authorization Error

0 votes
The endpoint should be "https://sandbox.esignlive.com/api" (without the hyphen). Let me know if that works.
Haris Haidary OneSpan Technical Consultant

Reply to: Getting Authorization Error

0 votes
Hello, Thank you. You help is much appreciated. I am facing same issue while calling Signed Document function in createDocumentsExample after calling createPackage function it is returning package id. Based on the response i am calling below fucntion private static void signDocuments(String response) { HttpRequest request = new HttpRequest(); request.setEndpoint('https://sandbox.esignlive.com/api/packages/' + response + '/documents/signed_documents'); request.setBody('{"documents": [{"id": "testDocumentOneid","name": "testDocumentOne"}]}'); request.setMethod('POST'); request.setHeader('Authorization', 'Basic ' + 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=='); request.setHeader('Content-type', 'application/json'); request.setHeader('Accept', 'application/json'); HttpResponse res = (new Http()).send(request); system.debug('3=== ' + res.getbody()); } But after send request i am getting below error: 17:21:09:637 USER_DEBUG [290]|DEBUG|3=== {"messageKey":"error.unauthorised.noSession","code":401,"message":"Failed to retrieve Session","name":"Unauthorized"}

Reply to: Getting Authorization Error

0 votes
You are trying to sign for the sender is that correct? The code above worked fine for me.
Haris Haidary OneSpan Technical Consultant

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off