1

请让我知道如何使用 REST API 向 XTRF 发布报价。我们在 REST API 中具有 POST/quote 功能,但我无法找到我们需要传递给该 API 调用的参数,并且我得到 Http 状态 415 - 不支持的媒体类型。

如果有人知道如何使用 REST API 在 XTRF 中添加报价,请帮助我

4

2 回答 2

0

我可以使用以下 CURL 操作创建报价。希望这会有所帮助。

$data =  '{
    "name" : "Test Estimate Newest",
    "customerProjectNumber" : "Test Project XX",
    "workflow" : { "name" : "Edit" },
    "specialization" : { "name" : "Economy"},
    "sourceLanguage" : {"name" : "English"},
    "targetLanguages" : [ {"name" : "Polish"}, {"name" : "German"} ],
    "notes" : "Sample notes",
    "autoAccept" : false,
    "persons" : [{"id":"131"}],
    "files" : [],
    "referenceFiles" : []
    }'; 
$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'Your URL to XTRF');
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiepath);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'Content-Length: '. strlen($data))); 

    $result = curl_exec($ch);
    curl_close($ch);
    return $result;

-Vamsi

于 2013-09-30T11:24:48.727 回答
0

XTRF REST API 方法POST /quotes需要 JSON 格式的内容。如果内容不符合 JSON 格式(即使用不同的格式或 JSON 字符串中存在一些语法错误),它会以 HTTP 状态代码 415(不支持的媒体类型)响应。

示例内容可能如下所示:

{
  "name" : "Google Gloves",
  "customerProjectNumber" : "G-312-2012",
  "workflow" : { "name" : "TP" },
  "specialization" : { "name" : "Economy"},
  "sourceLanguage" : {"name" : "English"},
  "targetLanguages" : [ {"name" : "Polish"}, {"name" : "German"} ],
  "deliveryDate" : "2012-09-15 11:30:00",
  "notes" : "Sample notes",
  "autoAccept" : false,
  "priceProfile" : {"name" : "Euro [€]"},
  "persons" : [{"id": 10}, {"id": 12}],
  "files" : [{"id": 1415596305}, {"id": 2005194325}],
  "referenceFiles" : [{"id": 4129771301}]
}

提示:如果您使用 JavaScript 中的 API,您可以使用JSON.stringify函数来确保您的对象正确序列化为 JSON 格式的字符串。

于 2013-09-17T12:44:41.160 回答