NAV Navbar
shell python javascript

Introduction

Welcome to the contract.fit API! You can use our API to access document activation endpoints.

We have language bindings in Shell, Python and JavaScript.

You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.

Authentication

Make sure to fill in the right values for domain, username and password

#Please make sure  you assign the right value to the three variables below
DOMAIN="your_domain"
USERNAME="your_username"
PASSWORD="your_password"

response=`curl -s -X POST \
  https://${DOMAIN}.contract-t.fit/api/auth \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{"username":"'${USERNAME}'","password":"'${PASSWORD}'"}'`

token=`echo $response|jq -r '.authentication_token'`
#You will need to input the below three variables to get started
domain = "domain"
username = "username"
password = "password"

import requests

url = "https://"+domain+".contract-t.fit/api/auth"

payload = "{\"username\":\""+username+"\",\"password\":\""+password+"\"}"
headers = {
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

print(headers)
print(payload)
response = requests.request("POST", url, data=payload, headers=headers)

token = None

if response.status_code == 200:
    token = response.json()['authentication_token']
else:
    print("Authentication not succeeded, exiting")
    sys.exit(1)

var domain = "domain"
var username = "username"
var password = "password"

var request = require("request");

var options = { method: 'POST',
  url: 'https://'+domain+'.contract-t.fit/api/auth',
  headers:
   { 'cache-control': 'no-cache',
     'content-type': 'application/json' },
  body: { username: username, password: password },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  token = body.authentication_token;
});

The above command returns JSON structured like this:

{
  "authentication_code": "token"
}

contract.fit uses tokens to access the API. You can obtain a key through this API call based on your username and password.

contract.fit expects for the API key to be included in all API requests to the server in a header that looks like the following:

Authorization: Bearer token

This API call will allow you to retrieve such a token.

HTTP Request

POST https://yourdomain.contract-t.fit/auth

Parameters

Parameter Description
username your username
password your password

Inboxes

Inboxes allow us to group documents which belong together, e.g., they need to be reviewed by one specific team.

For this documentation, we assume that you have just one inbox, which has been created when your organization was created.

Should you wish to learn more about inboxes and projects, we refer to the Swagger documentation.

List the available inboxes

response_inbox=`curl -s -X GET \
  https://${DOMAIN}.contract-t.fit/api/inboxes \
  -H 'authorization: Bearer '${TOKEN} \
  -H 'cache-control: no-cache'`

INBOX_ID=`echo $response_inbox|jq -r '.[0]["id"]'`
url = "https://contractfit1.contract-t.fit/api/inboxes"

headers = {
    'authorization': "Bearer "+token,
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

inbox_id = response.json()[0]['id']
var options = { method: 'GET',
  url: 'https://'+domain+'.contract-t.fit/api/inboxes',
  headers:
   { 'cache-control': 'no-cache',
     authorization: 'Bearer '+token },
     json:true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  var inbox_id = body[0]["id"];
});

The above command returns JSON structured like this:

[
  {
    "id": "yourInboxId",
    "name": "yourInboxName",
    "project": "yourProjectId"
  }
]

Here, we will just fetch the id of the first inbox which you have access to. This will then allow you to post a document to that inbox and inspect the results.

HTTP Request

GET https://yourdomain.contract-t.fit/api/inboxes

Documents

Now, we are ready to post a document to the inbox, using the obtained inbox_id.

Post a document

Please make sure to correctly set the path to the file you want to post

PATH_TO_YOUR_FILE="path_to_your_file"

curl -X POST \
  https://${DOMAIN}.contract-t.fit/api/documents/${INBOX_ID} \
  -H 'authorization: Bearer '${TOKEN} \
  -H 'cache-control: no-cache' \
  -F file=@${PATH_TO_YOUR_FILE}
url = "https://" + domain + ".contract-t.fit/api/documents/" + inbox_id
path_to_your_file = "path_to_your_file"

headers = {
    'authorization': "Bearer " + token,
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, files={'file': open(path_to_your_file,'rb')}, headers=headers)

print(response.json())
var path_to_your_file = "path_to_your_file"
var fs = require("fs");

var options = { method: 'POST',
  url: 'https://'+domain+'.contract-t.fit/api/documents/'+inbox_id,
  headers:
   { 'cache-control': 'no-cache',
     authorization: 'Bearer ' + token,
     'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' },
  formData:
   { file:
      { value: fs.createReadStream(path_to_your_file),
        options:
         { filename: path_to_your_file,
           contentType: null } } } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

The above command returns JSON structured like this:

{
  "id": "string",
  "original_filename": "string",
  "inbox": "inbox_id",
  "page_count": 0,
  "prediction": {
    "sections":[
    ]
    "annotations":{
    }
  },
  "feedback": {},
  "evaluation_data": [
    {}
  ],
  "review_flag": true,
  "timings": {
    "receive_time": "2019-04-24T09:43:53.791Z",
    "start_time": "2019-04-24T09:43:53.791Z",
    "done_time": "2019-04-24T09:43:53.791Z",
    "feedback_time": "2019-04-24T09:43:53.791Z",
    "processing_period": 0
  },
  "lock": {
    "value": true,
    "since": "2019-04-24T09:43:53.791Z",
    "by": "Unknown Type: null,string"
  },
  "escalate": {
    "value": true,
    "since": "2019-04-24T09:43:53.791Z",
    "by": "Unknown Type: null,string"
  }
}

This endpoint will return structured data for the document you sent

HTTP Request

POST https://yourdomain.contract-t.fit/documents/<inbox_id>

URL Parameters

Parameter Description
inbox_id The ID of the inbox to which you want to post
file The file that you want to process

Errors

The contract.fit API uses the following error codes:

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key is wrong.
404 Not Found -- The specified resource could not be found.
405 Method Not Allowed -- You tried to access an invalid method.
406 Not Acceptable -- You requested a format that isn't json.
429 Too Many Requests -- The server is experiencing too heavy load, please try again in 1 minute.
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.