Phrase TMS API

API Technology (TMS)

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

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

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

  • GET

    检索资源,不会对其进行任何修改。

  • POST

    创建资源。POST 也用于不适合四种操作中的任何一种或具有长或复杂输入的操作——例如搜索翻译记忆库或创建工作。

  • PUT

    更新资源。请注意,整个实体及其所有字段都是必需的,而不仅仅是那些更改的字段;如果未包含它,则应将其设置为 null。

  • DELETE

    删除资源。

重要

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

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

所有响应列表都是分页的。使用参数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": "在翻译记忆库中无需使用",
            "dateCreated":"2018-01-09T14:07:46+0000",
            "id":"1",
            "targetLangs": [
                "es",
                "it"
            ],
            "subDomain": null,
            "businessUnit": {
                "id":"1",
                "name":"第一个 BU"
            },
            "sourceLang": "en",
            "domain": null,
            "name":"我的新翻译记忆库"
        }
    ],
    "numberOfElements":1,
    "totalElements":1,
    "pageSize":50,
    "totalPages":1
}

创建新的翻译记忆库

POST

/web/api2/v1/transMemories

{{
"name":"我的新翻译记忆库"
"sourceLang": "en",
"targetLangs": [
"es", "it-IT"
],
"businessUnit": {
"id":"1"
},
"注释": "在翻译记忆库中无需使用"
}

响应

201

{
    "internalId":1,
    "createdBy": {
        "userName": "admin",
        "id":"3",
        "firstName":"J",
        "lastName":"Jan",
        "role":"ADMIN",
        "email": "jan.j@phrase.com"
    },
    "client": null,
    "注释": "在翻译记忆库中无需使用"
    "dateCreated":"2018-01-09T14:07:46+0000",
    "id":"1",
    "targetLangs": [
        "es",
        "it"
    ],
    "subDomain": null,
    "businessUnit": {
        "id":"1",
        "name":"第一个 BU"
    },
    "sourceLang": "en",
    "domain": null,
    "name":"我的新翻译记忆库"
}

创建工作时添加文件

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

来自 Postman 的示例 PHP:

<?php

$request = new HttpRequest();
$request->setUrl('https://cloud.memsource.com/web/api2/v1/projects/%7BUID%20of%20your%20project%7D/jobs');
$request->setMethod(HTTP_METH_POST);

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

$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":"缺少类型为 \"字符串\" 的必需参数 \"password\"。"
}

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

报告问题

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

  • API 端点

  • 请求

  • 时间(和时区)

  • 响应

  • 响应的短语-动作-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.