Skip to content

Repository files navigation

PHP client SmartCAT API

Latest VersionSoftware LicenseTotal Downloads

PHP client SmartCAT API

How to use:

  1. Install composer
  2. composer require smartcat/smartcat-api
  3. composer install

Use Case

useSmartCat\Client\SmartCat;
$sc=newSmartCat($login, $password);

Gets the account details
GET /api/integration/v1/account

$sc->getAccountManager()->accountGetAccountInfo();

Gets MT engines available for the account
GET /api/integration/v1/account/mtengines

$sc->getAccountManager()->accountGetMTEnginesForAccount();

Gets LSP's services available for the account](https://smartcat.com/api/methods/#!/Account/Account_GetLSPServicesForAccount)
GET /api/integration/v1/account/lsp/services

$sc->getAccountManager()->accountGetLSPServicesForAccount();

Gets available assignees (MyTeam freelancers or internal account users)
GET /api/integration/v1/account/assignableExecutives

$sc->getAccountManager()->accountGetAssignableExecutives();

Reset configurations of notifications receptionDELETE /api/integration/v1/callback

$sc->getCallbackManager()->callbackDelete()

Reading configurations of notifications reception of the accountGET /api/integration/v1/callback

$sc->getCallbackManager()->callbackGet()

Creating and updating configurations of notifications receptionPOST /api/integration/v1/callback

$callback=newCallbackPropertyModel();
$callback->setUrl('https://smartcat.ai');
$res=$sc->getCallbackManager()->callbackUpdate($callback);

Reading the last sending errors (no more than 100)GET /api/integration/v1/callback/lastErrors

$sc->getCallbackManager()->callbackGetLastErrors(['limit'=>$limit])

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

$clientId = $sc->getClientManager()->clientCreateClient('Test client');

Get details on a client specified within an account
GET /api/integration/v1/client/{clientId}

$client = $sc->getClientManager()->clientGetClient($clientId);

Sets the specified net rate model for the specified customer
PUT /api/integration/v1/client/{clientId}/set

$client = $sc->getClientManager()->clientSetClientNetRate($clientId, ['netRateId' => $netRateId]);

Receive the specified directoryGET /api/integration/v1/directory

$sc->getDirectoriesManager()->directoriesGet(['type'=>'projectStatus'])

Gets parsing formats supported by the account
GET /api/integration/v1/directory/formats

$sc->getDirectoriesManager()->directoriesGetSupportedFormatsForAccount();

Delete one or several documentsDELETE /api/integration/v1/document

$sc->getDocumentManager()->documentDelete(['documentIds'=>['id1','id2']])

Receive document modelGET /api/integration/v1/document

$sc->getDocumentManager()->documentGet(['documentId'=>$docId])

Update assigned documentPUT /api/integration/v1/document/update

$bilingualFileImportSettings = newBilingualFileImportSettingsModel();
$bilingualFileImportSettings
->setConfirmMode('none')
->setLockMode('none')
->setTargetSubstitutionMode('all');
$updateDocumentModel = newUploadDocumentPropertiesModel();
$updateDocumentModel->setBilingualFileImportSettings($bilingualFileImportSettings);
$res = $sc->getDocumentManager()->documentUpdate([
'documentId' => $docId,
'updateDocumentModel' => $updateDocumentModel,
'uploadedFile' => [
'fileContent' => fopen(__DIR__ . '\Resources\File2_EN.docx', 'r'),
'fileName' => 'File2_EN.docx'
]
]);

Rename assigned documentPUT /api/integration/v1/document/rename

$sc->getDocumentManager()->documentRename(['documentId'=>$docId,'name'=>'New file name'])

Translate indicated document using the transferred file with translationsPUT /api/integration/v1/document/translate

$sc->getDocumentManager()->documentTranslate([
'documentId'=>$docId,
'translationFile'=>[
'filePath'=>'file path',
'fileName'=>'file name'
]
])

Импортировать xliff-файл с переводами документа
PUT /api/integration/v1/document/translateWithXliff

$sc->getDocumentManager()->documentTranslateWithXliff([
'documentId' => $docId,
'confirmTranslation' => true,
'overwriteUpdatedSegments' => true,
'translationFile' => [
'filePath' => 'file path',
'fileName' => 'file.xliff'
]
]);

Receive the status of adding document translationGET /api/integration/v1/document/translate/status

$sc->getDocumentManager()->documentGetTranslationStatus(['documentId'=>$docId])

Gets a detailed report about translation importing results
GET /api/integration/v1/document/translate/result

$sc->getDocumentManager()->documentGetTranslationsImportResult(['documentId' => $docsId]);

Gets statistics
GET /api/integration/v1/document/statistics

$sc->getDocumentManager()->documentGetStatistics(['documentId' => $docsId]);

Split document into equal segments according to the number of words and assign each freelancer to one segmentPOST /api/integration/v1/document/assignFreelancers

$sc->getDocumentManager()->documentAssignFreelancersToDocument(
['Abbyyaolid1','Abbyyaolid2'], [
'documentId' => $documentId, 'stageNumber' => $stageNumber
]
)

Request document (-s) exportPOST /api/integration/v1/document/export

$sc->getDocumentExportManager()->documentExportRequestExport(['documentIds'=>['documenId1','documentId2'])

Download the results of exportGET /api/integration/v1/document/export/{taskId}

$sc->getDocumentExportManager()->documentExportDownloadExportResult($taskId);

Получить набор глоссариев
GET /api/integration/v1/glossaries

$res = $sc->getGlossaryManager()->glossaryGetGlossaries();

Creates a payable for a freelancer
POST /api/integration/v1/invoice/job

$importJobModel = newImportJobModel();
$importJobModel->setFreelancerId($freelanceId)
->setServiceType('translation')
->setJobDescription('Test invoice')
->setUnitsType('Any text')
->setUnitsAmount(10)
->setPricePerUnit(1)
->setCurrency('usd');
$res=$sc->getInvoiceManager()->invoiceImportJob($importJobModel);

Gets all placeholder formats available in the current account
GET /api/integration/v1/placeholders

$res = $sc->getPlaceholderFormatApiManager()->placeholderFormatApiGetPlaceholderFormats();

Saves a set of placeholder formats for the current account
PUT /api/integration/v1/placeholders

$placeHolder1 = newPlaceholderFormatModel();
$placeHolder1->setRegex($regEx1);
$placeHolder2 = newPlaceholderFormatModel();
$placeHolder2->setRegex($regEx2);
$res = $sc->getPlaceholderFormatApiManager()->placeholderFormatApiUpdatePlaceholderFormats([$placeHolder1, $placeHolder2]);

Validates the specified placeholder format
GET /api/integration/v1/placeholders/validate

$res = $this->sc->getPlaceholderFormatApiManager()->placeholderFormatApiValidatePlaceholderFormat(['format' => 'Stable\:(\s+)(.+)[\r|]\n']);

Delete projectDELETE /api/integration/v1/project/{projectId}

$sc->getProjectManager()->projectDelete($projectId)

Receive project modelGET /api/integration/v1/project/{projectId}

sc->getProjectManager()->projectGet($projectId)

Update project using ID
PUT /api/integration/v1/project/{projectId}

Receive the list of all projects in accountGET /api/integration/v1/project/list

$sc->getProjectManager()->projectGetAll()

Receive the list of all projects in account with offset (v2)

GET /api/integration/v2/project/list

$sc->getProjectManager()->projectsGetWithOffset($offset = 0, $limit = 100)

Receive statistics and project value
GET /api/integration/v2/project/{projectId}/statistics

$sc->getProjectManager()->projectGetProjectStatistics($projectId);
do {
sleep(5);
$res = $sc->getProjectManager()->projectGetProjectStatistics($projectId);
} while(!is_array($res));

Receiving statistics for the completed parts of the project
GET /api/integration/v1/project/{projectId}/completedWorkStatistics

$res = $sc->getProjectManager()->projectGetCompletedWorkStatistics($projectId);

Receiving a list of the TMs plugged into the project
GET /api/integration/v1/project/{projectId}/translationmemories

$res = $sc->getProjectManager()->projectGetProjectTranslationMemories($projectId);

Rewrite connected TMs — same set of TMs for all target languages
POST /api/integration/v1/project/{projectId}/translationmemories

$translationMemoryForProjectModel = newTranslationMemoryForProjectModel();
$translationMemoryForProjectModel->setId($tmId);
$translationMemoryForProjectModel->setIsWritable(true);
$translationMemoryForProjectModel->setMatchThreshold(100);
$res = $sc->getProjectManager()->projectSetTranslationMemoriesForWholeProject($projectId, [$translationMemoryForProjectModel]);

Gets a set of glossaries enabled for a project
GET /api/integration/v1/project/{projectId}/glossaries

$res = $sc->getProjectManager()->projectGetGlossaries($projectId);

Enables a set of glossaries for a project
PUT /api/integration/v1/project/{projectId}/glossaries

$res = $this->sc->getProjectManager()->projectSetGlossaries($projectId, [$glossaryId1, $glossaryId2]);

Starts generating statistics for the project
POST /api/integration/v1/project/{projectId}/statistics/build

$sc->getProjectManager()->projectBuildStatistics($this->prj->getId());

Rewrite connected TMs — each target language with its own set of TMs
POST /api/integration/v1/project/{projectId}/translationmemories/bylanguages

$translationMemoryForProjectModel = newTranslationMemoryForProjectModel();
$translationMemoryForProjectModel->setId($tmId);
$translationMemoryForProjectModel->setIsWritable(true);
$translationMemoryForProjectModel->setMatchThreshold(100);
$tm = newTranslationMemoriesForLanguageModel();
$tm->setLanguage('en');
$tm->setTranslationMemories([$translationMemoryForProjectModel]);
$res = $sc->getProjectManager()->projectSetProjectTranslationMemoriesByLanguages($projectId, [$tm]);

Create a projectPOST /api/integration/v1/project/create

$prjCreate = newCreateProjectWithFilesModel();
$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);

Add new document to projectPOST /api/integration/v1/project/document

$bilingualFileImportSettings = newBilingualFileImportSettingsModel();
$bilingualFileImportSettings
->setConfirmMode('none')
->setLockMode('none')
->setTargetSubstitutionMode('all');
$documentModel = newCreateDocumentPropertyWithFilesModel();
$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:

$bilingualFileImportSettings = newBilingualFileImportSettingsModel();
$bilingualFileImportSettings
->setConfirmMode('none')
->setLockMode('none')
->setTargetSubstitutionMode('all');
$disassembleSettings = (newDisassembleSettingsModel())
->setTranslatableAttributes(['img'=>['data-caption']]);
$documentModel = newCreateDocumentPropertyWithFilesModel();
$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
]);

Deprecated:

$sc->getProjectManager()->projectAddDocument([
'projectId'=>$projectId, 'file' => [
'filePath'=>'path to file',
'fileName'=>'File name'
]
]);

Add new target language to projectPOST /api/integration/v1/project/language

$sc->getProjectManager()->projectAddLanguage(['projectId'=>$projectId,'targetLanguage'=>'ja']);

Assign the group of translators for the specific stage of documents in projectPUT /api/integration/v1/project/{projectId}/assignGroupToWorkflowStage

$sc->getProjectManager()->projectAssignGroupToWorkflowStage($projectId,['groupName'=>'Administrators','workflowStage'=>'translation'])

Cancel projectPOST /api/integration/v1/project/cancel

$sc->getProjectManager()->projectCancelProject(['projectId'=>$projectId])

Restore projectPOST /api/integration/v1/project/restore

$sc->getProjectManager()->projectRestoreProject(['projectId'=>$projectId])

Completes the workflow for all project documents. The project status will change to Completed.
POST /api/integration/v1/project/restore

$sc->getProjectManager()->projectCompleteProject(['projectId' => $this->prj->getId()]);

Deletes the TM
DELETE /api/integration/v1/translationmemory/{tmId}

$sc->getTranslationMemoriesManager()->translationMemoriesRemoveTranslationMemory($tmId)

Gets TM details
GET /api/integration/v1/translationmemory/{tmId}

$sc->getTranslationMemoriesManager()->translationMemoriesGetMetaInfo($tmId);

Imports TMX files into the TM
POST /api/integration/v1/translationmemory/{tmId}

$sc->getTranslationMemoriesManager()->translationMemoriesImport(
$tmId,
[
'replaceAllContent' => 'true',
'tmxFile' => [
'filePath' => __DIR__ . '\Resources\Space.tmx'
]
]
);

Gets a collection of TMs available for the account
GET /api/integration/v1/translationmemory

$thirstRes = $sc->getTranslationMemoriesManager()->translationMemoriesGetTranslationMemoriesBatch([
'lastProcessedId' => '',
'batchSize' => 10
]);
$last = array_pop($thirstRes);
$secondRes = $sc->getTranslationMemoriesManager()->translationMemoriesGetTranslationMemoriesBatch([
'lastProcessedId' => $last->getId(),
'batchSize' => $count
]);

Creates an empty TM
POST /api/integration/v1/translationmemory

$tm = newCreateTranslationMemoryModel();
$name = 'PHP Unit ' . date('U');
$tm->setName($name);
$tm->setSourceLanguage('ru');
$tm->setTargetLanguages(['en']);
$tm->setDescription("Description: $name");
$tmId = $sc->getTranslationMemoriesManager()->translationMemoriesCreateEmptyTM($tm);

Gets a collection of tasks for TMX import
GET /api/integration/v1/translationmemory/task

$sc->getTranslationMemoriesManager()->translationMemoriesGetPendingTasks();

Sets an array of target languages required by the TM
PUT /api/integration/v1/translationmemory/{tmId}/target

$sc->getTranslationMemoriesManager()->translationMemoriesSetTMTargetLanguages($tmId, ["en", "es"]);

Exports TMX files from the TM
GET /api/integration/v1/translationmemory/{tmId}/file

$sc->getTranslationMemoriesManager()->translationMemoriesExportFile($tmId, ['withTags' => true])

Gets matches from a given TM
POST /api/integration/v1/translationmemory/matches

$tmMatch = newTmMatchesRequest();
$tmMatch->setSourceLanguage('en');
$tmMatch->setTargetLanguage('ru');
$segmentModel = newSegmentModel();
$segmentModel->setText('Test text message');
$segmentModel->setPrevContext('');
$segmentModel->setNextContext('');
$segmentModel->setTags([]);
$tmMatch->setSegmentModel($segmentModel);
$sc->getTranslationMemoriesManager()->translationMemoriesGetTMTranslations($tmMatch, ['tmId' => $tmId]);

Removes a given import task
DELETE /api/integration/v1/translationmemory/task/{taskId}

$sc->getTranslationMemoriesManager()->translationMemoriesRemoveSpecificImportTask($last->getId())

Creates a new user with the specified parameters
POST /api/integration/v1/user

$user = newCreateUserRequest();
$user->setEmail('test@test.com')
->setFirstName('FirstName')
->setLastName('LastName')
->setExternalId('my-external-id')
->setRightsGroup('executive');
$res = $sc->getUserManager()->userCreate($user);

Deletes a user
DELETE /api/integration/v1/user/{accountUserId}

$sc->getUserManager()->userDelete($smartcatAccountUserId);

Gets a user model
GET /api/integration/v1/user/{accountUserId}

$res = $sc->getUserManager()->userGet($smartcatAccountUserId);

Updates user data
PUT /api/integration/v1/user/{accountUserId}

$updateModel = newUpdateUserRequest();
$updateModel->setFirstName($newName);
$sc->getUserManager()->userUpdate($smartcatAccountUserId, $updateModel);

Gets a user by its external ID
GET /api/integration/v1/user/external

$res = $sc->getUserManager()->userGetExternal(['id' => $externalId]);

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages