/
REST Examples

REST Examples

The JoinVision backend supports several GET and POST REST calls, see the REST API documentation for more detail. The following examples show exemplary implementations for the Get Domains method using GET and Extract method using POST.

The GET example returns the latest domain value lists with English values in a JSON format. See the Rest API Reference for information on different parameters.

The POST example returns a structured XML containing all extracted information for a provided input file named “document.pdf”. Based on the selected Extraction Model, the returned XML validates against the respective XML Schema for the applied extraction mode.

Throughout the examples a placeholder is used instead of a valid product token. Replace <Product-Token> with your own token. Some of the examples use external libraries. Implementation steps may vary depending on the chosen library, please refer to the respective documentation.

Node.js / Javascript

Get Domains

var https = require('https'); var options = { host: 'cvlizer.joinvision.com', port: '443', path: '/cvlizer/rest/v1/domains/json/en', method: 'GET', headers: { Authorization: 'Bearer ' + <Product-Token> } }; var request = http.request(options, function (res) { if(res.statusCode !== 200){ console.log(res.statusCode); console.log(res.headers); } var str = ""; res.on("data", function(chunk) { str += chunk; }); res.on("end", function() { console.log(str); }); }); request.end();

Extract

var https = require('https'); var fs = require('fs'); var filename = "document.pdf"; fs.readFile(filename, function(err, file_data){ if (err) { throw err; } var base64 = new Buffer(file_data).toString('base64'); var data = JSON.stringify({ "model" : "cvlizer_3_0", "language" : "de", "filename":filename, "data":base64 }); var postheaders = { 'Content-Type' : 'application/json', 'Authorization': "Bearer " + <Product-Token> }; var postOptions = { host: "cvlizer.joinvision.com", port: "443", path: "/cvlizer/rest/v1/extract/xml", method: 'POST', headers: postheaders }; var request = https.request(postOptions, function (res) { if(res.statusCode !== 200){ console.log(res.statusCode); console.log(res.headers); } var str = ""; res.on("data", function(chunk) { str += chunk; }); res.on("end", function() { console.log(str); }); }); request.write(data); request.end(); });

Python 3

Get Domains

import requests r = requests.get('https://cvlizer.joinvision.com/cvlizer/rest/v1/domains/json/en', headers={'Authorization': 'Bearer <PRODUCT-TOKEN>'}) print(r.content.decode('utf-8'))

Extract

import requests import json import base64 # Replace xml with json for json result url = 'https://cvlizer.joinvision.com/cvlizer/rest/v1/extract/xml' model = 'cvlizer_3_0' language = 'en' filename = 'document.pdf' # Encode file to base64 fileContent = open(filename, "rb").read() base64Content = base64.b64encode(fileContent).decode('utf-8') payload = { 'model': model, 'data':base64Content, 'language':language, 'filename':filename } headers = { 'Content-Type':'application/json', 'Authorization':'Bearer <PRODUCT-TOKEN>' # Replace with actual product token } r = requests.post(url, data=json.dumps(payload), headers=headers) # if r.status_code... print(r.content.decode('utf-8'))

PHP

Get Domains

<?php $curl = curl_init('https://cvlizer.joinvision.com/cvlizer/rest/v1/domains/json/en'); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer <Product-Token>')); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $curl_response = curl_exec($curl); curl_close($curl); var_dump($curl_response); ?>

Extract

<?php $filename = 'document.pdf'; $base64 = base64_encode(file_get_contents($filename)); $data = array( 'model' => 'cvlizer_3_0', 'language' => 'de', 'filename' => $filename, 'data' => $base64 ); $headers = array('Content-Type:application/json', 'Authorization: Bearer <Product-Token>'); $curl = curl_init('https://cvlizer.joinvision.com/cvlizer/rest/v1/extract/xml'); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $curl_response = curl_exec($curl); curl_close($curl); var_dump($curl_response); ?>

Ruby

The following example uses the “rest-client”-gem in version 1.8.0. It can be installed with this command:

$ gem install rest-client

Get Domains

require 'rest-client' response = RestClient.get('https://cvlizer.joinvision.com/cvlizer/rest/v1/domains/json/en', {'Authorization' => 'Bearer <Product-Token>'}) puts response

Extract

require 'rest-client' require "base64" filename = 'document.pdf' base64 = Base64.encode64(File.read(filename)) response = RestClient.post( 'https://cvlizer.joinvision.com/cvlizer/rest/v1/extract/xml', { 'model'=>'cvlizer_3_0', 'data'=>base64, 'language'=>'de', 'filename'=>filename }.to_json, { 'Authorization' => 'Bearer <Product-Token>', :content_type => :json } ) puts response

Java

The examples use Jersey 2.X. Please note both examples are excerpts which are not runnable without an encapsulating class.

Get Domains

try { com.sun.jersey.api.client.Client client = com.sun.jersey.api.client.Client.create(); com.sun.jersey.api.client.WebResource webResource = client .resource("https://cvlizer.joinvision.com/cvlizer/rest/v1/domains/json/en"); com.sun.jersey.api.client.ClientResponse response = null; response = webResource .type("application/json") .header("Authorization", "Bearer <Product-Token>") .get(com.sun.jersey.api.client.ClientResponse.class); String jsonStr = response.getEntity(String.class); System.out.println(jsonStr); } catch (Exception e) { e.printStackTrace(); }

Extract

Apache Commons components are used for Base64 encoding.

String filename = "document.pdf"; try { File file = new File(filename); FileInputStream fis = new FileInputStream(file); byte[] bytes = new byte[(int) file.length()]; fis.read(bytes); String base64 = new String(org.apache.commons.codec.binary.Base64.encodeBase64(bytes)); org.json.JSONObject obj = new org.json.JSONObject(); obj.put("model", "cvlizer_3_0"); obj.put("data", base64); obj.put("language", "de"); obj.put("filename", filename); com.sun.jersey.api.client.Client client = com.sun.jersey.api.client.Client.create(); com.sun.jersey.api.client.WebResource webResource = client .resource("https://cvlizer.joinvision.com/cvlizer/rest/v1/extract/xml"); com.sun.jersey.api.client.ClientResponse response = null; response = webResource .type("application/json") .header("Authorization", "Bearer <Product-Token>") .post(com.sun.jersey.api.client.ClientResponse.class, obj.toString()); String jsonStr = response.getEntity(String.class); System.out.println(jsonStr); } catch (Exception e) { e.printStackTrace(); }

C#

Get Domains

using System; namespace rest_get { class MainClass { public static void Main (string[] args) { System.Net.HttpWebRequest req = System.Net.WebRequest.Create ("https://cvlizer.joinvision.com/cvlizer/rest/v1/domains/json/en") as System.Net.HttpWebRequest; req.Method = "GET"; req.Headers.Add("Authorization","Bearer " + <Product-Token>); string result = null; using (System.Net.HttpWebResponse resp = req.GetResponse() as System.Net.HttpWebResponse) { System.IO.StreamReader reader = new System.IO.StreamReader(resp.GetResponseStream()); result = reader.ReadToEnd(); } Console.Write(result); } } }

Extract

using System; namespace rest_post { public class JsonData{ public String model { get; set; } public String language { get; set; } public String filename { get; set; } public String data { get; set; } } class MainClass { private const string fileName = "document.pdf"; public static void Main (string[] args) { Byte[] bytes = System.IO.File.ReadAllBytes(fileName); String file = Convert.ToBase64String(bytes); JsonData data = new JsonData(); data.model = "cvlizer_3_0"; data.language = "de"; data.filename = fileName; data.data = file; string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(data); byte[] jsonBytes = System.Text.Encoding.UTF8.GetBytes(json); System.Net.HttpWebRequest req = System.Net.WebRequest.Create ("https://cvlizer.joinvision.com/cvlizer/rest/v1/extract/xml/") as System.Net.HttpWebRequest; req.Method = "POST"; req.ContentType = "application/json"; req.Headers.Add("Authorization","Bearer " + <Product-Token>); req.ContentLength = jsonBytes.Length; using (System.IO.Stream post = req.GetRequestStream()) { post.Write(jsonBytes, 0, jsonBytes.Length); } string result = null; using (System.Net.HttpWebResponse resp = req.GetResponse() as System.Net.HttpWebResponse) { System.IO.StreamReader reader = new System.IO.StreamReader(resp.GetResponseStream()); result = reader.ReadToEnd(); } Console.Write(result); } } }

 

Related content