PHP client SmartCAT API
, (*1)
PHP client SmartCAT API, (*2)
How to use:
- Install composer
- composer require smartcat/smartcat-api
-
composer install, (*3)
Use Case, (*4)
use SmartCat\Client\SmartCat;
$sc=new SmartCat($login, $password);
Gets the account details
GET /api/integration/v1/account
php
$sc->getAccountManager()->accountGetAccountInfo();
, (*5)
Gets MT engines available for the account
GET /api/integration/v1/account/mtengines
php
$sc->getAccountManager()->accountGetMTEnginesForAccount();
, (*6)
Gets LSP's services available for the account](https://smartcat.com/api/methods/#!/Account/Account_GetLSPServicesForAccount)
GET /api/integration/v1/account/lsp/services
php
$sc->getAccountManager()->accountGetLSPServicesForAccount();
, (*7)
Gets available assignees (MyTeam freelancers or internal account users)
GET /api/integration/v1/account/assignableExecutives
php
$sc->getAccountManager()->accountGetAssignableExecutives();
, (*8)
Reset configurations of notifications reception
DELETE /api/integration/v1/callback
php
$sc->getCallbackManager()->callbackDelete()
, (*9)
Reading configurations of notifications reception of the account
GET /api/integration/v1/callback
php
$sc->getCallbackManager()->callbackGet()
, (*10)
Creating and updating configurations of notifications reception
POST /api/integration/v1/callback
php
$callback=new CallbackPropertyModel();
$callback->setUrl('https://smartcat.ai');
$res=$sc->getCallbackManager()->callbackUpdate($callback);
, (*11)
Reading the last sending errors (no more than 100)
GET /api/integration/v1/callback/lastErrors
php
$sc->getCallbackManager()->callbackGetLastErrors(['limit'=>$limit])
, (*12)
Creates a client with the specified name and returns the Id
If the client already exists, just returns the Id.
POST /api/integration/v1/client/create
php
$clientId = $sc->getClientManager()->clientCreateClient('Test client');
, (*13)
Get details on a client specified within an account
GET /api/integration/v1/client/{clientId}
php
$client = $sc->getClientManager()->clientGetClient($clientId);
, (*14)
Sets the specified net rate model for the specified customer
PUT /api/integration/v1/client/{clientId}/set
php
$client = $sc->getClientManager()->clientSetClientNetRate($clientId, ['netRateId' => $netRateId]);
, (*15)
Receive the specified directory
GET /api/integration/v1/directory
php
$sc->getDirectoriesManager()->directoriesGet(['type'=>'projectStatus'])
, (*16)
Gets parsing formats supported by the account
GET /api/integration/v1/directory/formats
php
$sc->getDirectoriesManager()->directoriesGetSupportedFormatsForAccount();
, (*17)
Delete one or several documents
DELETE /api/integration/v1/document
php
$sc->getDocumentManager()->documentDelete(['documentIds'=>['id1','id2']])
, (*18)
Receive document model
GET /api/integration/v1/document
php
$sc->getDocumentManager()->documentGet(['documentId'=>$docId])
, (*19)
Update assigned document
PUT /api/integration/v1/document/update
php
$bilingualFileImportSettings = new BilingualFileImportSettingsModel();
$bilingualFileImportSettings
->setConfirmMode('none')
->setLockMode('none')
->setTargetSubstitutionMode('all');
$updateDocumentModel = new UploadDocumentPropertiesModel();
$updateDocumentModel->setBilingualFileImportSettings($bilingualFileImportSettings);
$res = $sc->getDocumentManager()->documentUpdate([
'documentId' => $docId,
'updateDocumentModel' => $updateDocumentModel,
'uploadedFile' => [
'fileContent' => fopen(__DIR__ . '\Resources\File2_EN.docx', 'r'),
'fileName' => 'File2_EN.docx'
]
]);
, (*20)
Rename assigned document
PUT /api/integration/v1/document/rename
php
$sc->getDocumentManager()->documentRename(['documentId'=>$docId,'name'=>'New file name'])
, (*21)
Translate indicated document using the transferred file with translations
PUT /api/integration/v1/document/translate
php
$sc->getDocumentManager()->documentTranslate([
'documentId'=>$docId,
'translationFile'=>[
'filePath'=>'file path',
'fileName'=>'file name'
]
])
, (*22)
Импортировать xliff-файл с переводами документа
PUT /api/integration/v1/document/translateWithXliff
php
$sc->getDocumentManager()->documentTranslateWithXliff([
'documentId' => $docId,
'confirmTranslation' => true,
'overwriteUpdatedSegments' => true,
'translationFile' => [
'filePath' => 'file path',
'fileName' => 'file.xliff'
]
]);
, (*23)
Receive the status of adding document translation
GET /api/integration/v1/document/translate/status
php
$sc->getDocumentManager()->documentGetTranslationStatus(['documentId'=>$docId])
, (*24)
Gets a detailed report about translation importing results
GET /api/integration/v1/document/translate/result
php
$sc->getDocumentManager()->documentGetTranslationsImportResult(['documentId' => $docsId]);
, (*25)
Gets statistics
GET /api/integration/v1/document/statistics
php
$sc->getDocumentManager()->documentGetStatistics(['documentId' => $docsId]);
, (*26)
Split document into equal segments according to the number of words and assign each freelancer to one segment
POST /api/integration/v1/document/assignFreelancers
php
$sc->getDocumentManager()->documentAssignFreelancersToDocument(
['Abbyyaolid1','Abbyyaolid2'],
[
'documentId' => $documentId,
'stageNumber' => $stageNumber
]
)
, (*27)
Request document (-s) export
POST /api/integration/v1/document/export
php
$sc->getDocumentExportManager()->documentExportRequestExport(['documentIds'=>['documenId1','documentId2'])
, (*28)
Download the results of export
GET /api/integration/v1/document/export/{taskId}
php
$sc->getDocumentExportManager()->documentExportDownloadExportResult($taskId);
, (*29)
Получить набор глоссариев
GET /api/integration/v1/glossaries
php
$res = $sc->getGlossaryManager()->glossaryGetGlossaries();
, (*30)
Creates a payable for a freelancer
POST /api/integration/v1/invoice/job
php
$importJobModel = new ImportJobModel();
$importJobModel->setFreelancerId($freelanceId)
->setServiceType('translation')
->setJobDescription('Test invoice')
->setUnitsType('Any text')
->setUnitsAmount(10)
->setPricePerUnit(1)
->setCurrency('usd');
$res=$sc->getInvoiceManager()->invoiceImportJob($importJobModel);
, (*31)
Gets all placeholder formats available in the current account
GET /api/integration/v1/placeholders
php
$res = $sc->getPlaceholderFormatApiManager()->placeholderFormatApiGetPlaceholderFormats();
, (*32)
Saves a set of placeholder formats for the current account
PUT /api/integration/v1/placeholders
php
$placeHolder1 = new PlaceholderFormatModel();
$placeHolder1->setRegex($regEx1);
$placeHolder2 = new PlaceholderFormatModel();
$placeHolder2->setRegex($regEx2);
$res = $sc->getPlaceholderFormatApiManager()->placeholderFormatApiUpdatePlaceholderFormats([$placeHolder1, $placeHolder2]);
, (*33)
Validates the specified placeholder format
GET /api/integration/v1/placeholders/validate
php
$res = $this->sc->getPlaceholderFormatApiManager()->placeholderFormatApiValidatePlaceholderFormat(['format' => 'Stable\:(\s+)(.+)[\r|]\n']);
, (*34)
Delete project
DELETE /api/integration/v1/project/{projectId}
php
$sc->getProjectManager()->projectDelete($projectId)
, (*35)
Receive project model
GET /api/integration/v1/project/{projectId}
php
sc->getProjectManager()->projectGet($projectId)
, (*36)
Update project using ID
PUT /api/integration/v1/project/{projectId}, (*37)
Receive the list of all projects in account
GET /api/integration/v1/project/list
php
$sc->getProjectManager()->projectGetAll()
, (*38)
Receive the list of all projects in account with offset (v2), (*39)
GET /api/integration/v2/project/list
php
$sc->getProjectManager()->projectsGetWithOffset($offset = 0, $limit = 100)
, (*40)
Receive statistics and project value
GET /api/integration/v2/project/{projectId}/statistics
php
$sc->getProjectManager()->projectGetProjectStatistics($projectId);
do {
sleep(5);
$res = $sc->getProjectManager()->projectGetProjectStatistics($projectId);
} while(!is_array($res));
, (*41)
Receiving statistics for the completed parts of the project
GET /api/integration/v1/project/{projectId}/completedWorkStatistics
php
$res = $sc->getProjectManager()->projectGetCompletedWorkStatistics($projectId);
, (*42)
Receiving a list of the TMs plugged into the project
GET /api/integration/v1/project/{projectId}/translationmemories
php
$res = $sc->getProjectManager()->projectGetProjectTranslationMemories($projectId);
, (*43)
Rewrite connected TMs — same set of TMs for all target languages
POST /api/integration/v1/project/{projectId}/translationmemories
php
$translationMemoryForProjectModel = new TranslationMemoryForProjectModel();
$translationMemoryForProjectModel->setId($tmId);
$translationMemoryForProjectModel->setIsWritable(true);
$translationMemoryForProjectModel->setMatchThreshold(100);
$res = $sc->getProjectManager()->projectSetTranslationMemoriesForWholeProject($projectId, [$translationMemoryForProjectModel]);
, (*44)
Gets a set of glossaries enabled for a project
GET /api/integration/v1/project/{projectId}/glossaries
php
$res = $sc->getProjectManager()->projectGetGlossaries($projectId);
, (*45)
Enables a set of glossaries for a project
PUT /api/integration/v1/project/{projectId}/glossaries
php
$res = $this->sc->getProjectManager()->projectSetGlossaries($projectId, [$glossaryId1, $glossaryId2]);
, (*46)
Starts generating statistics for the project
POST /api/integration/v1/project/{projectId}/statistics/build
php
$sc->getProjectManager()->projectBuildStatistics($this->prj->getId());
, (*47)
Rewrite connected TMs — each target language with its own set of TMs
POST /api/integration/v1/project/{projectId}/translationmemories/bylanguages
php
$translationMemoryForProjectModel = new TranslationMemoryForProjectModel();
$translationMemoryForProjectModel->setId($tmId);
$translationMemoryForProjectModel->setIsWritable(true);
$translationMemoryForProjectModel->setMatchThreshold(100);
$tm = new TranslationMemoriesForLanguageModel();
$tm->setLanguage('en');
$tm->setTranslationMemories([$translationMemoryForProjectModel]);
$res = $sc->getProjectManager()->projectSetProjectTranslationMemoriesByLanguages($projectId, [$tm]);
, (*48)
Create a project
POST /api/integration/v1/project/create
php
$prjCreate = new CreateProjectWithFilesModel();
$prjCreate->setName('Test project');
$prjCreate->setDescription('Test project');
$prjCreate->setSourceLanguage('ru');
$prjCreate->setTargetLanguages(['en']);
$prjCreate->setAssignToVendor(false);
$prjCreate->setUseMT(false);
$prjCreate->setPretranslate(false);
$prjCreate->setAutoPropagateRepetitions(false);
$prjCreate->setIsForTesting(true);
$prjCreate->setWorkflowStages(['translation']);
$prjCreate->attacheFile(fopen(__DIR__.'\Resources\File1_EN.docx'),'File1_EN.docx');
$sc->getProjectManager()->projectCreateProjectWithFiles($prjCreate);
, (*49)
Add new document to project
POST /api/integration/v1/project/document
php
$bilingualFileImportSettings = new BilingualFileImportSettingsModel();
$bilingualFileImportSettings
->setConfirmMode('none')
->setLockMode('none')
->setTargetSubstitutionMode('all');
$documentModel = new CreateDocumentPropertyWithFilesModel();
$documentModel->setBilingualFileImportSettings($bilingualFileImportSettings);
$documentModel->attachFile(fopen(__DIR__ . '\Resources\File2_EN.docx'), 'File2_EN.docx');
$res = $sc->getProjectManager()->projectAddDocument([
'documentModel' => [$documentModel],
'projectId' => $projectId
]);
If you want to set Disassemble Settings, you should set Disassemble Algorithm. For example:
```php
$bilingualFileImportSettings = new BilingualFileImportSettingsModel();
$bilingualFileImportSettings
->setConfirmMode('none')
->setLockMode('none')
->setTargetSubstitutionMode('all');, (*50)
$disassembleSettings = (new DisassembleSettingsModel())
->setTranslatableAttributes(['img'=>['data-caption']]);, (*51)
$documentModel = new CreateDocumentPropertyWithFilesModel();
$documentModel->setDisassembleAlgorithmName('html');
$documentModel->setDisassembleSettings($disassembleSettings);
$documentModel->setBilingualFileImportSettings($bilingualFileImportSettings);
$documentModel->attachFile(fopen(DIR . '\Resources\File2_EN.docx'), 'File2_EN.docx');
$res = $sc->getProjectManager()->projectAddDocument([
'documentModel' => [$documentModel],
'projectId' => $projectId
]);
```, (*52)
Deprecated:
php
$sc->getProjectManager()->projectAddDocument([
'projectId'=>$projectId,
'file' => [
'filePath'=>'path to file',
'fileName'=>'File name'
]
]);
, (*53)
Add new target language to project
POST /api/integration/v1/project/language
php
$sc->getProjectManager()->projectAddLanguage(['projectId'=>$projectId,'targetLanguage'=>'ja']);
, (*54)
Assign the group of translators for the specific stage of documents in project
PUT /api/integration/v1/project/{projectId}/assignGroupToWorkflowStage
php
$sc->getProjectManager()->projectAssignGroupToWorkflowStage($projectId,['groupName'=>'Administrators','workflowStage'=>'translation'])
, (*55)
Cancel project
POST /api/integration/v1/project/cancel
php
$sc->getProjectManager()->projectCancelProject(['projectId'=>$projectId])
, (*56)
Restore project
POST /api/integration/v1/project/restore
php
$sc->getProjectManager()->projectRestoreProject(['projectId'=>$projectId])
, (*57)
Completes the workflow for all project documents. The project status will change to Completed.
POST /api/integration/v1/project/restore
php
$sc->getProjectManager()->projectCompleteProject(['projectId' => $this->prj->getId()]);
, (*58)
Deletes the TM
DELETE /api/integration/v1/translationmemory/{tmId}
php
$sc->getTranslationMemoriesManager()->translationMemoriesRemoveTranslationMemory($tmId)
, (*59)
Gets TM details
GET /api/integration/v1/translationmemory/{tmId}
php
$sc->getTranslationMemoriesManager()->translationMemoriesGetMetaInfo($tmId);
, (*60)
Imports TMX files into the TM
POST /api/integration/v1/translationmemory/{tmId}
php
$sc->getTranslationMemoriesManager()->translationMemoriesImport(
$tmId,
[
'replaceAllContent' => 'true',
'tmxFile' => [
'filePath' => __DIR__ . '\Resources\Space.tmx'
]
]
);
, (*61)
Gets a collection of TMs available for the account
GET /api/integration/v1/translationmemory
php
$thirstRes = $sc->getTranslationMemoriesManager()->translationMemoriesGetTranslationMemoriesBatch([
'lastProcessedId' => '',
'batchSize' => 10
]);
$last = array_pop($thirstRes);
$secondRes = $sc->getTranslationMemoriesManager()->translationMemoriesGetTranslationMemoriesBatch([
'lastProcessedId' => $last->getId(),
'batchSize' => $count
]);
, (*62)
Creates an empty TM
POST /api/integration/v1/translationmemory
```php
$tm = new CreateTranslationMemoryModel();
$name = 'PHP Unit ' . date('U');
$tm->setName($name);
$tm->setSourceLanguage('ru');
$tm->setTargetLanguages(['en']);
$tm->setDescription("Description: $name");, (*63)
$tmId = $sc->getTranslationMemoriesManager()->translationMemoriesCreateEmptyTM($tm);
```, (*64)
Gets a collection of tasks for TMX import
GET /api/integration/v1/translationmemory/task
php
$sc->getTranslationMemoriesManager()->translationMemoriesGetPendingTasks();
, (*65)
Sets an array of target languages required by the TM
PUT /api/integration/v1/translationmemory/{tmId}/target
php
$sc->getTranslationMemoriesManager()->translationMemoriesSetTMTargetLanguages($tmId, ["en", "es"]);
, (*66)
Exports TMX files from the TM
GET /api/integration/v1/translationmemory/{tmId}/file
php
$sc->getTranslationMemoriesManager()->translationMemoriesExportFile($tmId, ['withTags' => true])
, (*67)
Gets matches from a given TM
POST /api/integration/v1/translationmemory/matches
```php
$tmMatch = new TmMatchesRequest();
$tmMatch->setSourceLanguage('en');
$tmMatch->setTargetLanguage('ru');
$segmentModel = new SegmentModel();
$segmentModel->setText('Test text message');
$segmentModel->setPrevContext('');
$segmentModel->setNextContext('');
$segmentModel->setTags([]);
$tmMatch->setSegmentModel($segmentModel);, (*68)
$sc->getTranslationMemoriesManager()->translationMemoriesGetTMTranslations($tmMatch, ['tmId' => $tmId]);
```, (*69)
Removes a given import task
DELETE /api/integration/v1/translationmemory/task/{taskId}
php
$sc->getTranslationMemoriesManager()->translationMemoriesRemoveSpecificImportTask($last->getId())
, (*70)
Creates a new user with the specified parameters
POST /api/integration/v1/user
php
$user = new CreateUserRequest();
$user->setEmail('test@test.com')
->setFirstName('FirstName')
->setLastName('LastName')
->setExternalId('my-external-id')
->setRightsGroup('executive');
$res = $sc->getUserManager()->userCreate($user);
, (*71)
Deletes a user
DELETE /api/integration/v1/user/{accountUserId}
php
$sc->getUserManager()->userDelete($smartcatAccountUserId);
, (*72)
Gets a user model
GET /api/integration/v1/user/{accountUserId}
php
$res = $sc->getUserManager()->userGet($smartcatAccountUserId);
, (*73)
Updates user data
PUT /api/integration/v1/user/{accountUserId}
php
$updateModel = new UpdateUserRequest();
$updateModel->setFirstName($newName);
$sc->getUserManager()->userUpdate($smartcatAccountUserId, $updateModel);
, (*74)
Gets a user by its external ID
GET /api/integration/v1/user/external
php
$res = $sc->getUserManager()->userGetExternal(['id' => $externalId]);
, (*75)