Summary
I have my own API for linking together several services used with mattermost utilising slash commands. I am looking to auto-detect when a new class is added to that and automatically make the corresponding slash command in mattermost.
I am using vanilla PHP and curl. The initial creation call works fine however you can’t pass the response icon / username through this so then sending a request to the “update a command” call on API this however gives me a “Invalid or missing command in request body.” error response.
According to API doc only required field is “command_id” which is correct and supplied. Most likely missed something obvious but been staring at this all day now with no luck.
Steps to reproduce
The following snippet has been separated from existing class used for API calls and replicates as a standalone. The missing config variables are self explanatory.
<?php
$sc_id = 'pxukapg41fye58w1gedfhqqcar';
$command = "testperms";
$url = "https://chat.r5k.net/api/v4/commands/".$sc_id;
$post = array();
$post['command_id'] = $sc_id;
$post['display_name'] = $command;
$post['description'] = "Command automatically synced - ".date("Y-m-d H:i:s");
$post['username'] = $_CONFIG['sc_username'];
$post['icon_url'] = $_CONFIG['sc_avatar'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$_CONFIG['mm_api_token']
));
$res = curl_exec($ch);
curl_close($ch);
Expected behavior
To update slash command with details sent.
Observed behavior
[id] => api.context.invalid_body_param.app_error
[message] => Invalid or missing command in request body.
[detailed_error] =>
[request_id] => udoub8izzby4pfp5kzx567g3qa
[status_code] => 400