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:

  • sourceDocument
  • convertedSourceDocument
  • additionalDocument comming soon
  • targetDocument will just be added by a translation vendor

Endpoints:

Default Schema

{
  "length": 12929
  "chunkSize": 261120
  "uploadDate": "2017-07-14T08:20:12.276Z"
  "md5": "329615e927fcff41ececb651f7d9d86e"
  "filename": "Job 11 - fr-CH.xlf"
  "id": "59687ebc21b7620007c198a6"
}
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.
id [readonly]:The id of the created document.
contentType [readonly]:
 The content type of the file.

Endpoints

GET /rest/api/documents/

Returns all documents of the users organization.

Example Request:

GET /rest/api/documents/ HTTP/1.1
Host: example.com
Accept: application/json, text/javascript

Example Response:

HTTP/1.1 200 OK
Vary: Accept
Content-Type: text/javascript

[
  {
    "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
Host: example.com
Accept: application/json, text/javascript
ContentType: application/json

{
 "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
Host: example.com
Accept: application/json, text/javascript
ContentType: application/octet-stream

Example Upload as multipart:

POST /rest/api/documents/ HTTP/1.1
Host: example.com
Accept: application/json, text/javascript
ContentType: multipart/form-data

Example Response:

HTTP/1.1 201 CREATED
Vary: Accept
Content-Type: text/javascript

{
  "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/(id)

Gets a document by it’s id.

Example Request:

GET /rest/api/documents/57725c230f62d3f60648f98a HTTP/1.1
Host: example.com

Example Response:

HTTP/1.1 200 GET
Vary: Accept
Content-Type: text/javascript

{
  "_id" : "57725c230f62d3f60648f98a",
  "length" : 13,
  "chunkSize" : 261120,
  "uploadDate" : "2017-01-31T14:48:27.532Z",
  "md5" : "1141f6857d065070576d8e1b93232dca",
  "filename" : "ziptext2.txt"
}
DELETE /rest/api/documents/(id)

Deletes a document by it’s id.

Example Request:

DELETE /rest/api/documents/57725c230f62d3f60648f98a HTTP/1.1
Host: example.com

Example Response:

HTTP/1.1 200 DELETE
GET /rest/api/documents/(id)/content

Returns the document as a stream.