【问题标题】:Redmine API updating time entry is not implemented?redmine API 更新时间入口没有实现?
【发布时间】:2019-05-13 09:31:32
【问题描述】:

更新时间条目: http://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Updating-a-time-entry 结果总是 404

我正在使用 Redmine 3.4.6.stable 并且正在使用: PUT /time_entries/[id].xml

其他操作,例如: 创建时间条目 正在工作。

此外,Delete 不起作用,我尝试使用 JSON 代替 XML,但响应相同。

然后我删除了这样的扩展: /time_entries/[id] 我得到了 422,但响应给了我一个完整的 HTML 页面:

无效的表单真实性令牌。

我不是 Ruby/Rails 开发人员,但在 routes.rb 中我可以看到:

match '/time_entries/:id', :to => 'timelog#destroy', :via => :delete, :id => /\d+/

这是唯一的条目: /time_entries/:id

所以这意味着文档位于: http://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Updating-a-time-entry 已过时,并且没有更新时间条目的终点。 这是正确的吗?

我还在 Redmine 中提交了一张票: http://www.redmine.org/issues/31288 但我想我会更快地得到答案/帮助。

这是我用来更新问题的 Groovy 代码:

def baseUrl = new URL("${Config.host}/time_entries/${timeEntry.key}.xml?key=${Config.redmineKey}")
new HTTPBuilder(baseUrl).request(Method.PUT, ContentType.XML) {
    body = "<time_entry><id>9956</id><project_id>25</project_id><issue_id>${timeEntry.key}</issue_id><spent_on>${spentOnDate}</spent_on><hours>${new Date(timeEntry.value.toInteger()).format("HH:mm")}</hours><activity_id>9</activity_id><comments></comments></time_entry>"
    response.success = { resp, xml ->
        println "Success! ${resp.status}"
    }
    response.failure = { resp ->
        println "Request failed with status ${resp.status}"
        def outputStream = new ByteArrayOutputStream()
        resp.entity.writeTo(outputStream)
        def errorMsg = outputStream.toString('utf8')
        println errorMsg
    }
}

【问题讨论】:

  • 我在 redmine.org 上回复过

标签: redmine redmine-api


【解决方案1】:

以下代码适用于 nodejs 并使用 xml 格式:

const http = require('http')

var body = ' <?xml version="1.0" ?>' +
           '<time_entry><id>1</id><issue_id>1</issue_id><spent_on>2019-02-02</spent_on><hours>9.0</hours></time_entry>';

var postRequest = {
    host: "localhost",
    path: "/time_entries/1.xml",
    port: 3000,
    method: "PUT",
    headers: {
        'Content-Type': 'text/xml',
        'X-Redmine-API-Key': '95228de814b46d8980447c00591460598990d469',
        'Content-Length': Buffer.byteLength(body)
    }
};

var buffer = "";

var req = http.request( postRequest, function( res )    {

   console.log( res.statusCode );
   var buffer = "";
   res.on( "data", function( data ) { buffer = buffer + data; } );
   res.on( "end", function( data ) { console.log( buffer ); } );

});

req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
});

req.write( body );
req.end();

确保正确配置 postRequest 参数,例如 X-Redmine-API-key 路径、主机、端口和方法...

【讨论】:

  • 我正在使用 Redmine 3.4.6.stable,似乎没有实现。你也可以在那里检查一下吗?
  • 我的版本是:3.4.6.stable.17600
  • 另外,我刚刚将 PUT 替换为 DELETE 并删除了条目...请将您的完整代码发布在某处以获取更多错误识别...
  • 我认为问题出在 ?key 上,不确定 groovy 中的代码,但在 nodejs 代码中,您可以看到 X-Redmine-API-Key 作为标头请求值...可能类似于import com.eviware.soapui.support.types.StringToStringMap def headers = new StringToStringMap() headers.put("X-Redmine-API-Key","value") testRunner.testCase.getTestStepByName("REST Test Request")。 testRequest.setRequestHeaders(headers)
  • 我也尝试过使用标题,但也得到了 404。对于插入时间条目,它与 URL 参数一起使用,所以这似乎很好。我真的认为在我的版本中缺少路线。你能看看你的版本中是否为它定义了路由吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多