Monti | Posts: 6

Get the next signer and the progress of the transaction

0 votes

Hello!
I am developing a portal where you can see the latest transactions made in OneSpan, as well as the % of progress of the transactions, see the next person to sign and the possibility of resending the signature email to said person.

Is there any endpoint to the REST API that allows me to obtain the following data?:
- Data of the next person to sign a transaction
- Level of progress of the transaction (the number of signatures made vs the total number of people).

Thank you very much!


Duo_Liang | Posts: 3776

Reply to: Get the next signer and the progress of the transaction

0 votes

Hi Monti,

 

Thanks for your post! I don't think there's a direct API endpoint which contains the information about the next pending signer and the signing progress, but you can definitely calculated these values via the transaction retrieval API (GET /api/packages/{packageId}). Below code snippets are written in Java, which should be able to accommodate your requirement:

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class GetOssTransactionSigningProgress{

    private String API_KEY = "your_api_key";
    private String API_URL = "https://sandbox.esignlive.com";
    private String packageId = "ptba-WpehQqKcQ838fD93TJKHqk=";

    public static void main(String[] args) throws IOException, JSONException {
        new GetOssTransactionSigningProgress().execute();
    }
    
    private class OssRole{
        int signingIndex;
        String firstName;
        String lastName;
        String roleId;
    }
    
    private JSONObject getPackageJSON(String packageId) throws IOException, JSONException {
        URL client = new URL(API_URL + "/api/packages/" + packageId);
        HttpURLConnection conn = (HttpURLConnection) client.openConnection();
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("Authorization", "Basic " + API_KEY);
        conn.setRequestProperty("Accept", "application/json");

        int responseCode = ((HttpURLConnection) conn).getResponseCode();

        if (responseCode == 200) {
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
            conn.disconnect();
            return new JSONObject(response.toString());
        } else {
            return null;
        }
    }
    
    private void execute() throws IOException, JSONException {
        JSONObject packageJSON = getPackageJSON(packageId);
        
        Set<String> pendingSignerIDs = new HashSet<String>();
        int totalSignature= 0;
        int signedSignature = 0;
        JSONArray documentsArray = packageJSON.getJSONArray("documents");
        for (int i = 0; i < documentsArray.length(); i++) {
            JSONObject documentJSON = documentsArray.getJSONObject(i);
            JSONArray approvalsArray = documentJSON.getJSONArray("approvals");

            if(approvalsArray.length() > 0) {
                totalSignature += approvalsArray.length();
                for (int j = 0; j < approvalsArray.length(); j++) {
                    JSONObject approvalJSON = approvalsArray.getJSONObject(j);
                    if(!approvalJSON.isNull("accepted")) {
                        signedSignature++;
                    }else {
                        pendingSignerIDs.add(approvalJSON.getString("role"));
                    }
                }                        
            }        
        }
        
        System.out.println("Current Signing Progress: " + signedSignature + " / "  + totalSignature);
        
        List<OssRole> ossRoles = new ArrayList<OssRole>();
        JSONArray rolesArray = packageJSON.getJSONArray("roles");
        for (int i = 0; i < rolesArray.length(); i++) {
            JSONObject roleJSON = rolesArray.getJSONObject(i);
            
            String roleId = roleJSON.getString("id");
            if(pendingSignerIDs.contains(roleId)) {
                OssRole ossRole = new OssRole();
                ossRole.roleId = roleId;
                ossRole.signingIndex = roleJSON.getInt("index");
                JSONObject signerJSON = roleJSON.getJSONArray("signers").getJSONObject(0);
                ossRole.firstName = signerJSON.getString("firstName");
                ossRole.lastName = signerJSON.getString("lastName");
                ossRoles.add(ossRole);
            }
        }
        
        List<OssRole> ossRolesPending = new ArrayList<OssRole>();
        int currentSigningIndex = -1;
        for (OssRole ossRole : ossRoles) {
            if(currentSigningIndex < 0 || ossRole.signingIndex < currentSigningIndex) {
                currentSigningIndex = ossRole.signingIndex;
            }
        }
        
        for (OssRole ossRole : ossRoles) {
            if(ossRole.signingIndex == currentSigningIndex) {
                ossRolesPending.add(ossRole);
                System.out.println("Pending Signer: " + ossRole.firstName + " " + ossRole.lastName + "; Role ID: " + ossRole.roleId);
            }
        }
    }

}

 

Duo


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