Request a demo Email us to a friend Client login Have questions? We’d love to chat: 1.866.273.6898

Examples → API Example Code


API authentication happens a couple of different ways and at numerous times throughout the process of accessing an account. There is API authentication, user authentication, application authorization and access authentication. Below are some snippets showing different types and methods of doing this authentication

User Authorizes Application

Here is a sample function done in php which constructs a page with a callback url for a user to click on which will allow the user to authenticate themselves, and authorize the application when they have not previously done so:

Please note, this is not production code, and is meant only as an example process
function showIntroPage($next) {
        $next_url  = urlencode($next);
        $redirect_url  = 'https://api.datawitness.net/login.php?app='.DEVELOPER_KEY;
        $redirect_url .= '&next='. $next_url;

        $a  = '<html>'.EOL;
        $a .= '<head>'.EOL;
        $a .= '<script type="text/javascript" src="/default.js"></script>'.EOL;
        $a .= '</head>'.EOL;
        $a .= '<body><center>'.EOL;
        $a .= '<table style="width:50%;">'.EOL;
        $a .= '<tr>'.EOL;
        $a .= '<th colspan="2" style="text-align:center;">'.APPNAME.' API</th>'.EOL;
        $a .= '</tr>'.EOL;
        $a .= '<tr><td>Before you get started, please ';
        $a .= '<a href="javascript:openwin(\''.$redirect_url.'\',\'Login\',425,500);">';
        $a .= 'sign in</a> ';
        $a .= 'to authorize this application.</td></tr>'.EOL;
        $a .= '</table>'.EOL;
        $a .= '</center></body></html>'.EOL;
        return $a;
}

You would then add this to your pages and call the function something like this:

if (empty($_SESSION['authId'])) {
        echo showIntroPage('https://YOURSITE.COM/URL/PAGE');
        exit;
}

It very basically redirects the user to a page with a link to the Datawitness API login page. The user is presented with a form to put in their username and password, and then they are prompted to authorize the application.

A fully constructed URL would look like this:

https://api.datawitness.net/login.php?app=5baa61e4c9b94g4g0683360b6cf8441b7dw68fd8
&next=http://YOURSITE.COM/URL/PAGE

Once the user completes this process, they are redirected to your callback url, which contains 1 argument. GET['authId']

if (isset($_GET['authId'])) {
        ...
        $_SESSION['authId'] = $_GET['authId'];
}

The authId is the password which you associate to the user for all subsequent api calls.


Help the planet by Keeping Digital Files Digital! Datawitness is uniquely situated to help you help our Planet!. Look for this icon The path to green! throughout the site for “Green Tips”


Signup for Datawitness
Related Links

Quick Fact

Executives spend 7.4% of their time looking for lost or misplaced documents.

Get In Touch

Request a demo or just contact us
We'll be glad to discuss our service with you

Latest News

"It worked flawlessly..."   Datawitness is proud to announce the Bulk Upload interface for online archiving. For organizations looking for a faster way to archive and forget about closed files, the Bulk Upload interface will allow you to queue up to 150 files at a time, so you can set it and forget it, while you continue to perform other tasks. You wanted a secured, faster, easier, economical and environmentally friendly way to archive. Here it is!

Full article: Seconds! NOT Minutes! Datawitness makes uploading vital records even faster and easier with new Bulk Uploading feature »