Skribble - Sign Documents Digitally

With Intrexx, you can have documents digitally signed. Intrexx offers an integration with Skribble for this purpose.

Skribble

Skribble is a web-based software solution that makes it easy and user-friendly to digitally sign documents. Skribble is developed and operated by Skribble AG and Skribble Deutschland GmbH. Skribble AG and Skribble Deutschland GmbH are technology partners of Intrexx GmbH. You can find them online at the following link: www.skribble.com

To better understand the following sections, it is helpful to familiarize yourself with Skribble's online help. There you'll find all the relevant information about setting up Skribble, legal requirements, processes, and much more.

You can find the Skribble online help at the following link: Skribble Online Help

Process Flow

Below is a simplified overview of the signing process.

  1. Documents are uploaded to an Intrexx application.

  2. The documents are assigned to one or more people who are to sign them.

  3. An email address is stored in Intrexx for these individuals.

  4. When an event occurs—such as clicking a "Send" button—the document is sent to Skribble via the API.

  5. At the same time, the person who is supposed to sign the document receives an email asking them to sign it. The person signing does not need to have their own Skribble account.

  6. The email contains a link that you can use to launch the Skribble web app and digitally sign the document.

  7. The signed document is transmitted to Intrexx via API.

Target Audience

The following sections are intended for experienced Intrexx application developers who are familiar with Groovy scripting.

Key Steps

Steps in Scrabble

Signing Up for Skribble

Sign up for Skribble.

You can find detailed information on this in the Skribble online help here: Create a Skribble Account

Create an API Key

In Skribble, create an API key in the admin area.

You can find detailed information on this in the Skribble online help here: Manage API keys

Steps in Intrexx

Create an Application

Create an application that includes the required fields so that Skribble can process a request from Intrexx correctly.

  • Email address of the signatory

    If the person signing has a Skribble account, the email address is sufficient.

    If the person signing does not have a Skribble account, the following fields are required in addition to the email address:

    • First Name

    • Last Name

    • Cell phone number

  • Title

  • Message text

  • Signature Quality

    For a qualified signature, an option to choose between the EU and Switzerland must be implemented.

  • Signing Status

  • Field for the PDF file to be signed (type "File")

  • Field for the request ID sent by Skribble

  • (Optional) Order

  • (Optional) Observer

Store API Data

Store the Skribble API data in Intrexx. The Groovy script (see below) uses a system data group for this purpose. This approach allows you to maintain the API data within the application in the portal.

However, you can also store the API data in the login information store.

Create a process using a Groovy script

Create a process that allows you to initiate and execute digital signing actions using Skribble. To this end, we are providing you with a Groovy script that contains all the key features needed to integrate with Skribble. You can customize this to suit your own needs.

Groovy script

Below is a Groovy script that you can use to connect to Skribble.

Below, you will find detailed explanations of the individual sections of the script.

Copy
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

import org.apache.http.client.methods.HttpPost
import org.apache.http.client.methods.HttpGet
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClients
import org.apache.http.util.EntityUtils
import org.apache.http.client.utils.URIBuilder

import de.uplanet.scripting.groovy.util.Safely

def sbDebug = new StringBuilder()
CloseableHttpClient httpclient = HttpClients.createDefault()

def conn = g_dbConnections.systemConnection
def stmt = null
def rs   = null


def signatures = []
def STRID = g_record["123456789CC5688C6514D46F166742F123456789"].value

// Data for API connection from XDATAGROUP8AEAEE02 (Skribble Config - AppProps)
def API_USERNAME = g_sysDg['123456789IXA39D44A251254E6ECIX123456789']
def API_KEY = g_sysDg['123456789IXB3E183390BD8EB0FIX123456789']
def API_HOST = g_sysDg['123456789IX5A7F21B81C261CF0IX123456789']

//Data sent with the document
def strTitle = g_record["123456789CDF6724B4007565824D486123456789"].value
def txtMessage = g_record["123456789IX12489B84569D9A20ACIX123456789"].value

try
{
    stmt = g_dbQuery.prepare(conn, """
        SELECT STR_EMAIL, L_SEQUENCE, STR_FIRSTNAME, STR_NAME, STR_MOBILENUMBER
        FROM DATAGROUP('123456789IX2CEE38FE85FBCB7168IX123456789')
        WHERE FKSTRID=? AND (B_OBSERVER=? OR B_OBSERVER IS NULL)
        ORDER BY L_SEQUENCE
    """)

    stmt.setString(1, STRID)
    stmt.setBoolean(2, false)

    rs = stmt.executeQuery()
    //Get signer data from IX_CRM_OFFER_EMAILSIGNING
    while (rs.next()) {
        def strEmail = rs.getStringValue(1)
        def iSequence = rs.getIntValue(2)
        def strFirstname = rs.getStringValue(3)
        def strName = rs.getStringValue(4)
        def strMobileNumber = rs.getStringValue(5)

        if (strEmail) {
            signatures << [
                "account_email": strEmail,
                "sequence"     : iSequence,
                "signer_identity_data": [
                    "email_address": strEmail,
                    "first_name"  : strFirstname,
                    "last_name"   : strName,
                    "mobile_number": strMobileNumber
                ]
            ]
        }
    }
}
finally
{
    rs   = Safely.close(rs)
    stmt = Safely.close(stmt)
}

//Get Observer from IX_CRM_OFFER_EMAILSIGNING
def observer = []
try
{
    stmt = g_dbQuery.prepare(conn, """
        SELECT STR_EMAIL
        FROM DATAGROUP('123456789IX2CEE38FE85FBCB7168IX123456789')
        WHERE FKSTRID=? AND B_OBSERVER=?
    """)

    stmt.setString(1, STRID)
    stmt.setBoolean(2, true)

    rs = stmt.executeQuery()

    while (rs.next()) {
        def strEmail = rs.getStringValue(1)

        if (strEmail) {
            observer << strEmail
        }
    }
}
finally
{
    rs   = Safely.close(rs)
    stmt = Safely.close(stmt)
}

//Convert document for signing
def fileField = g_record["123456789IX79C290AAB61A668EFBIX123456789"]
if (!fileField || !fileField.value) {
    throw new RuntimeException("Keine Datei vorhanden!")
}
def fileDescriptor = fileField.value[0]

def file = fileDescriptor.getFile()

def inputStream = file.newInputStream()
byte[] pdfBytes = inputStream.bytes
inputStream.close()

String base64Pdf = Base64.encoder.encodeToString(pdfBytes)

// ==============================
// AUTHENTICATION
// ==============================
def authUri = new URIBuilder()
    .setScheme("https")
    .setHost(API_HOST)
    .setPath("/v2/access/login")
    .build()

HttpPost authPost = new HttpPost(authUri)
authPost.setHeader("Content-Type", "application/json")

def authPayload = [
    username: API_USERNAME,
    "api-key": API_KEY
]

authPost.setEntity(new StringEntity(JsonOutput.toJson(authPayload), "UTF-8"))

def authResponse = httpclient.execute(authPost)
def status = authResponse.getStatusLine().getStatusCode()
def body = EntityUtils.toString(authResponse.getEntity())

if (status != 200) {
    throw new RuntimeException("Login fehlgeschlagen: ${status} - ${body}")
}

def accessToken = body?.trim()
if (!accessToken) {
    throw new RuntimeException("Kein Access Token erhalten")
}
// ==============================
// SIGNATURE REQUEST
// ==============================

def strSignaturQuality = g_record["123456789989F8FA362B65F89F251CD123456789"].value
def strLegislation     = g_record["1234567890F9IXB57F1FCFAC153B7IX123456789"].value

def signPayload = [
    "title"      : strTitle,
    "message"    : txtMessage,
    "content"    : base64Pdf,
    "signatures" : signatures
]

if (strSignaturQuality && strSignaturQuality != "DEMO") {

    signPayload["quality"] = strSignaturQuality

    if (strLegislation) {
        signPayload["legislation"] = strLegislation
    }
}

if (observer && !observer.isEmpty()) {
    signPayload["cc_email_addresses"] = observer
}
// ==============
// REQUEST
// ==============
def signUri = new URIBuilder()
       .setScheme("https")
       .setHost(API_HOST)
       .setPath("/v2/signature-requests")
       .build()

HttpPost signPost = new HttpPost(signUri)
signPost.setHeader("Content-Type", "application/json")
signPost.setHeader("Authorization", "Bearer ${accessToken}")

signPost.setEntity(new StringEntity(JsonOutput.toJson(signPayload), "UTF-8"))

def signResponse = httpclient.execute(signPost)

def statusCode = signResponse.getStatusLine().getStatusCode()
def signBody   = EntityUtils.toString(signResponse.getEntity())

if (statusCode != 200 && statusCode != 201) {
    throw new Exception("Signature Request fehlgeschlagen! Status: ${statusCode}\n${signBody}")
}

def signJson  = new JsonSlurper().parseText(signBody)
strRequestID = signJson.id

if (!strRequestID) {
    throw new Exception("Keine Request-ID erhalten!")
}
g_sharedState.put("requestId", strRequestID)

// ==============================
// STATUS CHECK
// ==============================
def statusUri = new URIBuilder()
        .setScheme("https")
        .setHost(API_HOST)
        .setPath("/v2/signature-requests/${strRequestID}")
        .build()

def statusGet = new HttpGet(statusUri)
statusGet.setHeader("Authorization", "Bearer ${accessToken}")

def statusResponse = httpclient.execute(statusGet)
def statusBody = EntityUtils.toString(statusResponse.getEntity())
def json = new JsonSlurper().parseText(statusBody)

def strOverallStatus = json.status_overall

stmt = g_dbQuery.prepare(conn, """
           UPDATE DATAGROUP('123456789IX8CC4092E4740444B6E1X123456789')
           SET STR_DOKUMENTENSTATUS=?
           WHERE STRID=?
       """)
       stmt.setString(1, strOverallStatus)
       stmt.setString(2, STRID)
       stmt.executeUpdate()
       stmt = Safely.close(stmt)

// ===========================================================
// Update the status of the signaturesin the child data group
// ===========================================================
json.signatures?.each { sig ->
    def strEmail = sig?.signer_identity_data?.email_address
    def strSigStatus = sig.status_code

     stmt = g_dbQuery.prepare(conn, """
           UPDATE DATAGROUP('1234567899IX2CEE38FE85FBCB716IX123456789')
           SET STR_SIGNIERSTATUS=?
           WHERE FKSTRID=? AND STR_EMAIL=?
       """)
       stmt.setString(1, strSigStatus)
       stmt.setString(2, STRID)
       stmt.setString(3, strEmail)
       stmt.executeUpdate()
       stmt = Safely.close(stmt)

}

1. Benötigte Imports für folgenden Aktionen und abfragen

In this step, the system prompts you to enter the required imports for the following actions.

Copy
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

import org.apache.http.client.methods.HttpPost
import org.apache.http.client.methods.HttpGet
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClients
import org.apache.http.util.EntityUtils
import org.apache.http.client.utils.URIBuilder

import de.uplanet.scripting.groovy.util.Safely

import java.io.File
import java.io.FileOutputStream

2. Save API data in Intrexx (for example, in the system data group)

For detailed information about the API data, see the Skribble online help: Manage API keys

After you've generated the API key, you can view it once or copy it.

API HOST: api.skribble.de

API USERNAME: "from Skribble account"

API KEY: "from Skribble account"

3. Load and Prepare a PDF from Intrexx

In this step, the PDF file stored in the data field is read. The file is loaded as a byte array and then converted to a Base64 string.

This encoding is necessary because the PDF file will later be sent to the Skribble API in this format.

Copy
//PDF aus Datenfeld der App
def fileField = g_record["dataFieldGuid"]

if (!fileField || !fileField.value) {
    throw new RuntimeException("Keine Datei vorhanden!")
}
def fileDescriptor = fileField.value[0]

def file = fileDescriptor.getFile()

def inputStream = file.newInputStream()
byte[] pdfBytes = inputStream.bytes
inputStream.close()

String base64Pdf = Base64.encoder.encodeToString(pdfBytes)

4. Retrieve stored titles, messages, signature quality, and, if applicable, relevant legislation

In this step, all relevant information required for the signature request is loaded from the data set. This includes the title, the message to the signatories, the signature quality, and—if necessary—the applicable legislation. These values will later be included in the request to the Skribble API.

Saved Titles

Copy
def strTitle = g_record["dataFieldGuid"].value

Saved Message

Copy
def txtMessage = g_record["dataFieldGuid"].value

Saved Signature: Quality and Legislation

Copy
def strSignaturQuality = g_record["dataFieldGuid"].value   //QES, AES, AES_MINIMAL, SES oder DEMO
def strLegislation     = g_record["dataFieldGuid"].value  // ZERTE oder EIDAS

5. Identify the signers by order and the viewers

In this step, all individuals involved are loaded from a child data group.

A distinction is made between signers (with the order of signatures) and viewers (for informational purposes only).

  • Signatures, including their order (sequence), are added to a list (signatures).

  • The signer's email address is passed to the API via `account_email `. If a Skribble account already exists for this address, that account will be used for the signature process.

  • If no Skribble account exists, the API uses the information in ` signer_identity_data ` to create external signers who do not have their own Skribble account. For external signatures, at least the first name, last name, email address, and cell phone number must be provided.

  • Observers are stored separately as an email list (observer).

  • The distinction is made using a Boolean field (B_OBSERVER).

This data will later be sent to the Skribble API.

Copy
try
{
    stmt = g_dbQuery.prepare(conn, """
        SELECT STR_EMAIL, L_SEQUENCE, STR_FIRSTNAME, STR_NAME, STR_MOBILENUMMER
        FROM DATAGROUP('dataGroupGuid')
        WHERE FKSTRID=? AND (B_OBSERVER=? OR B_OBSERVER IS NULL)
        ORDER BY L_SEQUENCE
    """)

    stmt.setString(1, STRID)
    stmt.setBoolean(2, false)

    rs = stmt.executeQuery()

    while (rs.next()) {
        def strEmail = rs.getStringValue(1)
        def iSequence = rs.getIntValue(2)
        def strFirstname = rs.getStringValue(3)
        def strName = rs.getStringValue(4)
        def strMobileNumber = rs.getStringValue(5)

        if (strEmail) {
            signatures << [
                "account_email": strEmail,
                "sequence"     : iSequence,
                "signer_identity_data": [
                    "email_address": strEmail,
                     "first_name"  : strFirstname,
                     "last_name"   : strName,
                     "mobile_number": strMobileNumber
            ]
          ]
        }
    }
}
finally
{
    rs   = Safely.close(rs)
    stmt = Safely.close(stmt)
}

def observer = []
try
{
    stmt = g_dbQuery.prepare(conn, """
        SELECT STR_EMAIL
        FROM DATAGROUP('dataGroupGuid')
        WHERE FKSTRID=? AND B_OBSERVER=?
    """)

    stmt.setString(1, STRID)
    stmt.setBoolean(2, true)

    rs = stmt.executeQuery()

    while (rs.next()) {
        def strEmail = rs.getStringValue(1)

        if (strEmail) {
            observer << strEmail
        }
    }
}
finally
{
    rs   = Safely.close(rs)
    stmt = Safely.close(stmt)
}

6. Authentication on Skribble

In this step, a connection to the Skribble API is established. To do this, a login request is sent with a username and API key.

The API verifies the credentials and returns an access token if the verification is successful. This token is then stored and used in the header for all subsequent API calls (e.g., signature request, status query, PDF download).

If the login fails or no token is returned, the script will terminate with an error.

Copy
def authUri = new URIBuilder()
    .setScheme("https")
    .setHost(API_HOST)
    .setPath("/v2/access/login")
    .build()

HttpPost authPost = new HttpPost(authUri)
authPost.setHeader("Content-Type", "application/json")

def authPayload = [
    username: API_USERNAME,
    "api-key": API_KEY
]

authPost.setEntity(new StringEntity(JsonOutput.toJson(authPayload), "UTF-8"))

def authResponse = httpclient.execute(authPost)
def status = authResponse.getStatusLine().getStatusCode()
def body = EntityUtils.toString(authResponse.getEntity())

if (status != 200) {
    throw new RuntimeException("Login fehlgeschlagen: ${status} - ${body}")
}

def accessToken = body?.trim()
if (!accessToken) {
    throw new RuntimeException("Kein Access Token erhalten")
}

7. Compile the signature package

In this step, the complete signature package is compiled. First, the basic data—such as the title, message, PDF (as Base64), and signatories—are compiled. Depending on your selection, additional options will then be added:

  • If a signature quality is specified , it is included. A qualified electronic signature (QES) also includes the legal basis.

  • Optionally, observers ( CC recipients) can also be added who can follow the signing process.

Copy
def signPayload = [
    "title"      : strTitle,
    "message"    : txtMessage,
    "content"    : base64Pdf,
    "signatures" : signatures
]

if (strSignaturQuality && strSignaturQuality != "DEMO") {

    signPayload["quality"] = strSignaturQuality

    if (strSignaturQuality== “QES”) {
        signPayload["legislation"] = strLegislation
    }
}

if (observer && !observer.isEmpty()) {
    signPayload["cc_email_addresses"] = observer
}

8. Send the signature request & save the request ID

In this step, the signature request is sent to the Skribble API, and if the signature is successfully generated, the API returns a request ID.

This ID is crucial because it will be needed later to:

  • to check the status of the signature

  • to download the final signed PDF file

The request ID is first stored in g_sharedState. It should then be permanently saved in a data field via a data event.

Copy
def signUri = new URIBuilder()
        .setScheme("https")
        .setHost(API_HOST)
        .setPath("/v2/signature-requests")
        .build()

HttpPost signPost = new HttpPost(signUri)
signPost.setHeader("Content-Type", "application/json")
signPost.setHeader("Authorization", "Bearer ${accessToken}")

signPost.setEntity(new StringEntity(JsonOutput.toJson(signPayload), "UTF-8"))

def signResponse = httpclient.execute(signPost)

def statusCode = signResponse.getStatusLine().getStatusCode()
def signBody   = EntityUtils.toString(signResponse.getEntity())

if (statusCode != 200 && statusCode != 201) {
    throw new Exception("Signature Request fehlgeschlagen! Status: ${statusCode}\n${signBody}")
}

def signJson  = new JsonSlurper().parseText(signBody)
def strRequestID = signJson.id

if (!strRequestID) {
    throw new Exception("Keine Request-ID erhalten!")
}

//Request-ID im g_sharedState gespeichert & muss anschließend über ein Datenereignis dauerhaft in einem Datenfeld gesichert werden.

g_sharedState.put("requestId", strRequestID)

9. Check the signature status & save it

In this step, the current status of the signature request is queried from the Skribble API using the stored request ID.

  • The overall status ( status_overall) is stored in the main dataset.

  • In addition, the status of each individual signature (per person) is updated in the child data group.

This ensures that the status of the signature can be tracked in the system at any time.

Copy
def statusUri = new URIBuilder()
        .setScheme("https")
        .setHost(API_HOST)
        .setPath("/v2/signature-requests/${strRequestID}")
        .build()

def statusGet = new HttpGet(statusUri)
statusGet.setHeader("Authorization", "Bearer ${accessToken}")

def statusresponse = httpclient.execute(statusGet)
def statusBody = EntityUtils.toString(statusresponse.getEntity())
def json = new JsonSlurper().parseText(statusBody)

def strOverallStatus = json.status_overall

stmt = g_dbQuery.prepare(conn, """
           UPDATE DATAGROUP('dataGroupGuid')
           SET STR_DOKUMENTENSTATUS=?
           WHERE STRID=?
       """)
       stmt.setString(1, strOverallStatus)
       stmt.setString(2, STRID)
       stmt.executeUpdate()
       stmt = Safely.close(stmt)


// Status der Signaturen der einzelnen Personen in Kinddatengruppe aktualisieren

json.signatures?.each { sig ->
    def strEmail = sig.sig?.signer_identity_data?.email_address
    def strSigStatus = sig.status_code

     stmt = g_dbQuery.prepare(conn, """
           UPDATE DATAGROUP('dataGroupGuid')
           SET STR_SIGNIERSTATUS=?
           WHERE FKSTRID=? AND STR_EMAIL=?
       """)
       stmt.setString(1, strSigStatus)
       stmt.setString(2, STRID)
       stmt.setString(3, strEmail)
       stmt.executeUpdate()
       stmt = Safely.close(stmt)

}

10. Download and save the signed PDF file

As soon as the status reaches "SIGNED, " the completed, signed PDF file is downloaded via the Skribble API.

The file is stored temporarily and then copied directly into an Intrexx file field in the record. After that, the temporary file is deleted.

This way, the signed version is immediately available in the system.

Copy
if (json.status_overall == "SIGNED") {

    def documentId = json.document_id

    def pdfUri = new URIBuilder()
            .setScheme("https")
            .setHost(API_HOST)
            .setPath("/v2/documents/${documentId}/content")
            .build()

    def pdfGet = new HttpGet(pdfUri)
    pdfGet.setHeader("Authorization", "Bearer ${accessToken}")

    def pdfResponse = httpclient.execute(pdfGet)

    if (pdfResponse.getStatusLine().getStatusCode() != 200) {
        throw new RuntimeException("PDF Download fehlgeschlagen")
    }

    File dirTemp = createTemporaryDirectory()

    try {

        File tmpFile = new File(dirTemp, "Signed_${documentId}.pdf")

        FileOutputStream out = new FileOutputStream(tmpFile)
        BufferedOutputStream bos = new BufferedOutputStream(out)

        pdfResponse.getEntity().writeTo(bos)

        bos.close()
        out.close()

        g_dgFile.copy(
            guid: "dataFieldGuid",
            id:   STRID,
            file: tmpFile,
            mode: "appendFirst"
        )
    }
    finally {
        dirTemp.deleteDir()
        pdfResponse.close()
    }
}