Difference between revisions of "Pangeanic API"

From Pangeanic
Jump to navigation Jump to search
(Created page with "External programs, legacy systems, programmers using console or API clients can access the full solution functionalities using the generic APIs. The updated description of APIs can be found at the following repositories: • https://corporateapi2.docs.apiary.io/# (text processing), • https://pgfile.docs.apiary.io/# (document processing) and • http://prodb.pangeamt.com:8000/docs (anonymization) • Pecat API (no online repo) Pangeanic’s API is a simple RESTFul i...")
 
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
===Pangeanic Translation API===
External programs, legacy systems, programmers using console or API clients can access the full solution functionalities using the generic APIs.
External programs, legacy systems, programmers using console or API clients can access the full solution functionalities using the generic APIs.
The updated description of APIs can be found at the following repositories:
The updated description of APIs can be found at the following repositories:
https://corporateapi2.docs.apiary.io/# (text processing),  
*https://corporateapi2.docs.apiary.io/# (text processing),  
https://pgfile.docs.apiary.io/# (document processing) and
*https://pgfile.docs.apiary.io/# (document processing) and
• http://prodb.pangeamt.com:8000/docs  (anonymization)
• Pecat API (no online repo)




Pangeanic’s API is a simple RESTFul implementation where typically the requests are sent as POSTs with a json encoded body.
Pangeanic’s API is a simple RESTFul implementation where typically the requests are sent as POSTs with a json encoded body.
When handling files the content is sent or received in base-64 encoded form.
When handling files the content is sent or received in base-64 encoded form.
As an example, the API definition for the translation of a single sentence would be:
As an example, the API definition for the translation of a single sentence would be:
POST to endpoint: https://production_access_server_url:8080/NexRelay/v1/translate  
POST to endpoint: https://production_access_server_url:8080/NexRelay/v1/translate  
Headers: Content-Type : application/json
Headers: Content-Type : application/json
Request Body:  
Request Body:  
<code>
{
{
"src":"en",
"src":"en",
"tgt":"es",
"tgt":"es",
"apikey":"your_api_key",
"apikey":"your_api_key",
"engineid":"your_engine_id",
"engine":"your_engine_id",
"text":[
"text":[
   "This is an example."
   "This is an example."
   ]
   ]
}
}
</code>
Answer Body:
Answer Body:
<code>
[
[
     [
     [
Line 30: Line 39:
         }
         }
     ]
     ]
</code>
Both https and http endpoints are configurable in the Access Server.
Both https and http endpoints are configurable in the Access Server.


7.1. Text Processing API
<br/>
===Text Translation API===
<br/>
HOST: http://prod.pangeamt.com:8080/NexRelay/v1/
HOST: http://prod.pangeamt.com:8080/NexRelay/v1/
List Engines [/corp/engines]
 
### List All available engines [POST]
====List Engines [/corp/engines]====
 
List All available engines [POST]
This edpoint is required to list the list of IDs of the available engines fo your APIKey
This edpoint is required to list the list of IDs of the available engines fo your APIKey
+ Request (application/json)
+ Request (application/json)
<code>
         {
         {
             "apikey": "your-apikey-here"
             "apikey": "your-apikey-here"
         }
         }
</code>
+ Response 200 (application/json)
+ Response 200 (application/json)
<code>
         {
         {
             "engines": [
             "engines": [
Line 70: Line 88:
             ]
             ]
         }
         }
 
</code>
      
      
Process text [/translate]
=====Process text [/translate]=====
### Process a text segment [POST]
Process a text segment [POST]
<br/>
A text segment is a number of words, processing works best if the segment is a sentence with whole semantic content.  
A text segment is a number of words, processing works best if the segment is a sentence with whole semantic content.  
- src and tgt are 2-letter language codes
*src and tgt are 2-letter language codes
- engine is the id (string) of the engine to be used
*engine is the id (string) of the engine to be used
- glossary_id, optional, is the id (integer) of the glossary to be used
*glossary_id, optional, is the id (integer) of the glossary to be used


+ Request (application/json)
+ Request (application/json)
<code>
         {
         {
             "src":"es",
             "src":"es",
Line 91: Line 111:
             ]
             ]
         }
         }
</code>
+ Response 200 (application/json)
+ Response 200 (application/json)
 
<code>
         [
         [
             [
             [
Line 107: Line 128:
             ]
             ]
         ]
         ]
</code>
<br/>


7.2. Document Processing API
===Document Processing API===
HOST: http://prod.pangeamt.com:8080/PGFile/v1
HOST: http://prod.pangeamt.com:8080/PGFile/v1


File Uploading [/sendfile]
====File Uploading [/sendfile]====
### Send a File [POST]
Send a File [POST]
 
 
Main request. Send a file to the service for translation.
Main request. Send a file to the service for translation.
The process parameters have to be included
The process parameters have to be included
Line 118: Line 143:


+ Request  
+ Request  
<code>
(multipart/form-data;boundary=----WebKitFormBoundary8M3sSU13ul5lXSJm)
(multipart/form-data;boundary=----WebKitFormBoundary8M3sSU13ul5lXSJm)


Line 143: Line 169:
             data
             data
         ------WebKitFormBoundary8M3sSU13ul5lXSJm--
         ------WebKitFormBoundary8M3sSU13ul5lXSJm--
 
</code>
+ Response 200 (application/json)
+ Response 200 (application/json)
<code>
         {
         {
         "fileId": "8d4e1c5be60d4e04850f55ec135f2554"
         "fileId": "8d4e1c5be60d4e04850f55ec135f2554"
         }
         }
 
</code>
+ Response 500 (application/json)
+ Response 500 (application/json)
<code>
         {
         {
         "error": true,
         "error": true,
         "error_message" : "the-error-message"
         "error_message" : "the-error-message"
         }
         }
</code>
<br/>
====Checking file status [/checkfile?apikey&fileid]====


Checking file status [/checkfile?apikey&fileid]
Use /checkfile to get the processing status of a file, this is a json post where body
Use /checkfile to get the processing status of a file, this is a json post where body
can have three forms:
can have three forms:
- just the apikey, the response will return info about all files being processed for the apikey.
*just the apikey, the response will return info about all files being processed for the apikey.
- guid, to get info about a single file
*guid, to get info about a single file


Use a get request like:
Use a get request like:
https://server_address:server_port/PGFile/v1/checkfile?apikey=your_api_key
https://server_address:server_port/PGFile/v1/checkfile?apikey=your_api_key
https://server_address:server_port/PGFile/v1/checkfile?apikey=your_api_key&guid=d9b95ffb3bc347efa6a7cb90ca80ca74
https://server_address:server_port/PGFile/v1/checkfile?apikey=your_api_key&guid=d9b95ffb3bc347efa6a7cb90ca80ca74
 
<br/>
The returned answer is a json list containing one json object for every file.
The returned answer is a json list containing one json object for every file.
The important field returned for every file is the status, an integer with possible values:
The important field returned for every file is the status, an integer with possible values:
- 10, file is queued for process at the server
*10, file is queued for process at the server
- 6 or 7, file is being analyzed
*6 or 7, file is being analyzed
- 20, 30 or 40, file is being processed
*20, 30 or 40, file is being processed
- 100, file processed successsfully, waiting download
*100, file processed successsfully, waiting download
- 110 or 120, file downloaded
*110 or 120, file downloaded
- -10 or -20 (negative values), processing error
* -10 or -20 (negative values), processing error


### Check the processing status of a file [GET]
Check the processing status of a file [GET]
+ Response 200 (application/json)
+ Response 200 (application/json)
<code>
         [
         [
             {
             {
Line 196: Line 231:
             }
             }
         ]
         ]
</code>


## Checking and downloading file [/retrievefile]
====Checking and downloading file [/retrievefile]====
This is a POST request that can be used to get info about a file that is being processed and
This is a POST request that can be used to get info about a file that is being processed and
download the processed file is process has finished.
download the processed file is process has finished.
<br/>
**WARNING** this endpoint is NOT safe for very big files: the file is returned in base64
**WARNING** this endpoint is NOT safe for very big files: the file is returned in base64
encoding and requires a lot of memory at server and client side.
encoding and requires a lot of memory at server and client side.
Line 206: Line 243:
If file is in processs a 200 response is returned with the status data.
If file is in processs a 200 response is returned with the status data.
Errors will generate a 401 response.
Errors will generate a 401 response.
### Check and get File [POST]
 
====Check and get File [POST]====
+ Request (application/json)
+ Request (application/json)
<code>
         {
         {
             "apikey": "your-api-key-here",
             "apikey": "your-api-key-here",
             "guid": "1dc77dc5ba6d44828b860537dae07187"
             "guid": "1dc77dc5ba6d44828b860537dae07187"
         }
         }
 
<code>
+ Response 200 (application/json)
+ Response 200 (application/json)
<code>
         # response when file is not finished
         # response when file is not finished
         {
         {
Line 233: Line 273:
                 "file": "U2VlIHRoaW5ncyB0byBkbywgcmVzdGF1cmFudHMsIGFuZCBob3RlbHMNCg=="
                 "file": "U2VlIHRoaW5ncyB0byBkbywgcmVzdGF1cmFudHMsIGFuZCBob3RlbHMNCg=="
             }
             }
         }  
         }
</code>
   
+ Response 401 (application/json)
+ Response 401 (application/json)
<code>
         {
         {
             "success": False,  
             "success": False,  
Line 244: Line 287:
             "data": {}
             "data": {}
         }
         }
</code>


Downloading file [/download?apikey&fileid]
====Downloading file [/download?apikey&fileid]====
Simple get request to retrieve a file. The get parameters are:
Simple get request to retrieve a file. The get parameters are:
- apikey
*apikey
- fileid, the file GUID
*fileid, the file GUID
The file is returned as a stream (similar to a call to wget)
The file is returned as a stream (similar to a call to wget)
### Send a File [GET]
+ Response 200

Latest revision as of 09:11, 17 October 2022

Pangeanic Translation API

External programs, legacy systems, programmers using console or API clients can access the full solution functionalities using the generic APIs.


The updated description of APIs can be found at the following repositories:


Pangeanic’s API is a simple RESTFul implementation where typically the requests are sent as POSTs with a json encoded body. When handling files the content is sent or received in base-64 encoded form.


As an example, the API definition for the translation of a single sentence would be:

POST to endpoint: https://production_access_server_url:8080/NexRelay/v1/translate Headers: Content-Type : application/json

Request Body: { "src":"en", "tgt":"es", "apikey":"your_api_key", "engine":"your_engine_id", "text":[

 "This is an example."
 ]

}

Answer Body: [

   [
       {
           "src": "This is an example.",
           "tgt": "Esto es un ejemplo."
       }
   ]

Both https and http endpoints are configurable in the Access Server.


Text Translation API


HOST: http://prod.pangeamt.com:8080/NexRelay/v1/

List Engines [/corp/engines]

List All available engines [POST] This edpoint is required to list the list of IDs of the available engines fo your APIKey + Request (application/json)

       {
           "apikey": "your-apikey-here"
       }

+ Response 200 (application/json)

       {
           "engines": [
               {
                   "id": 1,
                   "processid": 1,
                   "serviceid": 1,
                   "inserviceid": 0,
                   "src": "en",
                   "tgt": "es",
                   "descr": "ENES_B_plain",
                   "domain": "",
                   "flavor": "",
                   "status": 0
               },
               {
                   "id": 2,
                   "processid": 1,
                   "serviceid": 2,
                   "inserviceid": 0,
                   "src": "es",
                   "tgt": "en",
                   "descr": "ESEN_generic",
                   "domain": "",
                   "flavor": "",
                   "status": 0
               }
           ]
       }

Process text [/translate]

Process a text segment [POST]
A text segment is a number of words, processing works best if the segment is a sentence with whole semantic content.

  • src and tgt are 2-letter language codes
  • engine is the id (string) of the engine to be used
  • glossary_id, optional, is the id (integer) of the glossary to be used

+ Request (application/json)

       {
           "src":"es",
           "tgt":"en",
           "apikey":"your-api-key-here",
           "engine":"2",
           "glossary_id": 1,
           "text":[
               "¿Cómo estás?",
               "Mi perro es negro"
           ]
       }

+ Response 200 (application/json)

       [
           [
               {
                   "src": "¿Cómo estás?",
                   "tgt": "How are you?"
               }
           ],
           [
               {
                   "src": "Mi perro es negro",
                   "tgt": "My dog is black"
               }
           ]
       ]


Document Processing API

HOST: http://prod.pangeamt.com:8080/PGFile/v1

File Uploading [/sendfile]

Send a File [POST]


Main request. Send a file to the service for translation. The process parameters have to be included The success response is a json with file guid.

+ Request (multipart/form-data;boundary=----WebKitFormBoundary8M3sSU13ul5lXSJm)

       ------WebKitFormBoundary8M3sSU13ul5lXSJm
           Content-Disposition: form-data; name="json"


           {
               "title":"filename.docx",
               "processname":"translation",
               "engine":"123",
               "src":"es",
               "tgt": "en" ,
               "apikey":"your-apikey-here",
               "username": "testuser",
               "notiflink": "testlink",
               "processoption": "1"
           }
       ------WebKitFormBoundary8M3sSU13ul5lXSJm
           Content-Disposition: form-data; name="file"; filename="filename.docx"
           Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
           data
       ------WebKitFormBoundary8M3sSU13ul5lXSJm--

+ Response 200 (application/json)

       {
       "fileId": "8d4e1c5be60d4e04850f55ec135f2554"
       }

+ Response 500 (application/json)

       {
       "error": true,
       "error_message" : "the-error-message"
       }


Checking file status [/checkfile?apikey&fileid]

Use /checkfile to get the processing status of a file, this is a json post where body can have three forms:

  • just the apikey, the response will return info about all files being processed for the apikey.
  • guid, to get info about a single file

Use a get request like:

https://server_address:server_port/PGFile/v1/checkfile?apikey=your_api_key

https://server_address:server_port/PGFile/v1/checkfile?apikey=your_api_key&guid=d9b95ffb3bc347efa6a7cb90ca80ca74
The returned answer is a json list containing one json object for every file. The important field returned for every file is the status, an integer with possible values:

  • 10, file is queued for process at the server
  • 6 or 7, file is being analyzed
  • 20, 30 or 40, file is being processed
  • 100, file processed successsfully, waiting download
  • 110 or 120, file downloaded
  • -10 or -20 (negative values), processing error

Check the processing status of a file [GET] + Response 200 (application/json)

       [
           {
               "fileId": "1dc77dc5ba6d44828b860537dae07187", 
               "translatedPath": None, 
               "engineId": 58, 
               "glossaryId": 0, 
               "src": "es", 
               "tgt": "en", 
               "isZip": False, 
               "ztot": 0, 
               "zfinished": 0, 
               "translatedName": None, 
               "processName": "translate", 
               "processOptionId": 1, 
               "link": "", 
               "status": 10, 
               "id": 16567, 
               "fileName": "test.txt"
           }
       ]

Checking and downloading file [/retrievefile]

This is a POST request that can be used to get info about a file that is being processed and download the processed file is process has finished.

    • WARNING** this endpoint is NOT safe for very big files: the file is returned in base64

encoding and requires a lot of memory at server and client side.

When file is finished a 200 response is returned with the file. If file is in processs a 200 response is returned with the status data. Errors will generate a 401 response.

Check and get File [POST]

+ Request (application/json)

       {
           "apikey": "your-api-key-here",
           "guid": "1dc77dc5ba6d44828b860537dae07187"
       }

+ Response 200 (application/json)

       # response when file is not finished
       {
           "success": True, 
           "error": {}, 
           "status": "10", 
           "data": {}
       }  
       # response when file is finished
       {
           "success": True,
           "error": {}, 
           "status": "110", 
           "data": {
               "guid": "d74b06fd52434ad2bfbe82ebbff96464", 
               "fileType": "txt", 
               "filename": "test.txt", 
               "file": "U2VlIHRoaW5ncyB0byBkbywgcmVzdGF1cmFudHMsIGFuZCBob3RlbHMNCg=="
           }
       }

+ Response 401 (application/json)

       {
           "success": False, 
           "error": {
               "statusCode": 401, 
               "code": 6, 
               "message": "Invalid GUID"
           }, 
           "data": {}
       }

Downloading file [/download?apikey&fileid]

Simple get request to retrieve a file. The get parameters are:

  • apikey
  • fileid, the file GUID

The file is returned as a stream (similar to a call to wget)