Phrase TMS API

API 技术 (TMS)

文本由 Phrase Language AI 从英语机器翻译而得。

我们的 API 将应用程序实体(项目、任务、设置)视为可以检索、创建、修改和删除的资源。 

每个 HTTP 方法代表一个操作:

  • GET

    检索资源,从不更改资源

  • POST

    创建资源。POST 也用于不属于这四种操作的任何一种,或者具有冗长或复杂输入的操作——例如搜索翻译记忆库或创建任务。

  • PUT

    更新资源。请注意,需要提供整个实体及其所有字段,而不仅仅是已更改的字段;不包含的字段意味着应将其设置为 null。

  • 删除

    删除资源。

重要

输入和输出数据通常采用 JSON 格式,并使用 UTF-8 编码。对于作为请求主体内容类型的文件,使用 application/octet-streammultipart/form-data

实体尽可能使用扁平结构,以保持良好的响应时间。在回答中,不包含完整的子对象,而是包含含有 ID、UID 和其他几个属性的引用。预期使用 IDReferenceUidReference 对象来引用相关实体。

所有响应列表均已分页。使用参数 pageNumberpageSize 来检索请求的数据。最大页面大小为 50。

文档

OpenAPI 3.0 用于 API 文档。Swagger 代码生成器 推荐用于客户开发。

API 示例

获取所有翻译记忆库的列表

GET

/web/api2/v1/transMemories

响应

200

{
    "pageNumber": 0,
    "content": [
        {
            "internalId": 1,
            "createdBy": {
                "userName": "admin",
                "id": "3",
                "firstName": "Jan",
                "lastName": "Janocko",
                "role": "ADMIN",
                "email": "jan.janocko@phrase.com"
            },
            "client": null,
            "note": "not necessary to use in 翻译记忆库",
            "dateCreated": "2018-01-09T14:07:46+0000",
            "id": "1",
            "targetLangs": [
                "es",
                "it"
            ],
            "subDomain": null,
            "businessUnit": {
                "id": "1",
                "name": "First BU"
            },
            "sourceLang": "en",
            "domain": null,
            "name": "My new 翻译记忆库"
        }
    ],
    "numberOfElements": 1,
    "totalElements": 1,
    "pageSize": 50,
    "totalPages": 1
}

创建新的翻译记忆库

POST

/web/api2/v1/transMemories

{{
"name": "My new 翻译记忆库",
"sourceLang": "en",
"targetLangs": [
"es", "it-IT"
],
"businessUnit": {
"id": "1"
},
"note": "not necessary to use in 翻译记忆库"
}

响应

201

{
    "internalId": 1,
    "createdBy": {
        "userName": "admin",
        "id": "3",
        "firstName": "J",
        "lastName": "Jan",
        "role": "ADMIN",
        "email": "jan.j@phrase.com"
    },
    "client": null,
    "note": "not necessary to use in 翻译记忆库",
    "dateCreated": "2018-01-09T14:07:46+0000",
    "id": "1",
    "targetLangs": [
        "es",
        "it"
    ],
    "subDomain": null,
    "businessUnit": {
        "id": "1",
        "name": "First BU"
    },
    "sourceLang": "en",
    "domain": null,
    "name": "My new 翻译记忆库"
}

创建工作时添加文件

将此文件作为二进制附件添加到请求正文中。确保正确插入 Phrase 和 Content-Disposition 标头。

来自 Postman 的 PHP 示例:

<?php

$request = new HttpRequest();
$request->setUrl('https://cloud.memsource.com/web/api2/v1/projects/%7B您的项目%20ID%7D/jobs');
$request->setMethod(HTTP_METH_POST);

$request->setQueryData(array(
'token' => '在此处输入您的令牌'
));

$request->setHeaders(array(
'postman-token' => 'ABC',
'cache-control' => 'no-cache',
'content-disposition' => 'filename*=UTF-8''Sample.txt',
'memsource' => '{\\\\\"targetLangs\\\\\":[\\\\\"de\\\\\",\\\\\"fr\\\\\",\\\\\"es\\\\\"],\\\\\"callbackUrl\\\\\":\\\\\"https://my-shiny-service.com/consumeCallback\\\\\",\\\\\"importSettings\\\\\":{\\\\\"uid\\\\\":\\\\\"WF0T1SfSHxII09yKr0dZh9\\\\\"}}'
));

try {
$response = $request->send();

echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}

错误处理

如果处理 API 请求时出现问题,将返回以下 JSON 结构。错误代码将始终存在;详细描述可能为 null。

{ "errorCode": "InvalidArguments",
"errorDescription": "缺少类型为 \"string\" 的必需参数 \"password\"。"
}

可以通过读取 HTTP 状态 响应代码 来检测错误响应。如果发生错误,它将永远不会被设置为 2xx。状态代码为 400 错误请求,401 或 403 表示身份验证或授权问题。

报告问题

技术支持 报告问题时,请在报告中包含以下内容:

  • API 端点

  • 请求

  • 时间(及时区)

  • 响应

  • 响应的 Phrase-Action-ID

这篇文章有帮助吗?

Sorry about that! In what way was it not helpful?

The article didn’t address my problem.
I couldn’t understand the article.
The feature doesn’t do what I need.
Other reason.

Note that feedback is provided anonymously so we aren't able to reply to questions.
If you'd like to ask a question, submit a request to our Support team.
Thank you for your feedback.