post to slack api with httpotion elixir

房东的猫 提交于 2019-12-11 01:23:30

问题


Just dealing with a syntax error here. Trying to send the payload in the body of the HTTPotion request. Trying to send the data as json, but not really sure where I'm going wrong.

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: '['

Any ideas?


回答1:


You're missing headers: before the headers list. This should work:

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"]]



回答2:


You're missing headers key

It should be like this:

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"]]


来源:https://stackoverflow.com/questions/38602879/post-to-slack-api-with-httpotion-elixir

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!