[solved] Calling REST api directly from interactive button

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.

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.

May I ask where you found this infromation? I’m having a similar problem and wouldn’t know what to specify for typeand data_source.

I wrote a simple nodejs web service which logs any request sent to it, directed button actions to call this service and then I got this structure.

Type is either button or select as in the
developer documetation, the data_source can be empty. The data_source field is used by the system to fill the list for the “select” type (AFAIK it can be “users” or “channels”).

Right, thanks! I think type is button by default. Anyway… I’m still getting no reaction at all from Mattermost after returning that payload. If you have the time, could please take a look at my question here?

Sure, I’ll check this one.

Hi @alex_enyway, can I take a look at the Body of your Interactive Message POST request? I would like to know you get the button to make a request to external API!