Documents

The documents entity is a general entity in contenthub. You can upload documents via the API and set the relationship between the uploaded document and a translationTask after you uploaded it. Possible relationships with a translationTask are:

The following file types are supported by contenthub:

Endpoints

Method URI
GET /rest/api/documents/
POST /rest/api/documents/
GET /rest/api/documents/{doc_id}
DELETE /rest/api/documents/{doc_id}
GET /rest/api/documents/{doc_id}/content

Default Schema

{
  "length": 86,
  "chunkSize": 261120,
  "uploadDate": "2018-12-04T08:55:32.753Z",
  "md5": "64de40f4d727dba30f422116d4b2aefa",
  "filename": "sourceText_ZdnfA9qbSWpwXaFNK.merged.txt",
  "contentType": "application/octet-stream;charset=UTF-8",
  "metadata": {
    "type": "target",
    "translationTaskId": "Kv6PBnpZhJNK6LF6B",
    "sourceDocumentId": "5c063ebdd3edb60007f60a07",
    "translatedXliffDocumentId": "5c0641023e3673000752197c",
    "targetLanguage": "en-US"
  },
  "id": "5c0641049f97a000088e883a"
}

Properties

Property Writeable Value
length readonly The length of the document in bytes.
chunkSize readonly The size of the document in chunks.
uploadDate readonly The date when the document has been created. The date time will be exposed as ISO 8601 date format.
md5 readonly The md5 hash.
filename readonly The original filename of the uploaded file.
contentType readonly The content type of the file.
metadata readonly The metadata of the document contains different information depending on the target type
type
The types of the document: source, target, transformed, translated
userId
The id of the user.
jobId
The id of the job.
translationTaskId
The id of the translationTask.
sourceDocumentId
The id of the sourceDocument.
translatedXliffDocumentId
The id of the tran.salated XLIFF document.
documentTransformationId
The id of the document transformation
targetLanguage
The target language.
tmUpdate
The state of the TM update: RUNNING, ERROR
chubOrigin
The id of the document in the
id readonly The id of the created document.

Description of Endpoints

GET  /rest/api/documents/

Returns all documents of the users organization.

Example Request:

GET /rest/api/documents/ HTTP/1.1

Example Response:

[
  {
    "id": "577bc8dc0f62bbbf1817d428",
    "createdAt": "2016-05-27T07:41:26.640+0000",
    "filename": "Lorem ipsum dolor sit amet.docx",
    "contentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    "length": 15672
  }
  {
    "id": "57725c230f62d3f60648f98a",
    "createdAt": "2016-05-27T08:17:34.553+0000",
    "filename": "document.xml",
    "contentType": "application/xml",
    "length": 20578
  }
]

POST  /rest/api/documents/

Uploads a document into contenthub. After you uploaded a document you can use it as a sourceDocument or additionalDocument by setting a relationship to a translationTask. Please check the documentation at translationTask > sourceDocuments.

There are different possibilities to upload a document into contenthub:

  1. POST a JSON where you provide the filename and the contentUri where the file is located. contenthub would try to download the file from this location and save it as a document. Please be sure that contenthub has access to the location of the referenced file.
  2. POST a multipart/form-data.
  3. POST the content of the file in the body of the request as a stream.

Please note: You need to set the correct ContentType for each upload type:

  1. JSON with contentUri: ContentType: application/json
  2. As multipart: ContentType: multipart/form-data
  3. Stream: ContentType: application/octet-stream

Example Upload via content URI:

POST /rest/api/documents/ HTTP/1.1

{
  "filename": "Lorem_ipsum.docx",
  "contentUri": "http://example.com/files/574d3526f342e39b88e5d414"
}

Example Upload as Stream: The document content should be posted in the body of the request.

POST /rest/api/documents/?filename=Lorem_ipsum.xml HTTP/1.1

Accept: application/json, text/javascript
ContentType: application/octet-stream

Example Upload as multipart:

POST /rest/api/documents/ HTTP/1.1

Accept: application/json, text/javascript
ContentType: multipart/form-data

Example Response:

{
  "id": "27012250873896340681052919844",
  "createdAt" : "2016-05-31T17:31:46.378+0000",
  "filename" : "Lorem ipsum dolor sit amet-mit inhaltssteuerelementen.docx",
  "contentType" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  "length" : 22676
}

GET  /rest/api/documents/{doc_id}

Gets a document by it's id.

Example Request:

GET /rest/api/documents/57725c230f62d3f60648f98a HTTP/1.1

Example Response:

{
  "_id" : "57725c230f62d3f60648f98a",
  "length" : 13,
  "chunkSize" : 261120,
  "uploadDate" : "2017-01-31T14:48:27.532Z",
  "md5" : "1141f6857d065070576d8e1b93232dca",
  "filename" : "ziptext2.txt"
}

DELETE  /rest/api/documents/{doc_id}

Deletes a document by it's id.

Example Request:

DELETE /rest/api/documents/57725c230f62d3f60648f98a HTTP/1.1

Example Response:

HTTP/1.1 200 DELETE

GET  /rest/api/documents/{doc_id}/content

Returns the document as a stream.