Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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"]]}]
07JP27
C# / Azure大好きマン PoCやってるときが一番楽しい。 JDLA E資格 2019#2
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away