LoginSignup
3

More than 5 years have passed since last update.

Node-REDでA3RT APIを使うときのハマりどころ

Last updated at Posted at 2017-08-02

A3RT

A3RTとはリクルートが提供している機械学習やディープラーニングを用いたソリューションAPI群です。
ちなみに「アート」と発音します。APIを叩くだけで分析などをしてくれるのですが、Node-REDからこのAPIを呼び出すときにハマったところがあったのでメモ
https://a3rt.recruit-tech.co.jp

ハマりどころ

通常のNode-REDでAPIを叩くようにすると

apikey is null

が返される!

解決法

Node-RED : jp-node-red.japaneast.cloudapp.azure.com 2017-08-02 12-39-24.png
msg.headers の "Content-Type"を"application/x-www-form-urlencoded"に指定しましょう。

フロー全景はこんな感じ
Node-RED : jp-node-red.japaneast.cloudapp.azure.com 2017-08-02 12-41-00.png

 コード

以下はTalk APIを呼び出しています。

[{"id":"21ed046f.72f514","type":"inject","z":"69f4e0e9.4561e","name":"処理実行","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"x":65,"y":20,"wires":[["6b32188c.f4e86"]]},{"id":"3339c4a1.9774c4","type":"http request","z":"69f4e0e9.4561e","name":"POST","method":"POST","ret":"txt","url":"https://api.a3rt.recruit-tech.co.jp/talk/v1/smalltalk","tls":"","x":259,"y":145,"wires":[["3edabb6c.c78544"]]},{"id":"25d460be.2f7e7","type":"debug","z":"69f4e0e9.4561e","name":"結果表示","active":true,"console":"false","complete":"payload.results[0].reply","x":485,"y":256,"wires":[]},{"id":"3edabb6c.c78544","type":"json","z":"69f4e0e9.4561e","name":"","pretty":false,"x":358.5,"y":195,"wires":[["25d460be.2f7e7"]]},{"id":"6b32188c.f4e86","type":"function","z":"69f4e0e9.4561e","name":"リクエスト作成","func":"msg.payload = {\"apikey\":\"yourapikey\",\"query\":\"こんにちは\"};\nmsg.headers = {\"Content-Type\":\"application/x-www-form-urlencoded\"};\n\nreturn msg;","outputs":1,"noerr":0,"x":141,"y":81,"wires":[["3339c4a1.9774c4"]]}]

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3