使用httpotion elixir发布到slack api

时间:2016-07-27 02:46:19

标签: api post elixir

这里只是处理语法错误。尝试在HTTPotion请求的正文中发送有效负载。试图以json的形式发送数据,但不确定我哪里出错了。

HTTPotion.post "https://hooks.slack.com/services/a00000/b0000/XXXXXXX", [body: "{'channel': '#general', 'username': 'thedanotto', 'text': 'Pokemon are scary!', 'icon_emoji': ':ghost:'}", ["Content-Type": "application/json"]]

=> ** (SyntaxError) iex:1: syntax error before: '['

有什么想法吗?

2 个答案:

答案 0 :(得分:3)

您在标题列表前缺少headers:。这应该有效:

HTTPotion.post "https://hooks.slack.com/services/a00000/b0000/XXXXXXX", [body: "{'channel': '#general', 'username': 'thedanotto', 'text': 'Pokemon are scary!', 'icon_emoji': ':ghost:'}", headers: ["Content-Type": "application/json"]]

答案 1 :(得分:2)

您错过了headers密钥

应该是这样的:

HTTPotion.post "https://hooks.slack.com/services/a00000/b0000/XXXXXXX", [body: "{'channel': '#general', 'username': 'thedanotto', 'text': 'Pokemon are scary!', 'icon_emoji': ':ghost:'}", headers: ["Content-Type": "application/json"]]