Mattermost Peer-to-Peer Forum

[solved] Calling REST api directly from interactive button

#1

Is there any possibility to call REST API interface directly from interactive button? What is the right way to do it?

Right now I’m trying to call an incoming webhook from mattermost message to the same mattermost with little to no success:

Mar 19 06:29:19 Mattermost platform[24988]: {“level”:“error”,“ts”:1552991359.004765,“caller”:“web/context.go:52”,“msg”:“No text specified”,“path”:"/hooks/some_webhook_here",“request_id”:“ihn68c5x9tgjxmesi5ieioi65e”,“ip_addr”:“mm_url”,“user_id”:"",“method”:“POST”,“err_where”:“HandleIncomingWebhook”,“http_code”:400,“err_details”:""}
Mar 19 06:29:19 Mattermost platform[24988]: {“level”:“error”,“ts”:1552991359.0051658,“caller”:“web/context.go:52”,“msg”:“Action integration error”,“path”:"/api/v4/posts/qrebwzy4p7rnzdw4y6egubhgia/actions/pzfip7qwfbge7ba68cgpjy6yae",“request_id”:“nhsa451ad3yzmgm93g8u6u8d3r”,“ip_addr”:“10.239.2.92”,“user_id”:“aiegjz7sjidcjy6j93huedtohc”,“method”:“POST”,“err_where”:“DoActionRequest”,“http_code”:400,“err_details”:“status=400”}

The button in question looks like that:

{
	"attachments": [{
			"text": "Test",
			"actions": [{
					"name": "button",
					"integration": {
						"url": "http://10.239.5.200/hooks/owo7z39xw7rm3f6hs6cowdnnc",		
						"context": ["action": "do_something","text":"zzzzzzzzzzz","username":"myusernamehere"]
					}
				}
			]
		}
	]
}

I’m absolutely not sure about the things I wrote in context and whether this construction should work at all.

#2

I got it, the structure of JSON is

{
  "user_id": "",
  "channel_id": "",
  "team_id": "",
  "post_id": "",
  "trigger_id": "",
  "type": "",
  "data_source": "",
  "context": {
    "Content-Type": "application/json",
    "text": "zzzzzzzzzzz"
  }
}

Since context content is on the second layer of JSON I cannot use it as is in incoming webhooks.