【问题标题】:Add Quote to XTRF using REST API使用 REST API 向 XTRF 添加报价
【发布时间】:2013-09-17 11:16:00
【问题描述】:

请告诉我如何使用 REST API 将报价发布到 XTRF。我们在 REST API 中具有 POST/quote 功能,但我无法找到我们需要传递给该 API 调用的参数,并且我得到 Http 状态 415 - Unsupported Media type。

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

【问题讨论】:

标签: xtrf


【解决方案1】:

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 格式的字符串。

【讨论】:

    【解决方案2】:

    我可以使用以下 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      • 2021-03-25
      相关资源
      最近更新 更多