Elixir:如何使用httpotion发布其他API(redmine)

时间:2016-06-26 10:03:49

标签: json rest elixir redmine

您好我正在尝试创建并向Redmine API发布帖子

def createIssue(issue) do
  value = %{"project_id" => 1, "subject" => "Example", "priority_id" => 1, "tracker_id" => 1}
  content = Poison.Encoder.encode(value, [])
  HTTPotion.post("#{url}/issues.json", [body: "issue=#{content}" , basic_auth: auth()])
end

以上代码的结果如下

Started POST "/issues.json" for 127.0.0.1 at 2016-06-26 11:47:25 +0200
Processing by IssuesController#create as JSON
Parameters: {"issue"=>"{\"tracker_id\":1,\"subject\":\"Example\",\"project_id\":1,\"priority_id\":1}"}
Current user: admin (id=1)

redmine的正确回应应该是我能理解的以下

Parameters: {"issue"=>{"tracker_id":1,"subject": "Example","project_id":1,"priority_id":1}}

任何人都可以提供帮助? 感谢

1 个答案:

答案 0 :(得分:3)

问题不在于HTTPotion。您没有将“问题”节点编码为JSON。

'~data-props="(.*)"~U'